Skip to content
This repository was archived by the owner on Jul 15, 2025. It is now read-only.

Commit 8e93ab9

Browse files
committed
Copy source tree from tensorflow/java repository
1 parent f36e925 commit 8e93ab9

File tree

178 files changed

+21823
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+21823
-7
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.iml
2+
target

README.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To import the NdArray library in your project, simply add the following dependen
1111
<dependency>
1212
<groupId>org.tensorflow</groupId>
1313
<artifactId>ndarray</artifactId>
14-
<version>0.2.0-SNAPSHOT</version>
14+
<version>0.3.0</version>
1515
</dependency>
1616
```
1717

@@ -120,9 +120,3 @@ try (EagerSession session = EagerSession.create()) {
120120
);
121121
}
122122
```
123-
124-
## How to Contribute?
125-
126-
This repository is maintained by TensorFlow JVM Special Interest Group (SIG). You can easily join the group
127-
by subscribing to the [jvm@tensorflow.org](https://groups.google.com/a/tensorflow.org/forum/#!forum/jvm)
128-
mailing list, or you can simply send pull requests and raise issues to this repository.

pom.xml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<!--
2+
Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
=======================================================================
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
22+
<parent>
23+
<groupId>org.tensorflow</groupId>
24+
<artifactId>tensorflow-java</artifactId>
25+
<version>0.4.0-SNAPSHOT</version>
26+
</parent>
27+
<artifactId>ndarray</artifactId>
28+
<packaging>jar</packaging>
29+
30+
<name>TensorFlow NdArray Library</name>
31+
<description>
32+
Utility library for N-dimensional data I/O operations.
33+
</description>
34+
35+
<properties>
36+
<java.module.name>org.tensorflow.ndarray</java.module.name>
37+
</properties>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.junit.jupiter</groupId>
42+
<artifactId>junit-jupiter-api</artifactId>
43+
<scope>test</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter-engine</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.openjdk.jmh</groupId>
52+
<artifactId>jmh-core</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.openjdk.jmh</groupId>
57+
<artifactId>jmh-generator-annprocess</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
</dependencies>
61+
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<artifactId>maven-jar-plugin</artifactId>
66+
<version>3.2.0</version>
67+
<configuration>
68+
<archive>
69+
<manifestEntries>
70+
<Automatic-Module-Name>${java.module.name}</Automatic-Module-Name>
71+
</manifestEntries>
72+
</archive>
73+
</configuration>
74+
</plugin>
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-surefire-plugin</artifactId>
78+
<version>2.22.2</version>
79+
<configuration>
80+
<forkCount>1</forkCount>
81+
<reuseForks>false</reuseForks>
82+
<argLine>-Xmx2G -XX:MaxPermSize=256m</argLine>
83+
<includes>
84+
<include>**/*Test.java</include>
85+
</includes>
86+
</configuration>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
91+
</project>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
=======================================================================
16+
*/
17+
package org.tensorflow.ndarray;
18+
19+
import org.tensorflow.ndarray.buffer.BooleanDataBuffer;
20+
import org.tensorflow.ndarray.buffer.DataBuffer;
21+
import org.tensorflow.ndarray.index.Index;
22+
23+
/**
24+
* An {@link NdArray} of booleans.
25+
*/
26+
public interface BooleanNdArray extends NdArray<Boolean> {
27+
28+
/**
29+
* Returns the boolean value of the scalar found at the given coordinates.
30+
*
31+
* <p>To access the scalar element, the number of coordinates provided must be equal to the number
32+
* of dimensions of this array (i.e. its rank). For example:
33+
* <pre>{@code
34+
* BooleanNdArray matrix = NdArrays.ofBooleans(shape(2, 2)); // matrix rank = 2
35+
* matrix.getBoolean(0, 1); // succeeds, returns false
36+
* matrix.getBoolean(0); // throws IllegalRankException
37+
*
38+
* BooleanNdArray scalar = matrix.get(0, 1); // scalar rank = 0
39+
* scalar.getBoolean(); // succeeds, returns false
40+
* }</pre>
41+
*
42+
* @param coordinates coordinates of the scalar to resolve
43+
* @return value of that scalar
44+
* @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
45+
* @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
46+
*/
47+
boolean getBoolean(long... coordinates);
48+
49+
/**
50+
* Assigns the boolean value of the scalar found at the given coordinates.
51+
*
52+
* <p>To access the scalar element, the number of coordinates provided must be equal to the number
53+
* of dimensions of this array (i.e. its rank). For example:
54+
* <pre>{@code
55+
* BooleanNdArray matrix = NdArrays.ofBooleans(shape(2, 2)); // matrix rank = 2
56+
* matrix.setBoolean(true, 0, 1); // succeeds
57+
* matrix.setBoolean(true, 0); // throws IllegalRankException
58+
*
59+
* BooleanNdArray scalar = matrix.get(0, 1); // scalar rank = 0
60+
* scalar.setBoolean(true); // succeeds
61+
* }</pre>
62+
*
63+
* @param value the value to assign
64+
* @param coordinates coordinates of the scalar to assign
65+
* @return this array
66+
* @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
67+
* @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
68+
*/
69+
BooleanNdArray setBoolean(boolean value, long... coordinates);
70+
71+
@Override
72+
BooleanNdArray slice(Index... indices);
73+
74+
@Override
75+
BooleanNdArray get(long... coordinates);
76+
77+
@Override
78+
BooleanNdArray set(NdArray<Boolean> src, long... coordinates);
79+
80+
@Override
81+
default Boolean getObject(long... coordinates) {
82+
return getBoolean(coordinates);
83+
}
84+
85+
@Override
86+
default BooleanNdArray setObject(Boolean value, long... coordinates) {
87+
return setBoolean(value, coordinates);
88+
}
89+
90+
@Override
91+
NdArraySequence<BooleanNdArray> elements(int dimensionIdx);
92+
93+
@Override
94+
NdArraySequence<BooleanNdArray> scalars();
95+
96+
@Override
97+
BooleanNdArray copyTo(NdArray<Boolean> dst);
98+
99+
@Override
100+
BooleanNdArray read(DataBuffer<Boolean> dst);
101+
102+
BooleanNdArray read(BooleanDataBuffer dst);
103+
104+
@Override
105+
BooleanNdArray write(DataBuffer<Boolean> src);
106+
107+
BooleanNdArray write(BooleanDataBuffer src);
108+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
=======================================================================
16+
*/
17+
package org.tensorflow.ndarray;
18+
19+
import org.tensorflow.ndarray.buffer.ByteDataBuffer;
20+
import org.tensorflow.ndarray.buffer.DataBuffer;
21+
import org.tensorflow.ndarray.index.Index;
22+
23+
/**
24+
* An {@link NdArray} of bytes.
25+
*/
26+
public interface ByteNdArray extends NdArray<Byte> {
27+
28+
/**
29+
* Returns the byte value of the scalar found at the given coordinates.
30+
*
31+
* <p>To access the scalar element, the number of coordinates provided must be equal to the number
32+
* of dimensions of this array (i.e. its rank). For example:
33+
* <pre>{@code
34+
* ByteNdArray matrix = NdArrays.ofBytes(shape(2, 2)); // matrix rank = 2
35+
* matrix.getByte(0, 1); // succeeds, returns 0
36+
* matrix.getByte(0); // throws IllegalRankException
37+
*
38+
* ByteNdArray scalar = matrix.get(0, 1); // scalar rank = 0
39+
* scalar.getByte(); // succeeds, returns 0
40+
* }</pre>
41+
*
42+
* @param coordinates coordinates of the scalar to resolve
43+
* @return value of that scalar
44+
* @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
45+
* @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
46+
*/
47+
byte getByte(long... coordinates);
48+
49+
/**
50+
* Assigns the byte value of the scalar found at the given coordinates.
51+
*
52+
* <p>To access the scalar element, the number of coordinates provided must be equal to the number
53+
* of dimensions of this array (i.e. its rank). For example:
54+
* <pre>{@code
55+
* ByteNdArray matrix = NdArrays.ofBytes(shape(2, 2)); // matrix rank = 2
56+
* matrix.setByte(10, 0, 1); // succeeds
57+
* matrix.setByte(10, 0); // throws IllegalRankException
58+
*
59+
* ByteNdArray scalar = matrix.get(0, 1); // scalar rank = 0
60+
* scalar.setByte(10); // succeeds
61+
* }</pre>
62+
*
63+
* @param value the value to assign
64+
* @param coordinates coordinates of the scalar to assign
65+
* @return this array
66+
* @throws IndexOutOfBoundsException if some coordinates are outside the limits of their respective dimension
67+
* @throws IllegalRankException if number of coordinates is not sufficient to access a scalar element
68+
*/
69+
ByteNdArray setByte(byte value, long... coordinates);
70+
71+
@Override
72+
ByteNdArray slice(Index... indices);
73+
74+
@Override
75+
ByteNdArray get(long... coordinates);
76+
77+
@Override
78+
ByteNdArray set(NdArray<Byte> src, long... coordinates);
79+
80+
@Override
81+
default Byte getObject(long... coordinates) {
82+
return getByte(coordinates);
83+
}
84+
85+
@Override
86+
default ByteNdArray setObject(Byte value, long... coordinates) {
87+
return setByte(value, coordinates);
88+
}
89+
90+
@Override
91+
NdArraySequence<ByteNdArray> elements(int dimensionIdx);
92+
93+
@Override
94+
NdArraySequence<ByteNdArray> scalars();
95+
96+
@Override
97+
ByteNdArray copyTo(NdArray<Byte> dst);
98+
99+
@Override
100+
ByteNdArray read(DataBuffer<Byte> dst);
101+
102+
ByteNdArray read(ByteDataBuffer dst);
103+
104+
@Override
105+
ByteNdArray write(DataBuffer<Byte> src);
106+
107+
ByteNdArray write(ByteDataBuffer src);
108+
}

0 commit comments

Comments
 (0)