Skip to content

Commit 06ea735

Browse files
committed
Migrating tensorflow/java-ndarray repository to tensorflow/java
2 parents 75402be + 8d4f06e commit 06ea735

207 files changed

Lines changed: 30973 additions & 0 deletions

File tree

Some content is hidden

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

ndarray/pom.xml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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-ndarray</artifactId>
25+
<version>1.1.0-SNAPSHOT</version>
26+
</parent>
27+
<artifactId>ndarray</artifactId>
28+
<packaging>jar</packaging>
29+
30+
<name>NdArray Java Library</name>
31+
<description>
32+
Utility library for N-dimensional data I/O operations in Java.
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>3.0.0-M5</version>
79+
<configuration>
80+
<forkCount>1</forkCount>
81+
<reuseForks>false</reuseForks>
82+
<argLine>-Xmx2G</argLine>
83+
<includes>
84+
<include>**/*Test.java</include>
85+
</includes>
86+
<useModulePath>false</useModulePath>
87+
</configuration>
88+
</plugin>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-compiler-plugin</artifactId>
92+
<executions>
93+
<execution>
94+
<id>default-testCompile</id>
95+
<configuration>
96+
<compilerArgs>
97+
<arg>--add-modules=java.desktop</arg> <!-- For AWT usage in benchmarks -->
98+
</compilerArgs>
99+
</configuration>
100+
</execution>
101+
</executions>
102+
</plugin>
103+
</plugins>
104+
</build>
105+
106+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright 2022 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+
module org.tensorflow.ndarray {
18+
requires jdk.unsupported; // required by raw buffer implementations using Unsafe
19+
20+
exports org.tensorflow.ndarray;
21+
exports org.tensorflow.ndarray.buffer;
22+
exports org.tensorflow.ndarray.buffer.layout;
23+
exports org.tensorflow.ndarray.index;
24+
25+
// Expose all implementions of our interfaces, so consumers can write custom
26+
// implementations easily by extending from them
27+
exports org.tensorflow.ndarray.impl.buffer;
28+
exports org.tensorflow.ndarray.impl.buffer.adapter;
29+
exports org.tensorflow.ndarray.impl.buffer.layout;
30+
exports org.tensorflow.ndarray.impl.buffer.misc;
31+
exports org.tensorflow.ndarray.impl.buffer.nio;
32+
exports org.tensorflow.ndarray.impl.buffer.raw;
33+
exports org.tensorflow.ndarray.impl.dense;
34+
exports org.tensorflow.ndarray.impl.dimension;
35+
exports org.tensorflow.ndarray.impl.sequence;
36+
exports org.tensorflow.ndarray.impl.sparse;
37+
exports org.tensorflow.ndarray.impl.sparse.slice;
38+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 withShape(Shape shape);
73+
74+
@Override
75+
BooleanNdArray slice(Index... indices);
76+
77+
@Override
78+
BooleanNdArray get(long... coordinates);
79+
80+
@Override
81+
BooleanNdArray set(NdArray<Boolean> src, long... coordinates);
82+
83+
@Override
84+
default Boolean getObject(long... coordinates) {
85+
return getBoolean(coordinates);
86+
}
87+
88+
@Override
89+
default BooleanNdArray setObject(Boolean value, long... coordinates) {
90+
return setBoolean(value, coordinates);
91+
}
92+
93+
@Override
94+
NdArraySequence<BooleanNdArray> elements(int dimensionIdx);
95+
96+
@Override
97+
NdArraySequence<BooleanNdArray> scalars();
98+
99+
@Override
100+
BooleanNdArray copyTo(NdArray<Boolean> dst);
101+
102+
@Override
103+
BooleanNdArray copyTo(DataBuffer<Boolean> dst);
104+
105+
BooleanNdArray copyTo(BooleanDataBuffer dst);
106+
107+
@Override
108+
BooleanNdArray copyFrom(DataBuffer<Boolean> src);
109+
110+
BooleanNdArray copyFrom(BooleanDataBuffer src);
111+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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 withShape(Shape shape);
73+
74+
@Override
75+
ByteNdArray slice(Index... indices);
76+
77+
@Override
78+
ByteNdArray get(long... coordinates);
79+
80+
@Override
81+
ByteNdArray set(NdArray<Byte> src, long... coordinates);
82+
83+
@Override
84+
default Byte getObject(long... coordinates) {
85+
return getByte(coordinates);
86+
}
87+
88+
@Override
89+
default ByteNdArray setObject(Byte value, long... coordinates) {
90+
return setByte(value, coordinates);
91+
}
92+
93+
@Override
94+
NdArraySequence<ByteNdArray> elements(int dimensionIdx);
95+
96+
@Override
97+
NdArraySequence<ByteNdArray> scalars();
98+
99+
@Override
100+
ByteNdArray copyTo(NdArray<Byte> dst);
101+
102+
@Override
103+
ByteNdArray copyTo(DataBuffer<Byte> dst);
104+
105+
ByteNdArray copyTo(ByteDataBuffer dst);
106+
107+
@Override
108+
ByteNdArray copyFrom(DataBuffer<Byte> src);
109+
110+
ByteNdArray copyFrom(ByteDataBuffer src);
111+
}

0 commit comments

Comments
 (0)