Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8d579aa
Move NdArray library to subfolder
karllessard Apr 26, 2021
3f9d689
Add missing dependencies
karllessard Apr 26, 2021
edfc4d6
Fix settings.xml path
karllessard Apr 26, 2021
2fe76c0
Kotlin friendly names (Shape.get)
rnett May 18, 2021
210f8e0
Fix bug when slicing on a segmented dimension (#2)
karllessard Jul 27, 2021
01dfc1e
Sparse tensor (#3)
JimClarke5 Aug 4, 2021
220d52a
Allow SparseNdArray impls to be inherited (#5)
karllessard Jan 11, 2022
a6f8d7f
Better examples in Sparse array documentation (#6)
karllessard Feb 9, 2022
7ac4abb
Build on JDK11 by default (#7)
karllessard Feb 16, 2022
a40b7ac
Add missing export
karllessard Feb 16, 2022
9cec751
Adding toString to AbstractDenseNdArray and AbstractSparseNdArray (#8)
Craigacp Mar 17, 2022
9b3f8a0
Test Java copyFrom Ok
hmf Nov 21, 2022
4c9d606
Test Java copyFrom - trying to replicate Scala error
hmf Nov 21, 2022
17da0e0
Test Java copyFrom - trying to replicate Scala error v2
hmf Nov 22, 2022
14e09bb
Added basic index tests (rank 2)
hmf Nov 26, 2022
0dac08a
Added module-info to tests
hmf Nov 29, 2022
d363240
Module-info for tests use the same module name of src
hmf Nov 30, 2022
a223c05
Merge pull request #12 from hmf/slice_error
Craigacp Nov 30, 2022
9978956
Value streaming for NdArrays (#15)
karllessard Jan 25, 2023
8f17151
Release 0.4.0
karllessard Jan 26, 2023
b2ba5ad
Prepare next iteration
karllessard Jan 26, 2023
cdafccd
Viewing arrays with different shapes (#18)
karllessard Feb 18, 2024
e256302
Rename read/write to copyTo/From (#19)
karllessard Feb 20, 2024
08aa62f
Releasing 1.0.0-rc.1
karllessard Feb 20, 2024
8d4f06e
Increase version for next iteration
karllessard Feb 21, 2024
06ea735
Migrating `tensorflow/java-ndarray` repository to `tensorflow/java`
karllessard Feb 20, 2026
5f150df
Move ndarray to tensorflow-java
karllessard Mar 6, 2026
7e424e4
Apply spotless
karllessard Mar 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</scm>

<modules>
<module>tensorflow-ndarray</module>
<module>tensorflow-core</module>
<module>tensorflow-framework</module>
</modules>
Expand Down
5 changes: 2 additions & 3 deletions tensorflow-core/tensorflow-core-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<description>Platform-dependent native code and pure-Java code for the TensorFlow machine intelligence library.</description>

<properties>
<ndarray.version>1.0.0</ndarray.version>
<truth.version>1.1.5</truth.version>
<test.download.skip>false</test.download.skip>
<test.download.folder>${project.build.directory}/tf-text-download/</test.download.folder>
Expand All @@ -24,8 +23,8 @@
<dependencies>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>ndarray</artifactId>
<version>${ndarray.version}</version>
<artifactId>tensorflow-ndarray</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
Expand Down
101 changes: 101 additions & 0 deletions tensorflow-ndarray/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<!--
Copyright 2019 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=======================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-java</artifactId>
<version>1.2.0-SNAPSHOT</version>
</parent>
<artifactId>tensorflow-ndarray</artifactId>
<packaging>jar</packaging>

<name>TensorFlow NdArray Library</name>
<description>
Utility library for N-dimensional data I/O operations in Java.
</description>

<properties>
<java.module.name>org.tensorflow.ndarray</java.module.name>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>${java.module.name}</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<argLine>-Xmx2G</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-testCompile</id>
<configuration>
<compilerArgs>
<arg>--add-modules=java.desktop</arg> <!-- For AWT usage in benchmarks -->
</compilerArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
38 changes: 38 additions & 0 deletions tensorflow-ndarray/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright 2022 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=======================================================================
*/
module org.tensorflow.ndarray {
requires jdk.unsupported; // required by raw buffer implementations using Unsafe

exports org.tensorflow.ndarray;
exports org.tensorflow.ndarray.buffer;
exports org.tensorflow.ndarray.buffer.layout;
exports org.tensorflow.ndarray.index;

// Expose all implementations of our interfaces, so consumers can write custom
// implementations easily by extending from them
exports org.tensorflow.ndarray.impl.buffer;
exports org.tensorflow.ndarray.impl.buffer.adapter;
exports org.tensorflow.ndarray.impl.buffer.layout;
exports org.tensorflow.ndarray.impl.buffer.misc;
exports org.tensorflow.ndarray.impl.buffer.nio;
exports org.tensorflow.ndarray.impl.buffer.raw;
exports org.tensorflow.ndarray.impl.dense;
exports org.tensorflow.ndarray.impl.dimension;
exports org.tensorflow.ndarray.impl.sequence;
exports org.tensorflow.ndarray.impl.sparse;
exports org.tensorflow.ndarray.impl.sparse.slice;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
Copyright 2019 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=======================================================================
*/
package org.tensorflow.ndarray;

import org.tensorflow.ndarray.buffer.BooleanDataBuffer;
import org.tensorflow.ndarray.buffer.DataBuffer;
import org.tensorflow.ndarray.index.Index;

/** An {@link NdArray} of booleans. */
public interface BooleanNdArray extends NdArray<Boolean> {

/**
* Returns the boolean value of the scalar found at the given coordinates.
*
* <p>To access the scalar element, the number of coordinates provided must be equal to the number
* of dimensions of this array (i.e. its rank). For example:
*
* <pre>{@code
* BooleanNdArray matrix = NdArrays.ofBooleans(shape(2, 2)); // matrix rank = 2
* matrix.getBoolean(0, 1); // succeeds, returns false
* matrix.getBoolean(0); // throws IllegalRankException
*
* BooleanNdArray scalar = matrix.get(0, 1); // scalar rank = 0
* scalar.getBoolean(); // succeeds, returns false
* }</pre>
*
* @param coordinates coordinates of the scalar to resolve
* @return value of that scalar
* @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
* respective dimension
* @throws IllegalRankException if number of coordinates is not sufficient to access a scalar
* element
*/
boolean getBoolean(long... coordinates);

/**
* Assigns the boolean value of the scalar found at the given coordinates.
*
* <p>To access the scalar element, the number of coordinates provided must be equal to the number
* of dimensions of this array (i.e. its rank). For example:
*
* <pre>{@code
* BooleanNdArray matrix = NdArrays.ofBooleans(shape(2, 2)); // matrix rank = 2
* matrix.setBoolean(true, 0, 1); // succeeds
* matrix.setBoolean(true, 0); // throws IllegalRankException
*
* BooleanNdArray scalar = matrix.get(0, 1); // scalar rank = 0
* scalar.setBoolean(true); // succeeds
* }</pre>
*
* @param value the value to assign
* @param coordinates coordinates of the scalar to assign
* @return this array
* @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
* respective dimension
* @throws IllegalRankException if number of coordinates is not sufficient to access a scalar
* element
*/
BooleanNdArray setBoolean(boolean value, long... coordinates);

@Override
BooleanNdArray withShape(Shape shape);

@Override
BooleanNdArray slice(Index... indices);

@Override
BooleanNdArray get(long... coordinates);

@Override
BooleanNdArray set(NdArray<Boolean> src, long... coordinates);

@Override
default Boolean getObject(long... coordinates) {
return getBoolean(coordinates);
}

@Override
default BooleanNdArray setObject(Boolean value, long... coordinates) {
return setBoolean(value, coordinates);
}

@Override
NdArraySequence<BooleanNdArray> elements(int dimensionIdx);

@Override
NdArraySequence<BooleanNdArray> scalars();

@Override
BooleanNdArray copyTo(NdArray<Boolean> dst);

@Override
BooleanNdArray copyTo(DataBuffer<Boolean> dst);

BooleanNdArray copyTo(BooleanDataBuffer dst);

@Override
BooleanNdArray copyFrom(DataBuffer<Boolean> src);

BooleanNdArray copyFrom(BooleanDataBuffer src);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
Copyright 2019 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=======================================================================
*/
package org.tensorflow.ndarray;

import org.tensorflow.ndarray.buffer.ByteDataBuffer;
import org.tensorflow.ndarray.buffer.DataBuffer;
import org.tensorflow.ndarray.index.Index;

/** An {@link NdArray} of bytes. */
public interface ByteNdArray extends NdArray<Byte> {

/**
* Returns the byte value of the scalar found at the given coordinates.
*
* <p>To access the scalar element, the number of coordinates provided must be equal to the number
* of dimensions of this array (i.e. its rank). For example:
*
* <pre>{@code
* ByteNdArray matrix = NdArrays.ofBytes(shape(2, 2)); // matrix rank = 2
* matrix.getByte(0, 1); // succeeds, returns 0
* matrix.getByte(0); // throws IllegalRankException
*
* ByteNdArray scalar = matrix.get(0, 1); // scalar rank = 0
* scalar.getByte(); // succeeds, returns 0
* }</pre>
*
* @param coordinates coordinates of the scalar to resolve
* @return value of that scalar
* @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
* respective dimension
* @throws IllegalRankException if number of coordinates is not sufficient to access a scalar
* element
*/
byte getByte(long... coordinates);

/**
* Assigns the byte value of the scalar found at the given coordinates.
*
* <p>To access the scalar element, the number of coordinates provided must be equal to the number
* of dimensions of this array (i.e. its rank). For example:
*
* <pre>{@code
* ByteNdArray matrix = NdArrays.ofBytes(shape(2, 2)); // matrix rank = 2
* matrix.setByte(10, 0, 1); // succeeds
* matrix.setByte(10, 0); // throws IllegalRankException
*
* ByteNdArray scalar = matrix.get(0, 1); // scalar rank = 0
* scalar.setByte(10); // succeeds
* }</pre>
*
* @param value the value to assign
* @param coordinates coordinates of the scalar to assign
* @return this array
* @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
* respective dimension
* @throws IllegalRankException if number of coordinates is not sufficient to access a scalar
* element
*/
ByteNdArray setByte(byte value, long... coordinates);

@Override
ByteNdArray withShape(Shape shape);

@Override
ByteNdArray slice(Index... indices);

@Override
ByteNdArray get(long... coordinates);

@Override
ByteNdArray set(NdArray<Byte> src, long... coordinates);

@Override
default Byte getObject(long... coordinates) {
return getByte(coordinates);
}

@Override
default ByteNdArray setObject(Byte value, long... coordinates) {
return setByte(value, coordinates);
}

@Override
NdArraySequence<ByteNdArray> elements(int dimensionIdx);

@Override
NdArraySequence<ByteNdArray> scalars();

@Override
ByteNdArray copyTo(NdArray<Byte> dst);

@Override
ByteNdArray copyTo(DataBuffer<Byte> dst);

ByteNdArray copyTo(ByteDataBuffer dst);

@Override
ByteNdArray copyFrom(DataBuffer<Byte> src);

ByteNdArray copyFrom(ByteDataBuffer src);
}
Loading
Loading