Logically, the N-dimensional array can be flatten in a single vector, where the scalars of
- * the {@code (n - 1)}th element precedes those of the {@code (n)}th element, for a total of
- * {@link #size()} values.
- *
- *
For example, given a {@code n x m} matrix on the {@code [x, y]} axes, elements are iterated in
- * the following order:
- *
The returned sequence can then be iterated to visit each elements, either by calling
- * {@link NdArraySequence#forEach(Consumer)} or {@link NdArraySequence#forEachIndexed(BiConsumer)}.
- *
> elements(int dimensionIdx);
-
- /**
- * Returns a sequence of all scalars in this array.
- *
- * This is equivalent to call {@code elements(shape().numDimensions() - 1)}
- *
- * @return an {@code NdArray} sequence
- */
- NdArraySequence extends NdArray> scalars();
-
- /**
- * Creates a multi-dimensional view (or slice) of this array by mapping one or more dimensions
- * to the given index selectors.
- *
- * Slices allow to traverse an N-dimensional array in any of its axis and/or to filter only
- * elements of interest. For example, for a given matrix on the {@code [x, y]} axes, it is
- * possible to iterate elements at {@code y=0} for all {@code x}.
- *
- *
Any changes applied to the returned slice affect the data of this array as well, as there
- * is no copy involved.
- *
- *
Example of usage:
- *
{@code
- * FloatNdArray matrix3d = NdArrays.ofFloats(shape(3, 2, 4)); // with [x, y, z] axes
- *
- * // Iterates elements on the x axis by preserving only the 3rd value on the z axis,
- * // (i.e. [x, y, 2])
- * matrix3d.slice(all(), all(), at(2)).elements(0).forEach(m -> {
- * assertEquals(shape(2), m); // y=2, z=0 (scalar)
- * });
- *
- * // Creates a slice that contains only the last element of the y axis and elements with an
- * // odd `z` coordinate.
- * FloatNdArray slice = matrix3d.slice(all(), at(1), odd());
- * assertEquals(shape(3, 2), slice.shape()); // x=3, y=0 (scalar), z=2 (odd coordinates)
- *
- * // Iterates backward the elements on the x axis
- * matrix3d.slice(flip()).elements(0).forEach(m -> {
- * assertEquals(shape(2, 4), m); // y=2, z=4
- * });
- * }
- *
- * @param indices index selectors per dimensions, starting from dimension 0 of this array.
- * @return the element resulting of the index selection
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
- * respective dimension
- */
- NdArray slice(Index... indices);
-
- /**
- * Returns the N-dimensional element of this array at the given coordinates.
- *
- * Elements of any of the dimensions of this array can be retrieved. For example, if the number
- * of coordinates is equal to the number of dimensions of this array, then a rank-0 (scalar) array
- * is returned, which value can then be obtained by calling `array.getObject()`.
- *
- *
Any changes applied to the returned elements affect the data of this array as well, as there
- * is no copy involved.
- *
- *
Note that invoking this method is an equivalent and more efficient way to slice this array
- * on single scalar, i.e. {@code array.get(x, y, z)} is equal to
- * {@code array.slice(at(x), at(y), at(z))}
- *
- * @param coordinates coordinates of the element to access, none will return this array
- * @return the element at this index
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
- * respective dimension
- */
- NdArray get(long... coordinates);
-
- /**
- * Assigns the value of the N-dimensional element found at the given coordinates.
- *
- * The number of coordinates provided can be anywhere between 0 and rank - 1. For example:
- *
{@code
- * FloatNdArray matrix = NdArrays.ofFloats(shape(2, 2)); // matrix rank = 2
- * matrix.set(vector(10.0f, 20.0f), 0); // success
- * matrix.set(scalar(10.0f), 1, 0); // success
- * }
- *
- * @param src an array of the values to assign
- * @param coordinates coordinates of the element to assign
- * @return this array
- * @throws IndexOutOfBoundsException if some coordinates are outside the limits of their
- * respective dimension
- */
- NdArray set(NdArray src, long... coordinates);
-
- /**
- * Returns the value of the scalar found at the given coordinates.
- *
- * 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:
- *
{@code
- * FloatNdArray matrix = NdArrays.ofFloats(shape(2, 2)); // matrix rank = 2
- * matrix.getObject(0, 1); // succeeds, returns 0.0f
- * matrix.getObject(0); // throws IllegalRankException
- *
- * FloatNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getObject(); // succeeds, returns 0.0f
- * }
- *
- * Note: if this array stores values of a primitive type, prefer the usage of the specialized
- * method in the subclass for that type. For example, {@code floatArray.getFloat(0); }.
- *
- * @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
- */
- T getObject(long... coordinates);
-
- /**
- * Assigns the value of the scalar found at the given coordinates.
- *
- * 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:
- *
{@code
- * FloatNdArray matrix = NdArrays.ofFloats(shape(2, 2)); // matrix rank = 2
- * matrix.setObject(10.0f, 0, 1); // succeeds
- * matrix.setObject(10.0f, 0); // throws IllegalRankException
- *
- * FloatNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setObject(10.0f); // succeeds
- * }
- *
- * Note: if this array stores values of a primitive type, prefer the usage of the specialized
- * method in the subclass for that type. For example, {@code floatArray.setFloat(10.0f, 0); }
- *
- * @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
- */
- NdArray setObject(T value, long... coordinates);
-
- /**
- * Copy the content of this array to the destination array.
- *
- * The {@link #shape()} of the destination array must be equal to the shape of this array, or
- * an exception is thrown. After the copy, the content of both arrays can be altered
- * independently, without affecting each other.
- *
- * @param dst array to receive a copy of the content of this array
- * @return this array
- * @throws IllegalArgumentException if the shape of {@code dst} is not equal to the shape of this
- * array
- */
- NdArray copyTo(NdArray dst);
-
- /**
- * Read the content of this N-dimensional array into the destination buffer.
- *
- * The size of the buffer must be equal or greater to the {@link #size()} of this
- * array, or an exception is thrown. After the copy, content of the buffer and of the array can be
- * altered independently, without affecting each other.
- *
- * @param dst the destination buffer
- * @return this array
- * @throws java.nio.BufferOverflowException if the buffer cannot hold the content of this array
- * @see DataBuffer#size()
- */
- NdArray read(DataBuffer dst);
-
- /**
- * Write the content of this N-dimensional array from the source buffer.
- *
- * The size of the buffer must be equal or greater to the {@link #size()} of this
- * array, or an exception is thrown. After the copy, content of the buffer and of the array can be
- * altered independently, without affecting each other.
- *
- * @param src the source buffer
- * @return this array
- * @throws java.nio.BufferUnderflowException if the buffer has not enough remaining data to write
- * into this array
- * @see DataBuffer#size()
- */
- NdArray write(DataBuffer src);
-
- /**
- * Checks equality between n-dimensional arrays.
- *
- * An array is equal to another object if this object is another {@link NdArray} of the
- * same shape, type and the elements are equal and in the same order. For example:
- *
- *
{@code
- * IntNdArray array = NdArrays.ofInts(Shape.of(2, 2))
- * .set(NdArrays.vectorOf(1, 2), 0)
- * .set(NdArrays.vectorOf(3, 4), 1);
- *
- * assertEquals(array, StdArrays.ndCopyOf(new int[][] {{1, 2}, {3, 4}})); // true
- * assertEquals(array, StdArrays.ndCopyOf(new Integer[][] {{1, 2}, {3, 4}})); // true, as Integers are equal to ints
- * assertNotEquals(array, NdArrays.vectorOf(1, 2, 3, 4)); // false, different shapes
- * assertNotEquals(array, StdArrays.ndCopyOf(new int[][] {{3, 4}, {1, 2}})); // false, different order
- * assertNotEquals(array, StdArrays.ndCopyOf(new long[][] {{1L, 2L}, {3L, 4L}})); // false, different types
- * }
- *
- * Note that the computation required to verify equality between two arrays can be expensive
- * in some cases and therefore, it is recommended to not use this method in a critical path
- * where performances matter.
- *
- * @param obj object to compare this array with
- * @return true if this array is equal to the provided object
- */
- @Override
- boolean equals(Object obj);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/NdArraySequence.java b/ndarray/src/main/java/org/tensorflow/ndarray/NdArraySequence.java
deleted file mode 100644
index afb930e278b..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/NdArraySequence.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 java.util.function.BiConsumer;
-import org.tensorflow.ndarray.buffer.DataBufferWindow;
-
-/**
- * A sequence of elements of an N-dimensional array.
- *
- *
An {@code NdArraySequence} is used to traverse an {@code NdArray} in a given dimension
- * and visit each of its elements. For example, given a {@code n x m} matrix on the {@code [x, y]} axes,
- * elements are iterated in the following order:
- *
x0y0, x0y1, ..., x0ym-1, x1y0, x1y1, ..., xn-1ym-1
- *
- * @param data type of the array being iterated
- */
-public interface NdArraySequence> extends Iterable {
-
- /**
- * Visit each elements of this iteration and their respective coordinates.
- *
- * Important: the consumer method should not keep a reference to the coordinates
- * as they might be mutable and reused during the iteration to improve performance.
- *
- * @param consumer method to invoke for each elements
- */
- void forEachIndexed(BiConsumer consumer);
-
- /**
- * Returns each element as a new slice.
- *
- * Unlike conventional Java collections, elements of a {@code NdArraySequence} are transient, i.e. new {@code NdArray}
- * instances are allocated for each iteration. To improve performance, the same instance can be recycled to view
- * all elements of this sequence, using a {@link DataBufferWindow}.
- *
- *
In some cases though, it might be preferable to disable such optimizations to ensure that each element returned is a
- * new slice of the original array. For example, if one or more elements visited must live beyond the scope of the sequence
- * iteration, {@code asSlices()} makes sure that all elements returned by the sequence are unique instances.
- *
- *
{@code
- * final List vectors = new ArrayList<>();
- * IntNdArray matrix = NdArrays.ofInts(Shape.of(6, 6));
- * ndArray.elements(0).forEach(e -> vectors::add); // Not safe, as `e` might always be the same recycled instance
- * ndArray.elements(0).asSlices().forEach(e -> vectors::add); // Safe, each `e` is a distinct NdArray instance
- * }
- *
- * @return a sequence that returns each elements iterated as a new slice
- * @see DataBufferWindow
- */
- NdArraySequence asSlices();
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/NdArrays.java b/ndarray/src/main/java/org/tensorflow/ndarray/NdArrays.java
deleted file mode 100644
index 8ad55cae7ed..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/NdArrays.java
+++ /dev/null
@@ -1,495 +0,0 @@
-/*
- 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.impl.dense.DenseNdArray;
-import org.tensorflow.ndarray.impl.dense.IntDenseNdArray;
-import org.tensorflow.ndarray.buffer.BooleanDataBuffer;
-import org.tensorflow.ndarray.buffer.ByteDataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.buffer.DataBuffers;
-import org.tensorflow.ndarray.buffer.DoubleDataBuffer;
-import org.tensorflow.ndarray.buffer.FloatDataBuffer;
-import org.tensorflow.ndarray.buffer.IntDataBuffer;
-import org.tensorflow.ndarray.buffer.LongDataBuffer;
-import org.tensorflow.ndarray.buffer.ShortDataBuffer;
-import org.tensorflow.ndarray.impl.dense.BooleanDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.ByteDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.DoubleDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.FloatDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.LongDenseNdArray;
-import org.tensorflow.ndarray.impl.dense.ShortDenseNdArray;
-
-/**
- * Utility class for instantiating {@link NdArray} objects.
- */
-public final class NdArrays {
-
- // BYTE ARRAYS
-
- /**
- * Creates byte scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new byte scalar
- */
- public static ByteNdArray scalarOf(byte value) {
- return ofBytes(Shape.scalar()).setByte(value);
- }
-
- /**
- * Creates a byte vector (rank 1) initialized with the given values.
- *
- * Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new byte vector
- * @throws IllegalArgumentException if values is null
- */
- public static ByteNdArray vectorOf(byte... values) {
- if (values == null) {
- throw new IllegalArgumentException("Values cannot be null");
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of bytes of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new byte N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static ByteNdArray ofBytes(Shape shape) {
- if (shape == null) {
- throw new IllegalArgumentException("Shape cannot be null");
- }
- return wrap(shape, DataBuffers.ofBytes(shape.size()));
- }
-
- /**
- * Wraps a buffer in a byte N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new byte N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static ByteNdArray wrap(Shape shape, ByteDataBuffer buffer) {
- return ByteDenseNdArray.create(buffer, shape);
- }
-
- // LONG ARRAYS
-
- /**
- * Creates long scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new long scalar
- */
- public static LongNdArray scalarOf(long value) {
- return ofLongs(Shape.scalar()).setLong(value);
- }
-
- /**
- * Creates a long vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new long vector
- * @throws IllegalArgumentException if values is null
- */
- public static LongNdArray vectorOf(long... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of longs of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new long N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static LongNdArray ofLongs(Shape shape) {
- return wrap(shape, DataBuffers.ofLongs(shape.size()));
- }
-
- /**
- * Wraps a buffer in a long N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new long N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static LongNdArray wrap(Shape shape, LongDataBuffer buffer) {
- return LongDenseNdArray.create(buffer, shape);
- }
-
- // INT ARRAYS
-
- /**
- * Creates long scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new long scalar
- */
- public static IntNdArray scalarOf(int value) {
- return ofInts(Shape.scalar()).setInt(value);
- }
-
- /**
- * Creates a int vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new int vector
- * @throws IllegalArgumentException if values is null
- */
- public static IntNdArray vectorOf(int... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of ints of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new int N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static IntNdArray ofInts(Shape shape) {
- return wrap(shape, DataBuffers.ofInts(shape.size()));
- }
-
- /**
- * Wraps a buffer in an int N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new int N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static IntNdArray wrap(Shape shape, IntDataBuffer buffer) {
- return IntDenseNdArray.create(buffer, shape);
- }
-
- // SHORT ARRAYS
-
- /**
- * Creates short scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new short scalar
- */
- public static ShortNdArray scalarOf(short value) {
- return ofShorts(Shape.scalar()).setShort(value);
- }
-
- /**
- * Creates a short vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new short vector
- * @throws IllegalArgumentException if values is null
- */
- public static ShortNdArray vectorOf(short... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of shorts of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new short N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static ShortNdArray ofShorts(Shape shape) {
- return wrap(shape, DataBuffers.ofShorts(shape.size()));
- }
-
- /**
- * Wraps a buffer in a short N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new short N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static ShortNdArray wrap(Shape shape, ShortDataBuffer buffer) {
- return ShortDenseNdArray.create(buffer, shape);
- }
-
- // FLOAT ARRAYS
-
- /**
- * Creates float scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new float scalar
- */
- public static FloatNdArray scalarOf(float value) {
- return ofFloats(Shape.scalar()).setFloat(value);
- }
-
- /**
- * Creates a float vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new float vector
- * @throws IllegalArgumentException if values is null
- */
- public static FloatNdArray vectorOf(float... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of floats of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new float N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static FloatNdArray ofFloats(Shape shape) {
- return wrap(shape, DataBuffers.ofFloats(shape.size()));
- }
-
- /**
- * Wraps a buffer in a float N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new float N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static FloatNdArray wrap(Shape shape, FloatDataBuffer buffer) {
- return FloatDenseNdArray.create(buffer, shape);
- }
-
- // DOUBLE ARRAYS
-
- /**
- * Creates double scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new double scalar
- */
- public static DoubleNdArray scalarOf(double value) {
- return ofDoubles(Shape.scalar()).setDouble(value);
- }
-
- /**
- * Creates a double vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new double vector
- * @throws IllegalArgumentException if values is null
- */
- public static DoubleNdArray vectorOf(double... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of doubles of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new double N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static DoubleNdArray ofDoubles(Shape shape) {
- return wrap(shape, DataBuffers.ofDoubles(shape.size()));
- }
-
- /**
- * Wraps a buffer in a double N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new double N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static DoubleNdArray wrap(Shape shape, DoubleDataBuffer buffer) {
- return DoubleDenseNdArray.create(buffer, shape);
- }
-
- // BOOLEAN ARRAYS
-
- /**
- * Creates boolean scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @return new boolean scalar
- */
- public static BooleanNdArray scalarOf(boolean value) {
- return ofBooleans(Shape.scalar()).setBoolean(value);
- }
-
- /**
- * Creates a boolean vector (rank 1) initialized with the given values.
- *
- *
Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @return new boolean vector
- * @throws IllegalArgumentException if values is null
- */
- public static BooleanNdArray vectorOf(boolean... values) {
- if (values == null) {
- throw new IllegalArgumentException();
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of booleans of the given shape.
- *
- *
All values are initialized to zeros.
- *
- * @param shape shape of the array
- * @return new boolean N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static BooleanNdArray ofBooleans(Shape shape) {
- return wrap(shape, DataBuffers.ofBooleans(shape.size()));
- }
-
- /**
- * Wraps a buffer in a boolean N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @return new boolean N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static BooleanNdArray wrap(Shape shape, BooleanDataBuffer buffer) {
- return BooleanDenseNdArray.create(buffer, shape);
- }
-
- // OBJECT ARRAYS
-
- /**
- * Creates scalar (rank 0) initialized with the given value.
- *
- * @param value scalar value
- * @param the data type
- * @return new scalar
- */
- @SuppressWarnings("unchecked")
- public static NdArray scalarOfObject(T value) {
- if (value == null) {
- throw new IllegalArgumentException();
- }
- return ofObjects((Class)value.getClass(), Shape.scalar()).setObject(value);
- }
-
- /**
- * Creates a vector (rank 1) initialized with the given values.
- *
- * Modifying the data of the returned vector will also impact the values in the array
- * passed in parameter.
- *
- * @param values vector values
- * @param the data type
- * @return new vector
- * @throws IllegalArgumentException if values is null
- */
- @SafeVarargs
- public static NdArray vectorOfObjects(T... values) {
- if (values == null || values.length == 0) {
- throw new IllegalArgumentException("Null or zero length input supplied to vectorOfObjects.");
- }
- return wrap(Shape.of(values.length), DataBuffers.of(values, false, false));
- }
-
- /**
- * Creates an N-dimensional array of the given shape.
- *
- * All values are initialized to zeros.
- *
- * @param clazz class of the data to be stored in this array
- * @param shape shape of the array
- * @param the data type
- * @return new N-dimensional array
- * @throws IllegalArgumentException if shape is null or has unknown dimensions
- */
- public static NdArray ofObjects(Class clazz, Shape shape) {
- return wrap(shape, DataBuffers.ofObjects(clazz, shape.size()));
- }
-
- /**
- * Wraps a buffer in an N-dimensional array of a given shape.
- *
- * @param shape shape of the array
- * @param buffer buffer to wrap
- * @param the data type
- * @return new N-dimensional array
- * @throws IllegalArgumentException if shape is null, has unknown dimensions or has size bigger
- * in the buffer size
- */
- public static NdArray wrap(Shape shape, DataBuffer buffer) {
- return DenseNdArray.wrap(buffer, shape);
- }
-}
-
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/Shape.java b/ndarray/src/main/java/org/tensorflow/ndarray/Shape.java
deleted file mode 100644
index 85a905408c7..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/Shape.java
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
-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 java.util.Arrays;
-
-/**
- * The shape of a Tensor or {@link NdArray}.
- *
- * A {@code Shape} defines sizes along its axes. It may contain an unknown size for one of the
- * axes or may be totally unknown, in which case not even the number of axes is known. If the size
- * of an axis is unknown, {@link Shape#UNKNOWN_SIZE} should be used as its size.
- */
-public final class Shape {
-
- /** The size of an unknown axis or the total unknown size for an unknown Shape. */
- public static long UNKNOWN_SIZE = -1L;
-
- /**
- * Creates a Shape representing an unknown number of dimensions.
- *
- * @return A Shape for which {@link Shape#isUnknown()} is true, never null.
- */
- public static Shape unknown() {
- return new Shape(null);
- }
-
- /**
- * Creates a Shape representing a scalar value.
- *
- * @return A Shape without dimensions for which {@link Shape#isScalar()} is true, never null.
- */
- public static Shape scalar() {
- return new Shape(new long[0]);
- }
-
- /**
- * Create a Shape representing a scalar or an N-dimensional value.
- *
- *
Creates a Shape representing a scalar or an N-dimensional value (N being at least 1), with
- * the provided size for each dimension. A -1 indicates that the size of the corresponding
- * dimension is unknown. If no sizes are provided, a Shape representing a scalar is created. For
- * example:
- *
- *
{@code
- * // A 2-element vector.
- * Shape vector = Shape.of(2);
- *
- * // A 2x3 matrix.
- * Shape matrix = Shape.of(2, 3);
- *
- * // A matrix with 4 columns but an unknown number of rows.
- * // This is typically used to indicate the shape of tensors that represent
- * // a variable-sized batch of values. The Shape below might represent a
- * // variable-sized batch of 4-element vectors.
- * Shape batch = Shape.of(-1, 4);
- *
- * // A scalar. For readability, you should prefer calling Shape.scalar()
- * Shape scalar = Shape.of()
- * }
- *
- * @param dimensionSizes number of elements in each dimension of this shape, if any, or
- * {@link Shape#UNKNOWN_SIZE} if unknown.
- * @return a new shape
- */
- public static Shape of(long... dimensionSizes) {
- if (dimensionSizes == null || dimensionSizes.length == 0) {
- return scalar();
- }
- return new Shape(dimensionSizes);
- }
-
- /**
- * Returns the total number of elements a Tensor with this Shape would have.
- *
- * If {@link Shape#isUnknown()} is true or {@link Shape#hasUnknownDimension()} is true, {@link
- * Shape#UNKNOWN_SIZE} is returned.
- *
- * @return The total number of elements a Tensor with this shape would have if it can be
- * calculated, else {@link Shape#UNKNOWN_SIZE}.
- */
- public long size() {
- if (size == null) {
- size = computeSize(dimensionSizes);
- }
- return size;
- }
-
- /**
- * The size of the dimension with the given index.
- *
- *
If {@link Shape#isUnknown()} is true or the size of the dimension with the given index has
- * an unknown size, {@link Shape#UNKNOWN_SIZE} is returned.
- *
- * @param i the index of the dimension to get the size for. If this Shape has a known number of
- * dimensions, it must be < {@link Shape#numDimensions()}. The index may be negative, in which
- * case the position is counted from the end of the shape. E.g.: {@code size(-1)} returns the
- * size of the last dimension, {@code size(-2)} the size of the second to last dimension etc.
- * @return The size of the dimension with the given index if known, {@link Shape#UNKNOWN_SIZE}
- * otherwise.
- */
- public long size(int i) {
- if (dimensionSizes == null) {
- return UNKNOWN_SIZE;
- } else if (i >= 0) {
- return dimensionSizes[i];
- } else {
- return dimensionSizes[dimensionSizes.length + i];
- }
- }
-
- /**
- * Returns the number of dimensions of this Shape. -1 if unknown, 0 for a scalar, 1 for a vector,
- * 2 for a matrix etc.
- */
- public int numDimensions() {
- return dimensionSizes != null ? dimensionSizes.length : -1;
- }
-
- /** Returns whether one or more dimensions of this Shape have an unknown size. */
- public boolean hasUnknownDimension() {
- if (dimensionSizes == null) {
- return true;
- }
- for (long dimSize : dimensionSizes) {
- if (dimSize == UNKNOWN_SIZE) {
- return true;
- }
- }
- return false;
- }
-
- /** Returns whether this Shape represents a scalar. */
- public boolean isScalar() {
- return dimensionSizes != null && dimensionSizes.length == 0;
- }
-
- /** Returns whether this Shape is the shape of a vector. */
- public boolean isVector() {
- return dimensionSizes != null && dimensionSizes.length == 1;
- }
-
- /** Returns whether this Shape is the shape of a matrix */
- public boolean isMatrix() {
- return dimensionSizes != null && dimensionSizes.length == 2;
- }
-
- /** Returns whether the number of dimensions of this Shape is unknown. */
- public boolean isUnknown() {
- return dimensionSizes == null;
- }
-
- /**
- * Returns a defensive copy of the this Shape's axes. Changes to the returned array to not change
- * this Shape's state. Returns null if {@link Shape#isUnknown()} is true.
- */
- public long[] asArray() {
- if (this.dimensionSizes == null) {
- return null;
- } else {
- return Arrays.copyOf(dimensionSizes, dimensionSizes.length);
- }
- }
-
- @Override
- public int hashCode() {
- return dimensionSizes != null ? Arrays.hashCode(dimensionSizes) : super.hashCode();
- }
-
- /**
- * Equals implementation for Shapes. Two Shapes are considered equal iff:
- *
- *
- *
- * - the number of dimensions is defined and equal for both
- *
- the size of each dimension is defined and equal for both
- *
- *
- * If either Shape has unknown dimensions (even if they are the same in both) or if either
- * shape has an unknown number of dimensions (even if both return {@code true} for {@link
- * Shape#isUnknown()}), they are not considered equal! However, a shape will always equal itself,
- * even if it is unknown or contains unknown dimensions.
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- // Shapes are equivalent if all of their dimensions are equals
- if (obj instanceof Shape) {
- Shape otherShape = (Shape) obj;
- if (otherShape.hasUnknownDimension()) {
- return false;
- }
- return Arrays.equals(dimensionSizes, otherShape.dimensionSizes);
- }
- return false;
- }
-
- /** Succinct description of the Shape meant for debugging. */
- @Override
- public String toString() {
- return Arrays.toString(dimensionSizes);
- }
-
- private Shape(long[] dimensionSizes) {
- this.dimensionSizes = dimensionSizes;
- }
-
- private final long[] dimensionSizes;
- private Long size;
-
- /**
- * Returns a 1-dimensional Shape with first dimension matching the first dimension of this Shape.
- */
- public Shape head() {
- return take(1);
- }
-
- /**
- * Returns an n-dimensional Shape with the dimensions matching the first n dimensions of this
- * shape
- *
- * @param n the number of leading dimensions to get, must be <= than {@link Shape#numDimensions()}
- * @return an n-dimensional Shape with the first n dimensions matching the first n dimensions of
- * this Shape
- */
- public Shape take(int n) {
- if (n > numDimensions()) {
- throw new ArrayIndexOutOfBoundsException(
- "Cannot take " + n + " dimensions, shape has only " + numDimensions() + ".");
- }
- long[] newDimensions = new long[n];
- System.arraycopy(dimensionSizes, 0, newDimensions, 0, n);
- return Shape.of(newDimensions);
- }
-
- /** Returns a new Shape, with this Shape's first dimension removed. */
- public Shape tail() {
- if (dimensionSizes.length < 2) return Shape.of();
- return Shape.of(Arrays.copyOfRange(dimensionSizes, 1, dimensionSizes.length));
- }
-
- /**
- * Returns an n-dimensional Shape with the dimensions matching the last n dimensions of this
- * Shape.
- *
- * @param n the number of trailing dimensions to get, must be <= than {@link
- * Shape#numDimensions()}
- * @return an n-dimensional shape with the dimensions matching the last n dimensions of this
- * Shape, never null
- */
- public Shape takeLast(int n) {
- if (n > numDimensions()) {
- throw new ArrayIndexOutOfBoundsException(
- "Cannot take last " + n + " dimensions, shape has only " + numDimensions() + ".");
- }
- long[] newDimensions = new long[n];
- System.arraycopy(dimensionSizes, numDimensions() - n, newDimensions, 0, n);
- return Shape.of(newDimensions);
- }
-
- /**
- * Return a {@code end - begin} dimensional shape with dimensions matching this Shape from {@code begin} to {@code end}.
- * @param begin Where to start the sub-shape.
- * @param end Where to end the sub-shape, exclusive.
- * @return the sub-shape bounded by begin and end.
- */
- public Shape subShape(int begin, int end){
- if (end > numDimensions()) {
- throw new ArrayIndexOutOfBoundsException(
- "End index " + end + " out of bounds: shape only has " + numDimensions() + " dimensions.");
- }
- if (begin < 0) {
- throw new ArrayIndexOutOfBoundsException(
- "Begin index " + begin + " out of bounds: cannot be less than 0.");
- }
-
- long[] newDimensions = new long[end - begin];
- System.arraycopy(dimensionSizes, begin, newDimensions, 0, end - begin);
- return Shape.of(newDimensions);
- }
-
- /**
- * Returns a new Shape, with a new first dimension added. In order for this call to succeed,
- * {@link Shape#isUnknown()} must be {@code false}.
- *
- * @param firstDimension the dimension to prepend
- * @return a new shape with the given dimension first, followed by this Shape's dimensions, never
- * null
- */
- public Shape prepend(long firstDimension) {
- long[] newDimensions = new long[dimensionSizes.length + 1];
- newDimensions[0] = firstDimension;
- System.arraycopy(dimensionSizes, 0, newDimensions, 1, dimensionSizes.length);
-
- return Shape.of(newDimensions);
- }
-
- /**
- * Returns a new Shape, with a new last dimension added. In order for this call to succeed, {@link
- * Shape#isUnknown()} must be {@code false}.
- *
- * @param lastDimension the dimension to append
- * @return a new Shape with this Shape's dimensions followed by the given dimension, never null
- */
- public Shape append(long lastDimension) {
- long[] newDimensions = new long[dimensionSizes.length + 1];
- newDimensions[newDimensions.length - 1] = lastDimension;
- System.arraycopy(dimensionSizes, 0, newDimensions, 0, dimensionSizes.length);
-
- return Shape.of(newDimensions);
- }
-
- /**
- * Returns a new Shape, with another Shape's dimensions prepended. For both this Shape and the
- * other Shape, {@link Shape#isUnknown()} must return false. E.g. {@code
- * Shape.of(3,4).prepend(Shape.of(1,2)) => Shape.of(1,2,3,4) }
- *
- * @param other another Shape, must not be {@code null}, must not be unknown
- * @return A new Shape consisting of the given Shape's dimensions followed by this Shape's
- * dimensions, never null
- */
- public Shape prepend(Shape other) {
- long[] newDimensions = new long[other.dimensionSizes.length + dimensionSizes.length];
- System.arraycopy(other.dimensionSizes, 0, newDimensions, 0, other.dimensionSizes.length);
- System.arraycopy(
- dimensionSizes, 0, newDimensions, other.dimensionSizes.length, dimensionSizes.length);
- return Shape.of(newDimensions);
- }
-
- /**
- * Returns a new Shape, with another Shapes' dimensions appended. For both this Shape and the
- * other Shape, {@link Shape#isUnknown()} must return false. E.g. @code
- * Shape.of(3,4).append(Shape.of(1,2)) => Shape.of(3,4,1,2) }
- *
- * @param other another Shape, must not be {@code null}, must not be unknown
- * @return A new Shape consisting of this Shape's dimensions followed by the given Shape's
- * dimensions
- */
- public Shape append(Shape other) {
- long[] newDimensions = new long[dimensionSizes.length + other.dimensionSizes.length];
- System.arraycopy(dimensionSizes, 0, newDimensions, 0, dimensionSizes.length);
- System.arraycopy(
- other.dimensionSizes, 0, newDimensions, dimensionSizes.length, other.dimensionSizes.length);
- return Shape.of(newDimensions);
- }
-
- private static long computeSize(long[] dimensionSizes) {
- if (dimensionSizes == null) {
- return UNKNOWN_SIZE;
- }
- long computedSize = 1L;
- for (long dimensionSize : dimensionSizes) {
- if (dimensionSize == UNKNOWN_SIZE) {
- return UNKNOWN_SIZE;
- }
- computedSize *= dimensionSize;
- }
- return computedSize;
- }
-
- /**
- * Determines whether another shape is compatible with this one.
- *
- *
- *
- *
Two possibly-partially-defined shapes are compatible if there exists a fully-defined shape
- * that both shapes can represent. Thus, compatibility allows the shape inference code to reason
- * about partially-defined shapes. For example:
- *
- *
- * Shape.unknown()
is compatible with all shapes.
- * Shape(UNKNOWN_SIZE, UNKNOWN_SIZE)
is compatible with all two-dimensional
- * shapes, such as Shape(32, 784)
, and also Shape.unknown()
. It is
- * not compatible with, for example, Shape(UNKNOWN_SIZE)
or
- * Shape(UNKNOWN_SIZE, UNKNOWN_SIZE, UNKNOWN_SIZE)
.
- * Shape(32, UNKNOWN_SIZE)
is compatible with all two-dimensional shapes with
- * size 32 in the 0th dimension, and also Shape(UNKNOWN_SIZE, UNKNOWN_SIZE)
and
- * Shape.unknown()
. It is not compatible with, for example, Shape(32)
- *
, Shape(32, UNKNOWN_SIZE, 1)
or Shape(64, UNKNOWN_SIZE)
.
- * Shape(32, 784)
is compatible with itself, and also
- * Shape(32, UNKNOWN_SIZE)
, Shape(UNKNOWN_SIZE, 784)
,
- * Shape(UNKNOWN_SIZE, UNKNOWN_SIZE)
and Shape.unknown()
. It is not
- * compatible with, for example, Shape(32, 1, 784)
or Shape(UNKNOWN_SIZE)
- *
.
- *
- *
- * The compatibility relation is reflexive and symmetric, but not transitive. For example,
- * Shape(32, 784)
is compatible with Shape.unknown()
, and
- * Shape.unknown()
is compatible with Shape(4, 4)
, but Shape(32, 784)
- *
is not compatible with Shape(4, 4)
.
- *
- *
Compatibility is not the same as broadcasting. Compatible shapes must have the same number
- * of dimensions and for each dimension pair, one dimension has to equal the other dimensions or
- * at least one of the dimensions in the pair has to be UNKNOWN_SIZE.
- *
- *
Broadcasting allows different dimensions, but paired dimensions have to either be equal, or
- * one dimension must be 1. If one shape has less dimensions than another shape, the smaller shape
- * is "stretched" with dimensions of 1.
- *
- * @param shape The other shape
- * @return true, if the two shapes are compatible.
- */
- public boolean isCompatibleWith(Shape shape) {
- if (!this.isUnknown() && !shape.isUnknown()) {
- if (numDimensions() != shape.numDimensions()) {
- return false;
- }
- for (int i = 0; i < numDimensions(); i++) {
- if (!isCompatible(size(i), shape.size(i))) {
- return false;
- }
- }
- }
- return true;
- }
-
- /**
- * Test to see if two shape dimensions are compatible.
- *
- *
The dimensions are compatible if either dimension is Shape.UNKNOWN_SIZE
or both
- * dimensions are equal
- *
- * @param dim the first dimension
- * @param otherDim the second dimension
- * @return true, if both dimensions are compatible
- */
- public static boolean isCompatible(long dim, long otherDim) {
- return dim == Shape.UNKNOWN_SIZE || otherDim == Shape.UNKNOWN_SIZE || dim == otherDim;
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/Shaped.java b/ndarray/src/main/java/org/tensorflow/ndarray/Shaped.java
deleted file mode 100644
index fbe19d75623..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/Shaped.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- Copyright 2020 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 java.util.function.BiConsumer;
-import java.util.function.Consumer;
-import org.tensorflow.ndarray.buffer.DataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * Any data container with a given {@link Shape}.
- */
-public interface Shaped {
-
- /**
- * @return the shape of this container
- */
- Shape shape();
-
- /**
- * @return the rank of this container
- */
- default int rank() {
- return shape().numDimensions();
- }
-
- /**
- * Computes and returns the total size of this container, in number of values.
- *
- *
For example, given a 3x3x2 matrix, the return value will be 18.
- *
- * @return number of values in this element
- */
- default long size() {
- return shape().size();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java
deleted file mode 100644
index f9335b4d5d2..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- 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.DataBuffer;
-import org.tensorflow.ndarray.buffer.ShortDataBuffer;
-import org.tensorflow.ndarray.index.Index;
-
-/**
- * An {@link NdArray} of shorts.
- */
-public interface ShortNdArray extends NdArray {
-
- /**
- * Returns the short value of the scalar found at the given coordinates.
- *
- * 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:
- *
{@code
- * ShortNdArray matrix = NdArrays.ofShorts(shape(2, 2)); // matrix rank = 2
- * matrix.getShort(0, 1); // succeeds, returns 0.0f
- * matrix.getShort(0); // throws IllegalRankException
- *
- * ShortNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.getShort(); // succeeds, returns 0.0f
- * }
- *
- * @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
- */
- short getShort(long... coordinates);
-
- /**
- * Assigns the short value of the scalar found at the given coordinates.
- *
- * 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:
- *
{@code
- * ShortNdArray matrix = NdArrays.ofShorts(shape(2, 2)); // matrix rank = 2
- * matrix.setShort(10.0f, 0, 1); // succeeds
- * matrix.setShort(10.0f, 0); // throws IllegalRankException
- *
- * ShortNdArray scalar = matrix.get(0, 1); // scalar rank = 0
- * scalar.setShort(10.0f); // succeeds
- * }
- *
- * @param value 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
- */
- ShortNdArray setShort(short value, long... coordinates);
-
- @Override
- ShortNdArray slice(Index... coordinates);
-
- @Override
- ShortNdArray get(long... coordinates);
-
- @Override
- ShortNdArray set(NdArray src, long... coordinates);
-
- @Override
- default Short getObject(long... coordinates) {
- return getShort(coordinates);
- }
-
- @Override
- default ShortNdArray setObject(Short value, long... coordinates) {
- return setShort(value, coordinates);
- }
-
- @Override
- NdArraySequence elements(int dimensionIdx);
-
- @Override
- NdArraySequence scalars();
-
- @Override
- ShortNdArray copyTo(NdArray dst);
-
- @Override
- ShortNdArray read(DataBuffer dst);
-
- ShortNdArray read(ShortDataBuffer dst);
-
- @Override
- ShortNdArray write(DataBuffer src);
-
- ShortNdArray write(ShortDataBuffer src);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/StdArrays.java b/ndarray/src/main/java/org/tensorflow/ndarray/StdArrays.java
deleted file mode 100644
index 7d847bd1a9c..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/StdArrays.java
+++ /dev/null
@@ -1,3809 +0,0 @@
-package org.tensorflow.ndarray;
-
-import static org.tensorflow.ndarray.NdArrays.vectorOf;
-
-import java.lang.reflect.Array;
-import org.tensorflow.ndarray.buffer.DataBuffers;
-
-/**
- * Utility class for working with {@link NdArray} instances mixed with standard Java arrays.
- */
-public final class StdArrays {
-
- /**
- * Copy an array of ints in a new {@link IntNdArray}
- *
- * @param array source array
- * @return the {@code IntNdArray} copy
- */
- public static IntNdArray ndCopyOf(int[] array) {
- IntNdArray ndArray = NdArrays.ofInts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 2-dimensional array of ints in a new {@link IntNdArray}
- *
- * @param array source array
- * @return the {@code IntNdArray} copy
- */
- public static IntNdArray ndCopyOf(int[][] array) {
- IntNdArray ndArray = NdArrays.ofInts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 3-dimensional array of ints in a new {@link IntNdArray}
- *
- * @param array source array
- * @return the {@code IntNdArray} copy
- */
- public static IntNdArray ndCopyOf(int[][][] array) {
- IntNdArray ndArray = NdArrays.ofInts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 4-dimensional array of ints in a new {@link IntNdArray}
- *
- * @param array source array
- * @return the {@code IntNdArray} copy
- */
- public static IntNdArray ndCopyOf(int[][][][] array) {
- IntNdArray ndArray = NdArrays.ofInts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 5-dimensional array of ints in a new {@link IntNdArray}
- *
- * @param array source array
- * @return the {@code IntNdArray} copy
- */
- public static IntNdArray ndCopyOf(int[][][][][] array) {
- IntNdArray ndArray = NdArrays.ofInts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 6-dimensional array of ints in a new {@link IntNdArray}
- *
- * @param array source array
- * @return the {@code IntNdArray} copy
- */
- public static IntNdArray ndCopyOf(int[][][][][][] array) {
- IntNdArray ndArray = NdArrays.ofInts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy an array of longs in a new {@link LongNdArray}
- *
- * @param array source array
- * @return the {@code LongNdArray} copy
- */
- public static LongNdArray ndCopyOf(long[] array) {
- LongNdArray ndArray = NdArrays.ofLongs(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 2-dimensional array of longs in a new {@link LongNdArray}
- *
- * @param array source array
- * @return the {@code LongNdArray} copy
- */
- public static LongNdArray ndCopyOf(long[][] array) {
- LongNdArray ndArray = NdArrays.ofLongs(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 3-dimensional array of longs in a new {@link LongNdArray}
- *
- * @param array source array
- * @return the {@code LongNdArray} copy
- */
- public static LongNdArray ndCopyOf(long[][][] array) {
- LongNdArray ndArray = NdArrays.ofLongs(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 4-dimensional array of longs in a new {@link LongNdArray}
- *
- * @param array source array
- * @return the {@code LongNdArray} copy
- */
- public static LongNdArray ndCopyOf(long[][][][] array) {
- LongNdArray ndArray = NdArrays.ofLongs(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 5-dimensional array of longs in a new {@link LongNdArray}
- *
- * @param array source array
- * @return the {@code LongNdArray} copy
- */
- public static LongNdArray ndCopyOf(long[][][][][] array) {
- LongNdArray ndArray = NdArrays.ofLongs(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 6-dimensional array of longs in a new {@link LongNdArray}
- *
- * @param array source array
- * @return the {@code LongNdArray} copy
- */
- public static LongNdArray ndCopyOf(long[][][][][][] array) {
- LongNdArray ndArray = NdArrays.ofLongs(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy an array of floats in a new {@link FloatNdArray}
- *
- * @param array source array
- * @return the {@code FloatNdArray} copy
- */
- public static FloatNdArray ndCopyOf(float[] array) {
- FloatNdArray ndArray = NdArrays.ofFloats(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 2-dimensional array of floats in a new {@link FloatNdArray}
- *
- * @param array source array
- * @return the {@code FloatNdArray} copy
- */
- public static FloatNdArray ndCopyOf(float[][] array) {
- FloatNdArray ndArray = NdArrays.ofFloats(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 3-dimensional array of floats in a new {@link FloatNdArray}
- *
- * @param array source array
- * @return the {@code FloatNdArray} copy
- */
- public static FloatNdArray ndCopyOf(float[][][] array) {
- FloatNdArray ndArray = NdArrays.ofFloats(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 4-dimensional array of floats in a new {@link FloatNdArray}
- *
- * @param array source array
- * @return the {@code FloatNdArray} copy
- */
- public static FloatNdArray ndCopyOf(float[][][][] array) {
- FloatNdArray ndArray = NdArrays.ofFloats(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 5-dimensional array of floats in a new {@link FloatNdArray}
- *
- * @param array source array
- * @return the {@code FloatNdArray} copy
- */
- public static FloatNdArray ndCopyOf(float[][][][][] array) {
- FloatNdArray ndArray = NdArrays.ofFloats(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 6-dimensional array of floats in a new {@link FloatNdArray}
- *
- * @param array source array
- * @return the {@code FloatNdArray} copy
- */
- public static FloatNdArray ndCopyOf(float[][][][][][] array) {
- FloatNdArray ndArray = NdArrays.ofFloats(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy an array of doubles in a new {@link DoubleNdArray}
- *
- * @param array source array
- * @return the {@code DoubleNdArray} copy
- */
- public static DoubleNdArray ndCopyOf(double[] array) {
- DoubleNdArray ndArray = NdArrays.ofDoubles(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 2-dimensional array of doubles in a new {@link DoubleNdArray}
- *
- * @param array source array
- * @return the {@code DoubleNdArray} copy
- */
- public static DoubleNdArray ndCopyOf(double[][] array) {
- DoubleNdArray ndArray = NdArrays.ofDoubles(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 3-dimensional array of doubles in a new {@link DoubleNdArray}
- *
- * @param array source array
- * @return the {@code DoubleNdArray} copy
- */
- public static DoubleNdArray ndCopyOf(double[][][] array) {
- DoubleNdArray ndArray = NdArrays.ofDoubles(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 4-dimensional array of doubles in a new {@link DoubleNdArray}
- *
- * @param array source array
- * @return the {@code DoubleNdArray} copy
- */
- public static DoubleNdArray ndCopyOf(double[][][][] array) {
- DoubleNdArray ndArray = NdArrays.ofDoubles(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 5-dimensional array of doubles in a new {@link DoubleNdArray}
- *
- * @param array source array
- * @return the {@code DoubleNdArray} copy
- */
- public static DoubleNdArray ndCopyOf(double[][][][][] array) {
- DoubleNdArray ndArray = NdArrays.ofDoubles(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 6-dimensional array of doubles in a new {@link DoubleNdArray}
- *
- * @param array source array
- * @return the {@code DoubleNdArray} copy
- */
- public static DoubleNdArray ndCopyOf(double[][][][][][] array) {
- DoubleNdArray ndArray = NdArrays.ofDoubles(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy an array of bytes in a new {@link ByteNdArray}
- *
- * @param array source array
- * @return the {@code ByteNdArray} copy
- */
- public static ByteNdArray ndCopyOf(byte[] array) {
- ByteNdArray ndArray = NdArrays.ofBytes(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 2-dimensional array of bytes in a new {@link ByteNdArray}
- *
- * @param array source array
- * @return the {@code ByteNdArray} copy
- */
- public static ByteNdArray ndCopyOf(byte[][] array) {
- ByteNdArray ndArray = NdArrays.ofBytes(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 3-dimensional array of bytes in a new {@link ByteNdArray}
- *
- * @param array source array
- * @return the {@code ByteNdArray} copy
- */
- public static ByteNdArray ndCopyOf(byte[][][] array) {
- ByteNdArray ndArray = NdArrays.ofBytes(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 4-dimensional array of bytes in a new {@link ByteNdArray}
- *
- * @param array source array
- * @return the {@code ByteNdArray} copy
- */
- public static ByteNdArray ndCopyOf(byte[][][][] array) {
- ByteNdArray ndArray = NdArrays.ofBytes(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 5-dimensional array of bytes in a new {@link ByteNdArray}
- *
- * @param array source array
- * @return the {@code ByteNdArray} copy
- */
- public static ByteNdArray ndCopyOf(byte[][][][][] array) {
- ByteNdArray ndArray = NdArrays.ofBytes(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 6-dimensional array of bytes in a new {@link ByteNdArray}
- *
- * @param array source array
- * @return the {@code ByteNdArray} copy
- */
- public static ByteNdArray ndCopyOf(byte[][][][][][] array) {
- ByteNdArray ndArray = NdArrays.ofBytes(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy an array of shorts in a new {@link ShortNdArray}
- *
- * @param array source array
- * @return the {@code ShortNdArray} copy
- */
- public static ShortNdArray ndCopyOf(short[] array) {
- ShortNdArray ndArray = NdArrays.ofShorts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 2-dimensional array of shorts in a new {@link ShortNdArray}
- *
- * @param array source array
- * @return the {@code ShortNdArray} copy
- */
- public static ShortNdArray ndCopyOf(short[][] array) {
- ShortNdArray ndArray = NdArrays.ofShorts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 3-dimensional array of shorts in a new {@link ShortNdArray}
- *
- * @param array source array
- * @return the {@code ShortNdArray} copy
- */
- public static ShortNdArray ndCopyOf(short[][][] array) {
- ShortNdArray ndArray = NdArrays.ofShorts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 4-dimensional array of shorts in a new {@link ShortNdArray}
- *
- * @param array source array
- * @return the {@code ShortNdArray} copy
- */
- public static ShortNdArray ndCopyOf(short[][][][] array) {
- ShortNdArray ndArray = NdArrays.ofShorts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 5-dimensional array of shorts in a new {@link ShortNdArray}
- *
- * @param array source array
- * @return the {@code ShortNdArray} copy
- */
- public static ShortNdArray ndCopyOf(short[][][][][] array) {
- ShortNdArray ndArray = NdArrays.ofShorts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 6-dimensional array of shorts in a new {@link ShortNdArray}
- *
- * @param array source array
- * @return the {@code ShortNdArray} copy
- */
- public static ShortNdArray ndCopyOf(short[][][][][][] array) {
- ShortNdArray ndArray = NdArrays.ofShorts(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy an array of booleans in a new {@link BooleanNdArray}
- *
- * @param array source array
- * @return the {@code BooleanNdArray} copy
- */
- public static BooleanNdArray ndCopyOf(boolean[] array) {
- BooleanNdArray ndArray = NdArrays.ofBooleans(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 2-dimensional array of booleans in a new {@link BooleanNdArray}
- *
- * @param array source array
- * @return the {@code BooleanNdArray} copy
- */
- public static BooleanNdArray ndCopyOf(boolean[][] array) {
- BooleanNdArray ndArray = NdArrays.ofBooleans(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 3-dimensional array of booleans in a new {@link BooleanNdArray}
- *
- * @param array source array
- * @return the {@code BooleanNdArray} copy
- */
- public static BooleanNdArray ndCopyOf(boolean[][][] array) {
- BooleanNdArray ndArray = NdArrays.ofBooleans(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 4-dimensional array of booleans in a new {@link BooleanNdArray}
- *
- * @param array source array
- * @return the {@code BooleanNdArray} copy
- */
- public static BooleanNdArray ndCopyOf(boolean[][][][] array) {
- BooleanNdArray ndArray = NdArrays.ofBooleans(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 5-dimensional array of booleans in a new {@link BooleanNdArray}
- *
- * @param array source array
- * @return the {@code BooleanNdArray} copy
- */
- public static BooleanNdArray ndCopyOf(boolean[][][][][] array) {
- BooleanNdArray ndArray = NdArrays.ofBooleans(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 6-dimensional array of booleans in a new {@link BooleanNdArray}
- *
- * @param array source array
- * @return the {@code BooleanNdArray} copy
- */
- public static BooleanNdArray ndCopyOf(boolean[][][][][][] array) {
- BooleanNdArray ndArray = NdArrays.ofBooleans(shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy an array of objects in a new {@link NdArray}
- *
- * @param array source array
- * @param data type
- * @return the {@code NdArray} copy
- */
- public static NdArray ndCopyOf(T[] array) {
- @SuppressWarnings("unchecked")
- NdArray ndArray = NdArrays.ofObjects(componentTypeOf(array), shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 2-dimensional array of objects in a new {@link NdArray}
- *
- * @param array source array
- * @param data type
- * @return the {@code NdArray} copy
- */
- public static NdArray ndCopyOf(T[][] array) {
- @SuppressWarnings("unchecked")
- NdArrayndArray = NdArrays.ofObjects(componentTypeOf(array), shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 3-dimensional array of objects in a new {@link NdArray}
- *
- * @param array source array
- * @param data type
- * @return the {@code NdArray} copy
- */
- public static NdArray ndCopyOf(T[][][] array) {
- @SuppressWarnings("unchecked")
- NdArrayndArray = NdArrays.ofObjects(componentTypeOf(array), shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 4-dimensional array of objects in a new {@link NdArray}
- *
- * @param array source array
- * @param data type
- * @return the {@code NdArray} copy
- */
- public static NdArray ndCopyOf(T[][][][] array) {
- @SuppressWarnings("unchecked")
- NdArrayndArray = NdArrays.ofObjects(componentTypeOf(array), shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 5-dimensional array of objects in a new {@link NdArray}
- *
- * @param array source array
- * @param data type
- * @return the {@code NdArray} copy
- */
- public static NdArray ndCopyOf(T[][][][][] array) {
- @SuppressWarnings("unchecked")
- NdArrayndArray = NdArrays.ofObjects(componentTypeOf(array), shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a 6-dimensional array of objects in a new {@link NdArray}
- *
- * @param array source array
- * @param data type
- * @return the {@code NdArray} copy
- */
- public static NdArray ndCopyOf(T[][][][][][] array) {
- @SuppressWarnings("unchecked")
- NdArrayndArray = NdArrays.ofObjects(componentTypeOf(array), shapeOf(array));
- copyTo(array, ndArray);
- return ndArray;
- }
-
- /**
- * Copy a {@link IntNdArray} in a new 1-dimension standard array of ints
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-1 or has a shape that
- * exceeds standard arrays limits
- */
- public static int[] array1dCopyOf(IntNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 1);
- int[] array = new int[dims[0]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link IntNdArray} in a new 2-dimension standard array of ints
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-2 or has a shape that
- * exceeds standard arrays limits
- */
- public static int[][] array2dCopyOf(IntNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 2);
- int[][] array = new int[dims[0]][dims[1]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link IntNdArray} in a new 3-dimension standard array of ints
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-3 or has a shape that
- * exceeds standard arrays limits
- */
- public static int[][][] array3dCopyOf(IntNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 3);
- int[][][] array = new int[dims[0]][dims[1]][dims[2]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link IntNdArray} in a new 4-dimension standard array of ints
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-4 or has a shape that
- * exceeds standard arrays limits
- */
- public static int[][][][] array4dCopyOf(IntNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 4);
- int[][][][] array = new int[dims[0]][dims[1]][dims[2]][dims[3]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link IntNdArray} in a new 5-dimension standard array of ints
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-5 or has a shape that
- * exceeds standard arrays limits
- */
- public static int[][][][][] array5dCopyOf(IntNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 5);
- int[][][][][] array = new int[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link IntNdArray} in a new 6-dimension standard array of ints
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-6 or has a shape that
- * exceeds standard arrays limits
- */
- public static int[][][][][][] array6dCopyOf(IntNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 6);
- int[][][][][][] array = new int[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]][dims[5]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link LongNdArray} in a new 1-dimension standard array of longs
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-1 or has a shape that
- * exceeds standard arrays limits
- */
- public static long[] array1dCopyOf(LongNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 1);
- long[] array = new long[dims[0]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link LongNdArray} in a new 2-dimension standard array of longs
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-2 or has a shape that
- * exceeds standard arrays limits
- */
- public static long[][] array2dCopyOf(LongNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 2);
- long[][] array = new long[dims[0]][dims[1]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link LongNdArray} in a new 3-dimension standard array of longs
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-3 or has a shape that
- * exceeds standard arrays limits
- */
- public static long[][][] array3dCopyOf(LongNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 3);
- long[][][] array = new long[dims[0]][dims[1]][dims[2]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link LongNdArray} in a new 4-dimension standard array of longs
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-4 or has a shape that
- * exceeds standard arrays limits
- */
- public static long[][][][] array4dCopyOf(LongNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 4);
- long[][][][] array = new long[dims[0]][dims[1]][dims[2]][dims[3]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link LongNdArray} in a new 5-dimension standard array of longs
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-5 or has a shape that
- * exceeds standard arrays limits
- */
- public static long[][][][][] array5dCopyOf(LongNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 5);
- long[][][][][] array = new long[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link LongNdArray} in a new 6-dimension standard array of longs
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-6 or has a shape that
- * exceeds standard arrays limits
- */
- public static long[][][][][][] array6dCopyOf(LongNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 6);
- long[][][][][][] array = new long[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]][dims[5]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link FloatNdArray} in a new 1-dimension standard array of floats
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-1 or has a shape that
- * exceeds standard arrays limits
- */
- public static float[] array1dCopyOf(FloatNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 1);
- float[] array = new float[dims[0]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link FloatNdArray} in a new 2-dimension standard array of floats
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-2 or has a shape that
- * exceeds standard arrays limits
- */
- public static float[][] array2dCopyOf(FloatNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 2);
- float[][] array = new float[dims[0]][dims[1]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link FloatNdArray} in a new 3-dimension standard array of floats
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-3 or has a shape that
- * exceeds standard arrays limits
- */
- public static float[][][] array3dCopyOf(FloatNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 3);
- float[][][] array = new float[dims[0]][dims[1]][dims[2]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link FloatNdArray} in a new 4-dimension standard array of floats
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-4 or has a shape that
- * exceeds standard arrays limits
- */
- public static float[][][][] array4dCopyOf(FloatNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 4);
- float[][][][] array = new float[dims[0]][dims[1]][dims[2]][dims[3]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link FloatNdArray} in a new 5-dimension standard array of floats
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-5 or has a shape that
- * exceeds standard arrays limits
- */
- public static float[][][][][] array5dCopyOf(FloatNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 5);
- float[][][][][] array = new float[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link FloatNdArray} in a new 6-dimension standard array of floats
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-6 or has a shape that
- * exceeds standard arrays limits
- */
- public static float[][][][][][] array6dCopyOf(FloatNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 6);
- float[][][][][][] array = new float[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]][dims[5]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link DoubleNdArray} in a new 1-dimension standard array of doubles
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-1 or has a shape that
- * exceeds standard arrays limits
- */
- public static double[] array1dCopyOf(DoubleNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 1);
- double[] array = new double[dims[0]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link DoubleNdArray} in a new 2-dimension standard array of doubles
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-2 or has a shape that
- * exceeds standard arrays limits
- */
- public static double[][] array2dCopyOf(DoubleNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 2);
- double[][] array = new double[dims[0]][dims[1]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link DoubleNdArray} in a new 3-dimension standard array of doubles
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-3 or has a shape that
- * exceeds standard arrays limits
- */
- public static double[][][] array3dCopyOf(DoubleNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 3);
- double[][][] array = new double[dims[0]][dims[1]][dims[2]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link DoubleNdArray} in a new 4-dimension standard array of doubles
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-4 or has a shape that
- * exceeds standard arrays limits
- */
- public static double[][][][] array4dCopyOf(DoubleNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 4);
- double[][][][] array = new double[dims[0]][dims[1]][dims[2]][dims[3]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link DoubleNdArray} in a new 5-dimension standard array of doubles
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-5 or has a shape that
- * exceeds standard arrays limits
- */
- public static double[][][][][] array5dCopyOf(DoubleNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 5);
- double[][][][][] array = new double[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link DoubleNdArray} in a new 6-dimension standard array of doubles
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-6 or has a shape that
- * exceeds standard arrays limits
- */
- public static double[][][][][][] array6dCopyOf(DoubleNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 6);
- double[][][][][][] array = new double[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]][dims[5]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ByteNdArray} in a new 1-dimension standard array of bytes
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-1 or has a shape that
- * exceeds standard arrays limits
- */
- public static byte[] array1dCopyOf(ByteNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 1);
- byte[] array = new byte[dims[0]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ByteNdArray} in a new 2-dimension standard array of bytes
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-2 or has a shape that
- * exceeds standard arrays limits
- */
- public static byte[][] array2dCopyOf(ByteNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 2);
- byte[][] array = new byte[dims[0]][dims[1]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ByteNdArray} in a new 3-dimension standard array of bytes
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-3 or has a shape that
- * exceeds standard arrays limits
- */
- public static byte[][][] array3dCopyOf(ByteNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 3);
- byte[][][] array = new byte[dims[0]][dims[1]][dims[2]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ByteNdArray} in a new 4-dimension standard array of bytes
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-4 or has a shape that
- * exceeds standard arrays limits
- */
- public static byte[][][][] array4dCopyOf(ByteNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 4);
- byte[][][][] array = new byte[dims[0]][dims[1]][dims[2]][dims[3]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ByteNdArray} in a new 5-dimension standard array of bytes
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-5 or has a shape that
- * exceeds standard arrays limits
- */
- public static byte[][][][][] array5dCopyOf(ByteNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 5);
- byte[][][][][] array = new byte[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ByteNdArray} in a new 6-dimension standard array of bytes
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-6 or has a shape that
- * exceeds standard arrays limits
- */
- public static byte[][][][][][] array6dCopyOf(ByteNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 6);
- byte[][][][][][] array = new byte[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]][dims[5]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ShortNdArray} in a new 1-dimension standard array of shorts
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-1 or has a shape that
- * exceeds standard arrays limits
- */
- public static short[] array1dCopyOf(ShortNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 1);
- short[] array = new short[dims[0]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ShortNdArray} in a new 2-dimension standard array of shorts
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-2 or has a shape that
- * exceeds standard arrays limits
- */
- public static short[][] array2dCopyOf(ShortNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 2);
- short[][] array = new short[dims[0]][dims[1]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ShortNdArray} in a new 3-dimension standard array of shorts
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-3 or has a shape that
- * exceeds standard arrays limits
- */
- public static short[][][] array3dCopyOf(ShortNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 3);
- short[][][] array = new short[dims[0]][dims[1]][dims[2]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ShortNdArray} in a new 4-dimension standard array of shorts
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-4 or has a shape that
- * exceeds standard arrays limits
- */
- public static short[][][][] array4dCopyOf(ShortNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 4);
- short[][][][] array = new short[dims[0]][dims[1]][dims[2]][dims[3]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ShortNdArray} in a new 5-dimension standard array of shorts
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-5 or has a shape that
- * exceeds standard arrays limits
- */
- public static short[][][][][] array5dCopyOf(ShortNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 5);
- short[][][][][] array = new short[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link ShortNdArray} in a new 6-dimension standard array of shorts
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-6 or has a shape that
- * exceeds standard arrays limits
- */
- public static short[][][][][][] array6dCopyOf(ShortNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 6);
- short[][][][][][] array = new short[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]][dims[5]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link BooleanNdArray} in a new 1-dimension standard array of booleans
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-1 or has a shape that
- * exceeds standard arrays limits
- */
- public static boolean[] array1dCopyOf(BooleanNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 1);
- boolean[] array = new boolean[dims[0]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link BooleanNdArray} in a new 2-dimension standard array of booleans
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-2 or has a shape that
- * exceeds standard arrays limits
- */
- public static boolean[][] array2dCopyOf(BooleanNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 2);
- boolean[][] array = new boolean[dims[0]][dims[1]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link BooleanNdArray} in a new 3-dimension standard array of booleans
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-3 or has a shape that
- * exceeds standard arrays limits
- */
- public static boolean[][][] array3dCopyOf(BooleanNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 3);
- boolean[][][] array = new boolean[dims[0]][dims[1]][dims[2]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link BooleanNdArray} in a new 4-dimension standard array of booleans
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-4 or has a shape that
- * exceeds standard arrays limits
- */
- public static boolean[][][][] array4dCopyOf(BooleanNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 4);
- boolean[][][][] array = new boolean[dims[0]][dims[1]][dims[2]][dims[3]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link BooleanNdArray} in a new 5-dimension standard array of booleans
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-5 or has a shape that
- * exceeds standard arrays limits
- */
- public static boolean[][][][][] array5dCopyOf(BooleanNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 5);
- boolean[][][][][] array = new boolean[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link BooleanNdArray} in a new 6-dimension standard array of booleans
- *
- * @param ndArray source array
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-6 or has a shape that
- * exceeds standard arrays limits
- */
- public static boolean[][][][][][] array6dCopyOf(BooleanNdArray ndArray) {
- int[] dims = computeArrayDims(ndArray, 6);
- boolean[][][][][][] array = new boolean[dims[0]][dims[1]][dims[2]][dims[3]][dims[4]][dims[5]];
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link NdArray NdArray<T>} in a new 1-dimension standard array of objects
- *
- * @param ndArray source array
- * @param objectType type of object
- * @param data type
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-1 or has a shape that
- * exceeds standard arrays limits
- */
- public static T[] array1dCopyOf(NdArray ndArray, Class objectType) {
- int[] dims = computeArrayDims(ndArray, 1);
- T[] array = (T[])Array.newInstance(objectType, dims[0]);
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link NdArray NdArray<T>} in a new 2-dimension standard array of objects
- *
- * @param ndArray source array
- * @param objectType type of object
- * @param data type
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-2 or has a shape that
- * exceeds standard arrays limits
- */
- public static T[][] array2dCopyOf(NdArray ndArray, Class objectType) {
- int[] dims = computeArrayDims(ndArray, 2);
- T[][] array = (T[][])Array.newInstance(objectType, dims[0], dims[1]);
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link NdArray NdArray<T>} in a new 3-dimension standard array of objects
- *
- * @param ndArray source array
- * @param objectType type of object
- * @param data type
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-3 or has a shape that
- * exceeds standard arrays limits
- */
- public static T[][][] array3dCopyOf(NdArray ndArray, Class objectType) {
- int[] dims = computeArrayDims(ndArray, 3);
- T[][][] array = (T[][][])Array.newInstance(objectType, dims[0], dims[1], dims[2]);
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link NdArray NdArray<T>} in a new 4-dimension standard array of objects
- *
- * @param ndArray source array
- * @param objectType type of object
- * @param data type
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-4 or has a shape that
- * exceeds standard arrays limits
- */
- public static T[][][][] array4dCopyOf(NdArray ndArray, Class objectType) {
- int[] dims = computeArrayDims(ndArray, 4);
- T[][][][] array = (T[][][][])Array.newInstance(objectType, dims[0], dims[1], dims[2], dims[3]);
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link NdArray NdArray<T>} in a new 5-dimension standard array of objects
- *
- * @param ndArray source array
- * @param objectType type of object
- * @param data type
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-5 or has a shape that
- * exceeds standard arrays limits
- */
- public static T[][][][][] array5dCopyOf(NdArray ndArray, Class objectType) {
- int[] dims = computeArrayDims(ndArray, 5);
- T[][][][][] array =
- (T[][][][][])Array.newInstance(objectType, dims[0], dims[1], dims[2], dims[3], dims[4]);
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy a {@link NdArray NdArray<T>} in a new 6-dimension standard array of objects
- *
- * @param ndArray source array
- * @param objectType type of object
- * @param data type
- * @return the array copy
- * @throws IllegalArgumentException if {@code ndArray} is not of rank-6 or has a shape that
- * exceeds standard arrays limits
- */
- public static T[][][][][][] array6dCopyOf(NdArray ndArray, Class objectType) {
- int[] dims = computeArrayDims(ndArray, 6);
- T[][][][][][] array =
- (T[][][][][][])Array.newInstance(objectType, dims[0], dims[1], dims[2], dims[3], dims[4], dims[5]);
- copyFrom(ndArray, array);
- return array;
- }
-
- /**
- * Copy an array of ints into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-1 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-1 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(int[] src, IntNdArray dst) {
- NdArrays.vectorOf(src).copyTo(dst);
- }
-
- /**
- * Copy a 2-dimensional array of ints into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-2 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-2 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(int[][] src, IntNdArray dst) {
- dst.elements(0).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 3-dimensional array of ints into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-3 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-3 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(int[][][] src, IntNdArray dst) {
- dst.elements(1).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 4-dimensional array of ints into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-4 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-4 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(int[][][][] src, IntNdArray dst) {
- dst.elements(2).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 5-dimensional array of ints into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-5 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-5 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(int[][][][][] src, IntNdArray dst) {
- dst.elements(3).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 6-dimensional array of ints into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-6 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-6 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(int[][][][][][] src, IntNdArray dst) {
- dst.elements(4).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]]).copyTo(e)
- );
- }
-
- /**
- * Copy an array of longs into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-1 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-1 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(long[] src, LongNdArray dst) {
- NdArrays.vectorOf(src).copyTo(dst);
- }
-
- /**
- * Copy a 2-dimensional array of longs into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-2 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-2 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(long[][] src, LongNdArray dst) {
- dst.elements(0).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 3-dimensional array of longs into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-3 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-3 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(long[][][] src, LongNdArray dst) {
- dst.elements(1).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 4-dimensional array of longs into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-4 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-4 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(long[][][][] src, LongNdArray dst) {
- dst.elements(2).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 5-dimensional array of longs into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-5 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-5 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(long[][][][][] src, LongNdArray dst) {
- dst.elements(3).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 6-dimensional array of longs into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-6 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-6 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(long[][][][][][] src, LongNdArray dst) {
- dst.elements(4).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]]).copyTo(e)
- );
- }
-
- /**
- * Copy an array of floats into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-1 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-1 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(float[] src, FloatNdArray dst) {
- NdArrays.vectorOf(src).copyTo(dst);
- }
-
- /**
- * Copy a 2-dimensional array of floats into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-2 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-2 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(float[][] src, FloatNdArray dst) {
- dst.elements(0).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 3-dimensional array of floats into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-3 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-3 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(float[][][] src, FloatNdArray dst) {
- dst.elements(1).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 4-dimensional array of floats into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-4 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-4 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(float[][][][] src, FloatNdArray dst) {
- dst.elements(2).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 5-dimensional array of floats into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-5 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-5 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(float[][][][][] src, FloatNdArray dst) {
- dst.elements(3).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 6-dimensional array of floats into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-6 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-6 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(float[][][][][][] src, FloatNdArray dst) {
- dst.elements(4).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]]).copyTo(e)
- );
- }
-
- /**
- * Copy an array of doubles into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-1 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-1 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(double[] src, DoubleNdArray dst) {
- NdArrays.vectorOf(src).copyTo(dst);
- }
-
- /**
- * Copy a 2-dimensional array of doubles into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-2 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-2 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(double[][] src, DoubleNdArray dst) {
- dst.elements(0).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 3-dimensional array of doubles into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-3 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-3 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(double[][][] src, DoubleNdArray dst) {
- dst.elements(1).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 4-dimensional array of doubles into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-4 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-4 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(double[][][][] src, DoubleNdArray dst) {
- dst.elements(2).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 5-dimensional array of doubles into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-5 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-5 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(double[][][][][] src, DoubleNdArray dst) {
- dst.elements(3).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 6-dimensional array of doubles into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-6 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-6 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(double[][][][][][] src, DoubleNdArray dst) {
- dst.elements(4).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]]).copyTo(e)
- );
- }
-
- /**
- * Copy an array of bytes into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-1 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-1 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(byte[] src, ByteNdArray dst) {
- NdArrays.vectorOf(src).copyTo(dst);
- }
-
- /**
- * Copy a 2-dimensional array of bytes into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-2 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-2 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(byte[][] src, ByteNdArray dst) {
- dst.elements(0).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 3-dimensional array of bytes into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-3 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-3 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(byte[][][] src, ByteNdArray dst) {
- dst.elements(1).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 4-dimensional array of bytes into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-4 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-4 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(byte[][][][] src, ByteNdArray dst) {
- dst.elements(2).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 5-dimensional array of bytes into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-5 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-5 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(byte[][][][][] src, ByteNdArray dst) {
- dst.elements(3).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 6-dimensional array of bytes into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-6 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-6 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(byte[][][][][][] src, ByteNdArray dst) {
- dst.elements(4).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]]).copyTo(e)
- );
- }
-
- /**
- * Copy an array of shorts into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-1 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-1 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(short[] src, ShortNdArray dst) {
- NdArrays.vectorOf(src).copyTo(dst);
- }
-
- /**
- * Copy a 2-dimensional array of shorts into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-2 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-2 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(short[][] src, ShortNdArray dst) {
- dst.elements(0).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 3-dimensional array of shorts into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-3 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-3 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(short[][][] src, ShortNdArray dst) {
- dst.elements(1).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 4-dimensional array of shorts into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-4 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-4 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(short[][][][] src, ShortNdArray dst) {
- dst.elements(2).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 5-dimensional array of shorts into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-5 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-5 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(short[][][][][] src, ShortNdArray dst) {
- dst.elements(3).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 6-dimensional array of shorts into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-6 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-6 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(short[][][][][][] src, ShortNdArray dst) {
- dst.elements(4).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]]).copyTo(e)
- );
- }
-
- /**
- * Copy an array of booleans into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-1 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-1 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(boolean[] src, BooleanNdArray dst) {
- NdArrays.vectorOf(src).copyTo(dst);
- }
-
- /**
- * Copy a 2-dimensional array of booleans into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-2 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-2 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(boolean[][] src, BooleanNdArray dst) {
- dst.elements(0).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 3-dimensional array of booleans into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-3 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-3 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(boolean[][][] src, BooleanNdArray dst) {
- dst.elements(1).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 4-dimensional array of booleans into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-4 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-4 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(boolean[][][][] src, BooleanNdArray dst) {
- dst.elements(2).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 5-dimensional array of booleans into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-5 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-5 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(boolean[][][][][] src, BooleanNdArray dst) {
- dst.elements(3).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 6-dimensional array of booleans into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-6 array
- * @throws IllegalArgumentException if {@code dst} is not of rank-6 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(boolean[][][][][][] src, BooleanNdArray dst) {
- dst.elements(4).forEachIndexed((idx, e) ->
- NdArrays.vectorOf(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]]).copyTo(e)
- );
- }
-
- /**
- * Copy an array of objects into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-1 array
- * @param data type
- * @throws IllegalArgumentException if {@code dst} is not of rank-1 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(T[] src, NdArray dst) {
- NdArrays.vectorOfObjects(src).copyTo(dst);
- }
-
- /**
- * Copy a 2-dimensional array of objects into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-2 array
- * @param data type
- * @throws IllegalArgumentException if {@code dst} is not of rank-2 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(T[][] src, NdArray dst) {
- dst.elements(0).forEachIndexed((idx, e) ->
- NdArrays.vectorOfObjects(src[(int)idx[0]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 3-dimensional array of objects into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-3 array
- * @param data type
- * @throws IllegalArgumentException if {@code dst} is not of rank-3 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(T[][][] src, NdArray dst) {
- dst.elements(1).forEachIndexed((idx, e) ->
- NdArrays.vectorOfObjects(src[(int)idx[0]][(int)idx[1]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 4-dimensional array of objects into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-4 array
- * @param data type
- * @throws IllegalArgumentException if {@code dst} is not of rank-4 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(T[][][][] src, NdArray dst) {
- dst.elements(2).forEachIndexed((idx, e) ->
- NdArrays.vectorOfObjects(src[(int)idx[0]][(int)idx[1]][(int)idx[2]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 5-dimensional array of objects into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-5 array
- * @param data type
- * @throws IllegalArgumentException if {@code dst} is not of rank-5 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(T[][][][][] src, NdArray dst) {
- dst.elements(3).forEachIndexed((idx, e) ->
- NdArrays.vectorOfObjects(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]]).copyTo(e)
- );
- }
-
- /**
- * Copy a 6-dimensional array of objects into the {@code dst} {@link NdArray}
- *
- * @param src source array
- * @param dst destination rank-6 array
- * @param data type
- * @throws IllegalArgumentException if {@code dst} is not of rank-6 or has an incompatible shape
- * with the source array
- */
- public static void copyTo(T[][][][][][] src, NdArray dst) {
- dst.elements(4).forEachIndexed((idx, e) ->
- NdArrays.vectorOfObjects(src[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]]).copyTo(e)
- );
- }
-
-
- /**
- * Copy a {@link NdArray} to an array of ints
- *
- * @param src source rank-1 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-1
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(IntNdArray src, int[] dst) {
- if (src.rank() != 1) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- if (src.size() > dst.length) {
- throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
- }
- src.read(DataBuffers.of(dst, false, false));
- }
-
- /**
- * Copy a {@link NdArray} to a 2-dimensional array of ints
- *
- * @param src source rank-2 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-2
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(IntNdArray src, int[][] dst) {
- if (src.rank() != 2) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(0).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 3-dimensional array of ints
- *
- * @param src source rank-3 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-3
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(IntNdArray src, int[][][] dst) {
- if (src.rank() != 3) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(1).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 4-dimensional array of ints
- *
- * @param src source rank-4 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-4
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(IntNdArray src, int[][][][] dst) {
- if (src.rank() != 4) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(2).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 5-dimensional array of ints
- *
- * @param src source rank-5 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-5
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(IntNdArray src, int[][][][][] dst) {
- if (src.rank() != 5) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(3).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 6-dimensional array of ints
- *
- * @param src source rank-6 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-6
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(IntNdArray src, int[][][][][][] dst) {
- if (src.rank() != 6) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(4).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to an array of longs
- *
- * @param src source rank-1 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-1
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(LongNdArray src, long[] dst) {
- if (src.rank() != 1) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- if (src.size() > dst.length) {
- throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
- }
- src.read(DataBuffers.of(dst, false, false));
- }
-
- /**
- * Copy a {@link NdArray} to a 2-dimensional array of longs
- *
- * @param src source rank-2 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-2
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(LongNdArray src, long[][] dst) {
- if (src.rank() != 2) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(0).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 3-dimensional array of longs
- *
- * @param src source rank-3 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-3
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(LongNdArray src, long[][][] dst) {
- if (src.rank() != 3) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(1).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 4-dimensional array of longs
- *
- * @param src source rank-4 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-4
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(LongNdArray src, long[][][][] dst) {
- if (src.rank() != 4) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(2).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 5-dimensional array of longs
- *
- * @param src source rank-5 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-5
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(LongNdArray src, long[][][][][] dst) {
- if (src.rank() != 5) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(3).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 6-dimensional array of longs
- *
- * @param src source rank-6 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-6
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(LongNdArray src, long[][][][][][] dst) {
- if (src.rank() != 6) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(4).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to an array of floats
- *
- * @param src source rank-1 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-1
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(FloatNdArray src, float[] dst) {
- if (src.rank() != 1) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- if (src.size() > dst.length) {
- throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
- }
- src.read(DataBuffers.of(dst, false, false));
- }
-
- /**
- * Copy a {@link NdArray} to a 2-dimensional array of floats
- *
- * @param src source rank-2 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-2
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(FloatNdArray src, float[][] dst) {
- if (src.rank() != 2) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(0).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 3-dimensional array of floats
- *
- * @param src source rank-3 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-3
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(FloatNdArray src, float[][][] dst) {
- if (src.rank() != 3) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(1).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 4-dimensional array of floats
- *
- * @param src source rank-4 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-4
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(FloatNdArray src, float[][][][] dst) {
- if (src.rank() != 4) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(2).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 5-dimensional array of floats
- *
- * @param src source rank-5 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-5
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(FloatNdArray src, float[][][][][] dst) {
- if (src.rank() != 5) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(3).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 6-dimensional array of floats
- *
- * @param src source rank-6 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-6
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(FloatNdArray src, float[][][][][][] dst) {
- if (src.rank() != 6) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(4).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to an array of doubles
- *
- * @param src source rank-1 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-1
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(DoubleNdArray src, double[] dst) {
- if (src.rank() != 1) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- if (src.size() > dst.length) {
- throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
- }
- src.read(DataBuffers.of(dst, false, false));
- }
-
- /**
- * Copy a {@link NdArray} to a 2-dimensional array of doubles
- *
- * @param src source rank-2 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-2
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(DoubleNdArray src, double[][] dst) {
- if (src.rank() != 2) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(0).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 3-dimensional array of doubles
- *
- * @param src source rank-3 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-3
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(DoubleNdArray src, double[][][] dst) {
- if (src.rank() != 3) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(1).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 4-dimensional array of doubles
- *
- * @param src source rank-4 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-4
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(DoubleNdArray src, double[][][][] dst) {
- if (src.rank() != 4) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(2).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 5-dimensional array of doubles
- *
- * @param src source rank-5 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-5
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(DoubleNdArray src, double[][][][][] dst) {
- if (src.rank() != 5) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(3).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 6-dimensional array of doubles
- *
- * @param src source rank-6 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-6
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(DoubleNdArray src, double[][][][][][] dst) {
- if (src.rank() != 6) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(4).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to an array of bytes
- *
- * @param src source rank-1 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-1
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ByteNdArray src, byte[] dst) {
- if (src.rank() != 1) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- if (src.size() > dst.length) {
- throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
- }
- src.read(DataBuffers.of(dst, false, false));
- }
-
- /**
- * Copy a {@link NdArray} to a 2-dimensional array of bytes
- *
- * @param src source rank-2 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-2
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ByteNdArray src, byte[][] dst) {
- if (src.rank() != 2) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(0).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 3-dimensional array of bytes
- *
- * @param src source rank-3 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-3
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ByteNdArray src, byte[][][] dst) {
- if (src.rank() != 3) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(1).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 4-dimensional array of bytes
- *
- * @param src source rank-4 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-4
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ByteNdArray src, byte[][][][] dst) {
- if (src.rank() != 4) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(2).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 5-dimensional array of bytes
- *
- * @param src source rank-5 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-5
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ByteNdArray src, byte[][][][][] dst) {
- if (src.rank() != 5) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(3).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 6-dimensional array of bytes
- *
- * @param src source rank-6 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-6
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ByteNdArray src, byte[][][][][][] dst) {
- if (src.rank() != 6) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(4).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to an array of shorts
- *
- * @param src source rank-1 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-1
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ShortNdArray src, short[] dst) {
- if (src.rank() != 1) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- if (src.size() > dst.length) {
- throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
- }
- src.read(DataBuffers.of(dst, false, false));
- }
-
- /**
- * Copy a {@link NdArray} to a 2-dimensional array of shorts
- *
- * @param src source rank-2 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-2
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ShortNdArray src, short[][] dst) {
- if (src.rank() != 2) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(0).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 3-dimensional array of shorts
- *
- * @param src source rank-3 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-3
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ShortNdArray src, short[][][] dst) {
- if (src.rank() != 3) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(1).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 4-dimensional array of shorts
- *
- * @param src source rank-4 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-4
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ShortNdArray src, short[][][][] dst) {
- if (src.rank() != 4) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(2).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 5-dimensional array of shorts
- *
- * @param src source rank-5 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-5
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ShortNdArray src, short[][][][][] dst) {
- if (src.rank() != 5) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(3).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 6-dimensional array of shorts
- *
- * @param src source rank-6 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-6
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(ShortNdArray src, short[][][][][][] dst) {
- if (src.rank() != 6) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(4).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to an array of booleans.
- *
- * @param src source rank-1 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-1
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(BooleanNdArray src, boolean[] dst) {
- if (src.rank() != 1) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- if (src.size() > dst.length) {
- throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
- }
- src.read(DataBuffers.of(dst, false, false));
- }
-
- /**
- * Copy a {@link NdArray} to a 2-dimensional array of booleans
- *
- * @param src source rank-2 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-2
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(BooleanNdArray src, boolean[][] dst) {
- if (src.rank() != 2) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(0).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 3-dimensional array of booleans
- *
- * @param src source rank-3 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-3
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(BooleanNdArray src, boolean[][][] dst) {
- if (src.rank() != 3) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(1).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 4-dimensional array of booleans
- *
- * @param src source rank-4 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-4
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(BooleanNdArray src, boolean[][][][] dst) {
- if (src.rank() != 4) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(2).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 5-dimensional array of booleans
- *
- * @param src source rank-5 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-5
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(BooleanNdArray src, boolean[][][][][] dst) {
- if (src.rank() != 5) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(3).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 6-dimensional array of booleans
- *
- * @param src source rank-6 array
- * @param dst destination array
- * @throws IllegalArgumentException if {@code src} is not of rank-6
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(BooleanNdArray src, boolean[][][][][][] dst) {
- if (src.rank() != 6) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(4).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to an array of objects
- *
- * @param src source rank-1 array
- * @param dst destination array
- * @param data type
- * @throws IllegalArgumentException if {@code src} is not of rank-1
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(NdArray src, T[] dst) {
- if (src.rank() != 1) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- if (src.size() > dst.length) {
- throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
- }
- src.read(DataBuffers.of(dst, false, false));
- }
-
- /**
- * Copy a {@link NdArray} to a 2-dimensional array of objects
- *
- * @param src source rank-2 array
- * @param dst destination array
- * @param data type
- * @throws IllegalArgumentException if {@code src} is not of rank-2
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(NdArray src, T[][] dst) {
- if (src.rank() != 2) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(0).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 3-dimensional array of objects
- *
- * @param src source rank-3 array
- * @param dst destination array
- * @param data type
- * @throws IllegalArgumentException if {@code src} is not of rank-3
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(NdArray src, T[][][] dst) {
- if (src.rank() != 3) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(1).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 4-dimensional array of objects
- *
- * @param src source rank-4 array
- * @param dst destination array
- * @param data type
- * @throws IllegalArgumentException if {@code src} is not of rank-4
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(NdArray src, T[][][][] dst) {
- if (src.rank() != 4) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(2).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 5-dimensional array of objects
- *
- * @param src source rank-5 array
- * @param dst destination array
- * @param data type
- * @throws IllegalArgumentException if {@code src} is not of rank-5
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(NdArray src, T[][][][][] dst) {
- if (src.rank() != 5) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(3).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]])
- );
- }
-
- /**
- * Copy a {@link NdArray} to a 6-dimensional array of objects
- *
- * @param src source rank-6 array
- * @param dst destination array
- * @param data type
- * @throws IllegalArgumentException if {@code src} is not of rank-6
- * @throws ArrayIndexOutOfBoundsException if not all elements of {@code src} can fit it the destination array
- */
- public static void copyFrom(NdArray src, T[][][][][][] dst) {
- if (src.rank() != 6) {
- throw new IllegalArgumentException("Array cannot be copied from NdArray of rank " + src.rank());
- }
- src.elements(4).forEachIndexed((idx, e) ->
- copyFrom(e, dst[(int)idx[0]][(int)idx[1]][(int)idx[2]][(int)idx[3]][(int)idx[4]])
- );
- }
-
- /**
- * Compute the shape of an int array.
- *
- * @param array 1D array
- * @return shape of the array
- */
- public static Shape shapeOf(int[] array) {
- return Shape.of(array.length);
- }
-
- /**
- * Compute the shape of a 2-dimensional int array.
- *
- * @param array 2D array
- * @return shape of the array
- */
- public static Shape shapeOf(int[][] array) {
- return Shape.of(computeShape(array, new long[2]));
- }
-
- /**
- * Compute the shape of a 3-dimensional int array.
- *
- * @param array 3D array
- * @return shape of the array
- */
- public static Shape shapeOf(int[][][] array) {
- return Shape.of(computeShape(array, new long[3]));
- }
-
- /**
- * Compute the shape of a 4-dimensional int array.
- *
- * @param array 4D array
- * @return shape of the array
- */
- public static Shape shapeOf(int[][][][] array) {
- return Shape.of(computeShape(array, new long[4]));
- }
-
- /**
- * Compute the shape of a 5-dimensional int array.
- *
- * @param array 5D array
- * @return shape of the array
- */
- public static Shape shapeOf(int[][][][][] array) {
- return Shape.of(computeShape(array, new long[5]));
- }
-
- /**
- * Compute the shape of a 6-dimensional int array.
- *
- * @param array 6D array
- * @return shape of the array
- */
- public static Shape shapeOf(int[][][][][][] array) {
- return Shape.of(computeShape(array, new long[6]));
- }
-
- /**
- * Compute the shape of a long array.
- *
- * @param array 1D array
- * @return shape of the array
- */
- public static Shape shapeOf(long[] array) {
- return Shape.of(array.length);
- }
-
- /**
- * Compute the shape of a 2-dimensional long array.
- *
- * @param array 2D array
- * @return shape of the array
- */
- public static Shape shapeOf(long[][] array) {
- return Shape.of(computeShape(array, new long[2]));
- }
-
- /**
- * Compute the shape of a 3-dimensional long array.
- *
- * @param array 3D array
- * @return shape of the array
- */
- public static Shape shapeOf(long[][][] array) {
- return Shape.of(computeShape(array, new long[3]));
- }
-
- /**
- * Compute the shape of a 4-dimensional long array.
- *
- * @param array 4D array
- * @return shape of the array
- */
- public static Shape shapeOf(long[][][][] array) {
- return Shape.of(computeShape(array, new long[4]));
- }
-
- /**
- * Compute the shape of a 5-dimensional long array.
- *
- * @param array 5D array
- * @return shape of the array
- */
- public static Shape shapeOf(long[][][][][] array) {
- return Shape.of(computeShape(array, new long[5]));
- }
-
- /**
- * Compute the shape of a 6-dimensional long array.
- *
- * @param array 6D array
- * @return shape of the array
- */
- public static Shape shapeOf(long[][][][][][] array) {
- return Shape.of(computeShape(array, new long[6]));
- }
-
- /**
- * Compute the shape of a float array.
- *
- * @param array 1D array
- * @return shape of the array
- */
- public static Shape shapeOf(float[] array) {
- return Shape.of(array.length);
- }
-
- /**
- * Compute the shape of a 2-dimensional float array.
- *
- * @param array 2D array
- * @return shape of the array
- */
- public static Shape shapeOf(float[][] array) {
- return Shape.of(computeShape(array, new long[2]));
- }
-
- /**
- * Compute the shape of a 3-dimensional float array.
- *
- * @param array 3D array
- * @return shape of the array
- */
- public static Shape shapeOf(float[][][] array) {
- return Shape.of(computeShape(array, new long[3]));
- }
-
- /**
- * Compute the shape of a 4-dimensional float array.
- *
- * @param array 4D array
- * @return shape of the array
- */
- public static Shape shapeOf(float[][][][] array) {
- return Shape.of(computeShape(array, new long[4]));
- }
-
- /**
- * Compute the shape of a 5-dimensional float array.
- *
- * @param array 5D array
- * @return shape of the array
- */
- public static Shape shapeOf(float[][][][][] array) {
- return Shape.of(computeShape(array, new long[5]));
- }
-
- /**
- * Compute the shape of a 6-dimensional float array.
- *
- * @param array 6D array
- * @return shape of the array
- */
- public static Shape shapeOf(float[][][][][][] array) {
- return Shape.of(computeShape(array, new long[6]));
- }
-
- /**
- * Compute the shape of a double array.
- *
- * @param array 1D array
- * @return shape of the array
- */
- public static Shape shapeOf(double[] array) {
- return Shape.of(array.length);
- }
-
- /**
- * Compute the shape of a 2-dimensional double array.
- *
- * @param array 2D array
- * @return shape of the array
- */
- public static Shape shapeOf(double[][] array) {
- return Shape.of(computeShape(array, new long[2]));
- }
-
- /**
- * Compute the shape of a 3-dimensional double array.
- *
- * @param array 3D array
- * @return shape of the array
- */
- public static Shape shapeOf(double[][][] array) {
- return Shape.of(computeShape(array, new long[3]));
- }
-
- /**
- * Compute the shape of a 4-dimensional double array.
- *
- * @param array 4D array
- * @return shape of the array
- */
- public static Shape shapeOf(double[][][][] array) {
- return Shape.of(computeShape(array, new long[4]));
- }
-
- /**
- * Compute the shape of a 5-dimensional double array.
- *
- * @param array 5D array
- * @return shape of the array
- */
- public static Shape shapeOf(double[][][][][] array) {
- return Shape.of(computeShape(array, new long[5]));
- }
-
- /**
- * Compute the shape of a 6-dimensional double array.
- *
- * @param array 6D array
- * @return shape of the array
- */
- public static Shape shapeOf(double[][][][][][] array) {
- return Shape.of(computeShape(array, new long[6]));
- }
-
- /**
- * Compute the shape of a byte array.
- *
- * @param array 1D array
- * @return shape of the array
- */
- public static Shape shapeOf(byte[] array) {
- return Shape.of(array.length);
- }
-
- /**
- * Compute the shape of a 2-dimensional byte array.
- *
- * @param array 2D array
- * @return shape of the array
- */
- public static Shape shapeOf(byte[][] array) {
- return Shape.of(computeShape(array, new long[2]));
- }
-
- /**
- * Compute the shape of a 3-dimensional byte array.
- *
- * @param array 3D array
- * @return shape of the array
- */
- public static Shape shapeOf(byte[][][] array) {
- return Shape.of(computeShape(array, new long[3]));
- }
-
- /**
- * Compute the shape of a 4-dimensional byte array.
- *
- * @param array 4D array
- * @return shape of the array
- */
- public static Shape shapeOf(byte[][][][] array) {
- return Shape.of(computeShape(array, new long[4]));
- }
-
- /**
- * Compute the shape of a 5-dimensional byte array.
- *
- * @param array 5D array
- * @return shape of the array
- */
- public static Shape shapeOf(byte[][][][][] array) {
- return Shape.of(computeShape(array, new long[5]));
- }
-
- /**
- * Compute the shape of a 6-dimensional byte array.
- *
- * @param array 6D array
- * @return shape of the array
- */
- public static Shape shapeOf(byte[][][][][][] array) {
- return Shape.of(computeShape(array, new long[6]));
- }
-
- /**
- * Compute the shape of a short array.
- *
- * @param array 1D array
- * @return shape of the array
- */
- public static Shape shapeOf(short[] array) {
- return Shape.of(array.length);
- }
-
- /**
- * Compute the shape of a 2-dimensional short array.
- *
- * @param array 2D array
- * @return shape of the array
- */
- public static Shape shapeOf(short[][] array) {
- return Shape.of(computeShape(array, new long[2]));
- }
-
- /**
- * Compute the shape of a 3-dimensional short array.
- *
- * @param array 3D array
- * @return shape of the array
- */
- public static Shape shapeOf(short[][][] array) {
- return Shape.of(computeShape(array, new long[3]));
- }
-
- /**
- * Compute the shape of a 4-dimensional short array.
- *
- * @param array 4D array
- * @return shape of the array
- */
- public static Shape shapeOf(short[][][][] array) {
- return Shape.of(computeShape(array, new long[4]));
- }
-
- /**
- * Compute the shape of a 5-dimensional short array.
- *
- * @param array 5D array
- * @return shape of the array
- */
- public static Shape shapeOf(short[][][][][] array) {
- return Shape.of(computeShape(array, new long[5]));
- }
-
- /**
- * Compute the shape of a 6-dimensional short array.
- *
- * @param array 6D array
- * @return shape of the array
- */
- public static Shape shapeOf(short[][][][][][] array) {
- return Shape.of(computeShape(array, new long[6]));
- }
-
- /**
- * Compute the shape of a boolean array.
- *
- * @param array 1D array
- * @return shape of the array
- */
- public static Shape shapeOf(boolean[] array) {
- return Shape.of(array.length);
- }
-
- /**
- * Compute the shape of a 2-dimensional boolean array.
- *
- * @param array 2D array
- * @return shape of the array
- */
- public static Shape shapeOf(boolean[][] array) {
- return Shape.of(computeShape(array, new long[2]));
- }
-
- /**
- * Compute the shape of a 3-dimensional boolean array.
- *
- * @param array 3D array
- * @return shape of the array
- */
- public static Shape shapeOf(boolean[][][] array) {
- return Shape.of(computeShape(array, new long[3]));
- }
-
- /**
- * Compute the shape of a 4-dimensional boolean array.
- *
- * @param array 4D array
- * @return shape of the array
- */
- public static Shape shapeOf(boolean[][][][] array) {
- return Shape.of(computeShape(array, new long[4]));
- }
-
- /**
- * Compute the shape of a 5-dimensional boolean array.
- *
- * @param array 5D array
- * @return shape of the array
- */
- public static Shape shapeOf(boolean[][][][][] array) {
- return Shape.of(computeShape(array, new long[5]));
- }
-
- /**
- * Compute the shape of a 6-dimensional boolean array.
- *
- * @param array 6D array
- * @return shape of the array
- */
- public static Shape shapeOf(boolean[][][][][][] array) {
- return Shape.of(computeShape(array, new long[6]));
- }
-
- /**
- * Compute the shape of an object array.
- *
- * @param array 1D array
- * @param data type
- * @return shape of the array
- */
- public static Shape shapeOf(T[] array) {
- return Shape.of(array.length);
- }
-
- /**
- * Compute the shape of a 2-dimensional object array.
- *
- * @param array 2D array
- * @param data type
- * @return shape of the array
- */
- public static Shape shapeOf(T[][] array) {
- return Shape.of(computeShape(array, new long[2]));
- }
-
- /**
- * Compute the shape of a 3-dimensional object array.
- *
- * @param array 3D array
- * @param data type
- * @return shape of the array
- */
- public static Shape shapeOf(T[][][] array) {
- return Shape.of(computeShape(array, new long[3]));
- }
-
- /**
- * Compute the shape of a 4-dimensional object array.
- *
- * @param array 4D array
- * @param data type
- * @return shape of the array
- */
- public static Shape shapeOf(T[][][][] array) {
- return Shape.of(computeShape(array, new long[4]));
- }
-
- /**
- * Compute the shape of a 5-dimensional object array.
- *
- * @param array 5D array
- * @param data type
- * @return shape of the array
- */
- public static Shape shapeOf(T[][][][][] array) {
- return Shape.of(computeShape(array, new long[5]));
- }
-
- /**
- * Compute the shape of a 6-dimensional object array.
- *
- * @param array 6D array
- * @param data type
- * @return shape of the array
- */
- public static Shape shapeOf(T[][][][][][] array) {
- return Shape.of(computeShape(array, new long[6]));
- }
-
- private static void dimSize(int arrayLength, long[] shape, int dimIdx) {
- if (shape[dimIdx] == 0) {
- shape[dimIdx] = arrayLength;
- } else if (shape[dimIdx] != arrayLength) {
- shape[dimIdx] = Shape.UNKNOWN_SIZE;
- }
- }
-
- private static long[] computeShape(int[][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 2);
- for (int i = 0; i < array.length; ++i) {
- if (array[i] == null) {
- throw new IllegalStateException("One of the subarray is null");
- }
- dimSize(array[i].length, shape, shape.length - 1);
- }
- return shape;
- }
-
- private static long[] computeShape(int[][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 3);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(int[][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 4);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(int[][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 5);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(int[][][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 6);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(long[][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 2);
- for (int i = 0; i < array.length; ++i) {
- if (array[i] == null) {
- throw new IllegalStateException("One of the subarray is null");
- }
- dimSize(array[i].length, shape, shape.length - 1);
- }
- return shape;
- }
-
- private static long[] computeShape(long[][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 3);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(long[][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 4);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(long[][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 5);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(long[][][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 6);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(float[][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 2);
- for (int i = 0; i < array.length; ++i) {
- if (array[i] == null) {
- throw new IllegalStateException("One of the subarray is null");
- }
- dimSize(array[i].length, shape, shape.length - 1);
- }
- return shape;
- }
-
- private static long[] computeShape(float[][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 3);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(float[][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 4);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(float[][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 5);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(float[][][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 6);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(double[][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 2);
- for (int i = 0; i < array.length; ++i) {
- if (array[i] == null) {
- throw new IllegalStateException("One of the subarray is null");
- }
- dimSize(array[i].length, shape, shape.length - 1);
- }
- return shape;
- }
-
- private static long[] computeShape(double[][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 3);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(double[][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 4);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(double[][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 5);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(double[][][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 6);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(byte[][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 2);
- for (int i = 0; i < array.length; ++i) {
- if (array[i] == null) {
- throw new IllegalStateException("One of the subarray is null");
- }
- dimSize(array[i].length, shape, shape.length - 1);
- }
- return shape;
- }
-
- private static long[] computeShape(byte[][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 3);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(byte[][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 4);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(byte[][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 5);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(byte[][][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 6);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(short[][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 2);
- for (int i = 0; i < array.length; ++i) {
- if (array[i] == null) {
- throw new IllegalStateException("One of the subarray is null");
- }
- dimSize(array[i].length, shape, shape.length - 1);
- }
- return shape;
- }
-
- private static long[] computeShape(short[][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 3);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(short[][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 4);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(short[][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 5);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(short[][][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 6);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(boolean[][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 2);
- for (int i = 0; i < array.length; ++i) {
- if (array[i] == null) {
- throw new IllegalStateException("One of the subarray is null");
- }
- dimSize(array[i].length, shape, shape.length - 1);
- }
- return shape;
- }
-
- private static long[] computeShape(boolean[][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 3);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(boolean[][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 4);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(boolean[][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 5);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(boolean[][][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 6);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(T[][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 2);
- for (int i = 0; i < array.length; ++i) {
- if (array[i] == null) {
- throw new IllegalStateException("One of the subarray is null");
- }
- dimSize(array[i].length, shape, shape.length - 1);
- }
- return shape;
- }
-
- private static long[] computeShape(T[][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 3);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(T[][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 4);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(T[][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 5);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static long[] computeShape(T[][][][][][] array, long[] shape) {
- if (array == null) {
- throw new IllegalStateException("The array or one of its subarray is null");
- }
- dimSize(array.length, shape, shape.length - 6);
- for (int i = 0; i < array.length; ++i) {
- computeShape(array[i], shape);
- }
- return shape;
- }
-
- private static Class componentTypeOf(Object array) {
- Class> componentType = array.getClass().getComponentType();
- while (componentType.isArray()) {
- componentType = componentType.getComponentType();
- }
- return (Class)componentType;
- }
-
- private static int[] computeArrayDims(NdArray> ndArray, int expectedRank) {
- Shape shape = ndArray.shape();
- if (shape.numDimensions() != expectedRank) {
- throw new IllegalArgumentException("NdArray must be of rank " + expectedRank);
- }
- int[] arrayShape = new int[expectedRank];
- for (int i = 0; i < expectedRank; ++i) {
- long dimSize = shape.size(i);
- if (dimSize > Integer.MAX_VALUE) {
- throw new IllegalArgumentException("Dimension " + i + " is too large to fit in a standard array (" + shape.size(i) + ")");
- }
- arrayShape[i] = (int)dimSize;
- }
- return arrayShape;
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/BooleanDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/BooleanDataBuffer.java
deleted file mode 100644
index 73a570d4fe8..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/BooleanDataBuffer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- 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.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of booleans.
- */
-public interface BooleanDataBuffer extends DataBuffer {
-
- /**
- * Reads the boolean at the given index.
- *
- * @param index the index from which the float will be read
- * @return the boolean at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- boolean getBoolean(long index);
-
- /**
- * Writes the given boolean into this buffer at the given index.
- *
- * @param value the boolean to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- BooleanDataBuffer setBoolean(boolean value, long index);
-
- /**
- * Bulk get method, using boolean arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default BooleanDataBuffer read(boolean[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Bulk get method, using boolean arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- BooleanDataBuffer read(boolean[] dst, int offset, int length);
-
- /**
- * Bulk put method, using boolean arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default BooleanDataBuffer write(boolean[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using boolean arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- BooleanDataBuffer write(boolean[] src, int offset, int length);
-
- @Override
- default Boolean getObject(long index) {
- return getBoolean(index);
- }
-
- @Override
- default BooleanDataBuffer setObject(Boolean value, long index) {
- return setBoolean(value, index);
- }
-
- @Override
- BooleanDataBuffer copyTo(DataBuffer dst, long size);
-
- @Override
- default BooleanDataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- @Override
- default BooleanDataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- @Override
- BooleanDataBuffer slice(long index, long size);
-
- @Override
- default DataBufferWindow window(long size) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/ByteDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/ByteDataBuffer.java
deleted file mode 100644
index b1cce441b13..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/ByteDataBuffer.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- 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.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of bytes.
- */
-public interface ByteDataBuffer extends DataBuffer {
-
- /**
- * Reads the byte at the given index.
- *
- * @param index the index from which the float will be read
- * @return the byte at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- byte getByte(long index);
-
- /**
- * Writes the given byte into this buffer at the given index.
- *
- * @param value the byte to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- ByteDataBuffer setByte(byte value, long index);
-
- /**
- * Bulk get method, using byte arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default ByteDataBuffer read(byte[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Bulk get method, using byte arrays.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- ByteDataBuffer read(byte[] dst, int offset, int length);
-
- /**
- * Bulk put method, using byte arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default ByteDataBuffer write(byte[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using byte arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- ByteDataBuffer write(byte[] src, int offset, int length);
-
- /**
- * Return this byte buffer as a buffer of ints.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link IntDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- IntDataBuffer asInts();
-
- /**
- * Return this byte buffer as a buffer of shorts.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link ShortDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- ShortDataBuffer asShorts();
-
- /**
- * Return this byte buffer as a buffer of longs.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link LongDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- LongDataBuffer asLongs();
-
- /**
- * Return this byte buffer as a buffer of floats.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link FloatDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- FloatDataBuffer asFloats();
-
- /**
- * Return this byte buffer as a buffer of doubles.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link DoubleDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- DoubleDataBuffer asDoubles();
-
- /**
- * Return this byte buffer as a buffer of booleans.
- *
- *
The returned buffer provides a different view on the same memory as the original byte buffer,
- * meaning that changing a value in one will affect the other.
- *
- * @return this buffer as a {@link BooleanDataBuffer}
- * @throws IllegalStateException if this buffer cannot be converted
- */
- BooleanDataBuffer asBooleans();
-
- @Override
- default Byte getObject(long index) {
- return getByte(index);
- }
-
- @Override
- default ByteDataBuffer setObject(Byte value, long index) {
- return setByte(value, index);
- }
-
- @Override
- ByteDataBuffer copyTo(DataBuffer dst, long size);
-
-
- @Override
- default ByteDataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- @Override
- default ByteDataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- @Override
- ByteDataBuffer slice(long index, long size);
-
- @Override
- default DataBufferWindow window(long size) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBuffer.java
deleted file mode 100644
index e62ba87ce6e..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBuffer.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- 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.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A container of data of a specific type.
- *
- * Instances of {@code DataBuffer} map native or heap memory segments to a linear view that
- * supports:
- *
- * - 64-bits indexing, allowing to work with buffer larger than 231 bytes
- * - Storage of object of any types and not only primitives
- * - Generic types allows to work directly with boxed types as well, which does not require
- * explicit buffer types as with the standard JDK buffers.
- *
- * It is important to note that there is no guarantee the memory managed by a {@code DataBuffer}
- * is linear, specially when dealing with non-primitive types or large buffers.
- *
- * @param type of data stored in this buffer
- */
-public interface DataBuffer {
-
- /**
- * Size of the buffer, in elements.
- *
- * For exemple, in case of a byte buffer, this value is equal to the number of bytes this buffer
- * can hold. For an integer buffer, it is equal to the number of integers, therefore the size
- * in bytes of this buffer is {@code size() * Integer.BYTES}.
- *
- * @return the buffer size
- */
- long size();
-
- /**
- * Tells whether or not this buffer is backed by an accessible array.
- *
- * @return true if, and only if, this buffer is read-only
- */
- boolean isReadOnly();
-
- /**
- * Reads the value at the given index.
- *
- * Important: Usage of this method should be limited to buffers of non-primitive types or
- * when the data type is not deterministically known by the caller. In any other case, prefer
- * the usage of its primitive variant which will significantly improve performances
- * (e.g. {@code IntDataBuffer.getInt(idx)}
- *
- * @param index the index from which the float will be read
- * @return the value at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- T getObject(long index);
-
- /**
- * Writes the given value into this buffer at the given index.
- *
- * Important: Usage of this method should be limited to buffers of non-primitive types or
- * when the data type is not deterministically known by the caller. In any other case, prefer
- * the usage of its primitive variant which will significantly improve performances
- * (e.g. {@code IntDataBuffer.setInt(idx)}
- *
- * @param value the value to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- DataBuffer setObject(T value, long index);
-
- /**
- * Read the references of the objects in this buffer into the destination array.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code dst.length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = dst.length} values from this buffer into the given
- * array.
- *
- * @param dst the array into which values are to be written
- * @return this buffer
- * @throws BufferUnderflowException if there are not enough values to copy from this buffer
- */
- default DataBuffer read(T[] dst) {
- return read(dst, 0, dst.length);
- }
-
- /**
- * Read the references of the objects in this buffer into the destination array.
- *
- * This method transfers values from this buffer into the given destination array. If there are
- * fewer values in the buffer than are required to satisfy the request, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferUnderflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from this buffer into the given array
- * starting at the given offset.
- *
- * @param dst the array into which values are to be written
- * @param offset the offset within the array of the first value to be written; must be
- * non-negative and no larger than {@code dst.length}
- * @param length the maximum number of values to be written to the given array; must be
- * non-negative and no larger than {@code dst.length - offset}
- * @return this buffer
- * @throws BufferUnderflowException if there are fewer than length values remaining in this buffer
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- */
- DataBuffer read(T[] dst, int offset, int length);
-
- /**
- * Write the references of the objects in the source array into this buffer.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code src.length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = src.length} values from the given array.
- *
- * @param src the source array from which values are to be read
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- default DataBuffer write(T[] src) {
- return write(src, 0, src.length);
- }
-
- /**
- * Bulk put method, using int arrays.
- *
- * This method transfers the values in the given source array into this buffer. If there are
- * more values in the source array than in this buffer, that is, if
- * {@code length > size()}, then no values are transferred and a
- * BufferOverflowException is thrown.
- *
- * Otherwise, this method copies {@code n = length} values from the given array into this buffer,
- * starting at the given offset.
- *
- * @param src the source array from which values are to be read
- * @param offset the offset within the array of the first value to be read; must be non-negative
- * and no larger than {@code src.length}
- * @param length the number of values to be read from the given array; must be non-negative and no
- * larger than {@code src.length - offset}
- * @return this buffer
- * @throws BufferOverflowException if there is insufficient space in this buffer for the values in
- * the source array
- * @throws IndexOutOfBoundsException if the preconditions on the offset and length parameters do
- * not hold
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- DataBuffer write(T[] src, int offset, int length);
-
- /**
- * Write the references of the objects in the source array into this buffer.
- *
- * If there are more values to copy than the destination buffer size, i.e.
- * {@code size > dst.size()}, then no values are transferred and a
- * BufferOverflowException is thrown. On the other hand, if there are more values to copy that
- * the source buffer size, i.e. {@code > src.size()}, then a BufferUnderfloatException is thrown.
- *
- * Otherwise, this method copies {@code n = size} values from this buffer into
- * the destination buffer.
- *
- * @param dst the destination buffer into which values are copied; must not be this buffer
- * @param size number of values to copy to the destination buffer
- * @return this buffer
- * @throws IllegalArgumentException if the destination buffer is this buffer
- * @throws ReadOnlyBufferException if the destination buffer is read-only
- * @throws java.nio.BufferOverflowException if there is not enough space in destination buffer
- * @throws java.nio.BufferUnderflowException if there are not enough values in the source buffer
- */
- DataBuffer copyTo(DataBuffer dst, long size);
-
- /**
- * Creates a new buffer whose content is a shared subsequence of this buffer's content, starting
- * at the given index.
- *
- * The index must not be greater than this buffer size. Changes to this buffer's content will
- * be visible in the new buffer and vice versa. The new buffer will be read-only if, and only if,
- * this buffer is read-only.
- *
- * This call is equivalent to {@link #slice(long, long) slice(index, size() - index)}
- *
- * @param index index of the first value of the new buffer created, must not be greater than
- * {@code size()}
- * @return the new buffer
- * @throws IllegalArgumentException if index do not pass validation checks
- */
- default DataBuffer offset(long index) {
- return slice(index, size() - index);
- }
-
- /**
- * Creates a new buffer whose content is a shared subsequence of this buffer's content, whose
- * size is set to the given value.
- *
- * The new size must not be greater than this buffer size. Changes to this buffer's
- * content will be visible in the new buffer and vice versa. The new buffer will be read-only if,
- * and only if, this buffer is read-only.
- *
- * This call is equivalent to {@link #slice(long, long) slice(0, size)}
- *
- * @param size size of this new buffer
- * @return the new buffer
- * @throws IllegalArgumentException if index and/or size values do not pass validation checks
- */
- default DataBuffer narrow(long size) {
- return slice(0, size);
- }
-
- /**
- * Creates a new buffer whose content is a shared subsequence of this buffer's content, starting
- * at the given index and of the given size.
- *
- * The index plus the new size must not be greater than this buffer size. Changes to this
- * buffer's content will be visible in the new buffer and vice versa. The new buffer will be
- * read-only if, and only if, this buffer is read-only.
- *
- * @param index index of the first value of the new buffer created
- * @param size size of this new buffer, must not be greater than {@code size()}
- * @return the new buffer
- * @throws IllegalArgumentException if size value do not pass validation checks
- */
- DataBuffer slice(long index, long size);
-
- /**
- * Creates a {@link DataBufferWindow} that provides a partial view of this buffer.
- *
- * The created window has a fixed size and can {@link DataBufferWindow#slide(long) "slide"}
- * along this buffer to provide different views of the data without allocating a new buffer
- * instance, like {@link #offset(long)} does. This improves overall performance when this
- * operation is repeated frequently. For example:
- *
- *
{@code
- * IntDataBuffer bufferA = DataBuffers.ofInts(1024);
- * // ... init buffer data
- * IntDataBuffer bufferB = DataBuffers.ofInts(1, 2, 3, 4);
- *
- * // Return the index of the first occurrence of bufferB in bufferA using a sliding window
- * DataBufferWindow windowA = bufferA.window(4);
- * for (int i = 0; i < bufferA.size() - bufferB.size(); ++i) {
- * if (windowA.slideTo(i).buffer().equals(bufferB)) {
- * return i;
- * }
- * }
- * }
- *
- * The returned object is stateful and is not thread-safe.
- *
- * @param size size of the window
- * @return a new window that starts at the index 0 of this buffer
- * @throws UnsupportedOperationException if this type of buffer does not support buffer windows
- */
- default DataBufferWindow extends DataBuffer> window(long size) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Visits the backing storage of this buffer.
- *
- * The buffer implementation is responsible of passing back a reference to the actual data
- * storage to the provided visitor. The visitor does not have to handle all possible types of
- * data storage and can override only methods for storage it is actually interested in. For any
- * other type of storage, this call will fallback to {@link DataStorageVisitor#fallback()} so the
- * visitor can execute some generic routine if needed.
- *
- * @param visitor visits the data storage of this buffer
- * @param type of value returned by the visitor
- * @return the same value returned by the visitor
- */
- default R accept(DataStorageVisitor visitor) {
- return visitor.fallback();
- }
-
- /**
- * Checks equality between data buffers.
- *
- * A data buffer is equal to another object if this object is another {@link DataBuffer} of the
- * same size, type and the elements are equal and in the same order. For example:
- *
- *
{@code
- * IntDataBuffer buffer = DataBuffers.of(1, 2, 3);
- *
- * assertEquals(buffer, DataBuffers.of(1, 2, 3)); // true
- * assertEquals(buffer, DataBuffers.ofObjects(1, 2, 3)); // true, as Integers are equal to ints
- * assertNotEquals(buffer, DataBuffers.of(1, 2, 3, 0)); // false, different sizes
- * assertNotEquals(buffer, DataBuffers.of(1, 3, 2)); // false, different order
- * assertNotEquals(buffer, DataBuffers.of(1L, 2L, 3L)); // false, different types
- * }
- *
- * Note that the computation required to verify equality between two buffers can be expensive
- * in some cases and therefore, it is recommended to not use this method in a critical path
- * where performances matter.
- *
- * @param obj object to compare this buffer with
- * @return true if this buffer is equal to the provided object
- */
- @Override
- boolean equals(Object obj);
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBufferWindow.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBufferWindow.java
deleted file mode 100644
index 85fc8c43d05..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBufferWindow.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package org.tensorflow.ndarray.buffer;
-
-/**
- * A mutable container for viewing part of a {@link DataBuffer}.
- *
- *
Data buffer windows have a fixed size and can {@link DataBufferWindow#slide(long) "slide"}
- * along a buffer to provide different views of the data without allocating a new buffer instance,
- * like {@link DataBuffer#offset(long)} does. This improves overall performance when this operation
- * is repeated frequently. For example:
- *
- *
{@code
- * IntDataBuffer bufferA = DataBuffers.ofInts(1024);
- * // ... init buffer data
- * IntDataBuffer bufferB = DataBuffers.ofInts(1, 2, 3, 4);
- *
- * // Return the index of the first occurrence of bufferB in bufferA using a sliding window
- * DataBufferWindow windowA = bufferA.window(4);
- * for (int i = 0; i < bufferA.size() - bufferB.size(); ++i) {
- * if (windowA.slideTo(i).buffer().equals(bufferB)) {
- * return i;
- * }
- * }
- * }
- *
- * {@code DataBufferWindow} instances are stateful and not thread-safe.
- *
- * @param the type of buffer being viewed
- */
-public interface DataBufferWindow> {
-
- /**
- * Returns the current offset of this window in the original buffer.
- */
- long offset();
-
- /**
- * Returns the size of this buffer window.
- */
- long size();
-
- /**
- * Moves the window at the given position in the original buffer.
- *
- *
The size of the window remains the same and its offset is set to {@code index}, so that
- * accessing the value of {@link #buffer()} at index {@code x} will return the value at
- * {@code index + x} in the original buffer.
- *
- * @param index new offset for this window
- * @return this instance
- * @throws IndexOutOfBoundsException if the window cannot be slid because it goes beyond
- * the original buffer limits
- */
- DataBufferWindow slideTo(long index);
-
- /**
- * Moves the window of {@code step} elements in the original buffer.
- *
- *
The size of the window remains the same and its offset is set to {@code offset() + step}.
- * If {@code step} is positive, then the window will slide forward. If it is negative, it will
- * slide backward.
- *
- * @param step value to add to the current offset of this window
- * @return this instance
- * @throws IndexOutOfBoundsException if the window cannot be slid because it goes beyond
- * the original buffer limits
- */
- DataBufferWindow slide(long step);
-
- /**
- * Returns the buffer backing this window.
- *
- *
Each window instance has it's own buffer providing a view onto the original
- * {@link DataBuffer}. The buffers are mutated when the window slides to different offsets.
- * For example:
- *
- *
{@code
- * IntDataBuffer buffer = DataBuffers.of(0, 1, 2, 3);
- * DataBufferWindow window = buffer.window(0, 2);
- *
- * IntDataBuffer windowBuffer = window.buffer();
- * assertEquals(0, windowBuffer.getInt(0));
- * assertEquals(1, windowBuffer.getInt(1));
- *
- * window.slideTo(2);
- * assertEquals(2, windowBuffer.getInt(0));
- * assertEquals(3, windowBuffer.getInt(1));
- * assertSame(windowBuffer, window.buffer());
- * }
- *
- * @return this window's buffer
- */
- B buffer();
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBuffers.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBuffers.java
deleted file mode 100644
index a5feb2599d0..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataBuffers.java
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- 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.buffer;
-
-import java.lang.reflect.Array;
-import java.nio.ByteBuffer;
-import java.nio.DoubleBuffer;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-import java.nio.LongBuffer;
-import java.nio.ShortBuffer;
-import java.util.Arrays;
-import java.util.BitSet;
-import org.tensorflow.ndarray.impl.buffer.Validator;
-import org.tensorflow.ndarray.impl.buffer.misc.MiscDataBufferFactory;
-import org.tensorflow.ndarray.impl.buffer.nio.NioDataBufferFactory;
-import org.tensorflow.ndarray.impl.buffer.raw.RawDataBufferFactory;
-
-/**
- * Helper class for creating {@code DataBuffer} instances.
- */
-public final class DataBuffers {
-
- /**
- * Creates a buffer of bytes that can store up to {@code size} values
- *
- * @param size size of the buffer to allocate
- * @return a new buffer
- */
- public static ByteDataBuffer ofBytes(long size) {
- Validator.createArgs(size, MAX_32BITS);
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(new byte[(int)size], false);
- }
- return NioDataBufferFactory.create(ByteBuffer.allocate((int)size));
- }
-
- /**
- * Creates a buffer of longs that can store up to {@code size} values
- *
- * @param size size of the buffer to allocate
- * @return a new buffer
- */
- public static LongDataBuffer ofLongs(long size) {
- Validator.createArgs(size, MAX_32BITS);
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(new long[(int)size], false);
- }
- return NioDataBufferFactory.create(LongBuffer.allocate((int)size));
- }
-
- /**
- * Creates a buffer of integers that can store up to {@code size} values
- *
- * @param size size of the buffer to allocate
- * @return a new buffer
- */
- public static IntDataBuffer ofInts(long size) {
- Validator.createArgs(size, MAX_32BITS);
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(new int[(int)size], false);
- }
- return NioDataBufferFactory.create(IntBuffer.allocate((int)size));
- }
-
- /**
- * Creates a buffer of shorts that can store up to {@code size} values
- *
- * @param size size of the buffer to allocate
- * @return a new buffer
- */
- public static ShortDataBuffer ofShorts(long size) {
- Validator.createArgs(size, MAX_32BITS);
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(new short[(int)size], false);
- }
- return NioDataBufferFactory.create(ShortBuffer.allocate((int)size));
- }
-
- /**
- * Creates a buffer of doubles that can store up to {@code size} values
- *
- * @param size size of the buffer to allocate
- * @return a new buffer
- */
- public static DoubleDataBuffer ofDoubles(long size) {
- Validator.createArgs(size, MAX_32BITS);
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(new double[(int)size], false);
- }
- return NioDataBufferFactory.create(DoubleBuffer.allocate((int)size));
- }
-
- /**
- * Creates a buffer of floats that can store up to {@code size} values
- *
- * @param size size of the buffer to allocate
- * @return a new buffer
- */
- public static FloatDataBuffer ofFloats(long size) {
- Validator.createArgs(size, MAX_32BITS);
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(new float[(int)size], false);
- }
- return NioDataBufferFactory.create(FloatBuffer.allocate((int)size));
- }
-
- /**
- * Creates a buffer of booleans that can store up to {@code size} values
- *
- * @param size size of the buffer to allocate
- * @return a new buffer
- */
- public static BooleanDataBuffer ofBooleans(long size) {
- Validator.createArgs(size, MAX_32BITS);
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(new boolean[(int)size], false);
- }
- return MiscDataBufferFactory.create(new BitSet((int)size), size, false);
- }
-
- /**
- * Creates a buffer of references to objects of type {@code clazz` that can store up to `size}
- * values.
- *
- * @param type the type of object stored in this buffer
- * @param size size of the buffer to allocate
- * @param data type
- * @return a new buffer
- */
- public static DataBuffer ofObjects(Class type, long size) {
- Validator.createArgs(size, MAX_32BITS);
- @SuppressWarnings("unchecked")
- T[] array = (T[])Array.newInstance(type, (int)size);
- return MiscDataBufferFactory.create(array, false);
- }
-
- /**
- * Create a buffer from an array of floats into a data buffer.
- *
- * The returned buffer allows read and write operations and share the memory of the source
- * array, which is equivalent to call {@link #of(float[], boolean, boolean) of(values, false, false}}
- *
- * @param values float values
- * @return a new buffer
- */
- public static FloatDataBuffer of(float... values) {
- return of(values, false, false);
- }
-
- /**
- * Create a buffer from an array of bytes into a data buffer.
- *
- *
The returned buffer allows read and write operations and share the memory of the source
- * array, which is equivalent to call {@link #of(byte[], boolean, boolean) of(values, false, false}}
- *
- * @param values byte values
- * @return a new buffer
- */
- public static ByteDataBuffer of(byte... values) {
- return of(values, false, false);
- }
-
- /**
- * Create a buffer from an array of longs into a data buffer.
- *
- *
The returned buffer allows read and write operations and share the memory of the source
- * array, which is equivalent to call {@link #of(long[], boolean, boolean) of(values, false, false}}
- *
- * @param values long values
- * @return a new buffer
- */
- public static LongDataBuffer of(long... values) {
- return of(values, false, false);
- }
-
- /**
- * Create a buffer from an array of ints into a data buffer.
- *
- *
The returned buffer allows read and write operations and share the memory of the source
- * array, which is equivalent to call {@link #of(int[], boolean, boolean) of(values, false, false}}
- *
- * @param values int values
- * @return a new buffer
- */
- public static IntDataBuffer of(int... values) {
- return of(values, false, false);
- }
-
- /**
- * Create a buffer from an array of shorts into a data buffer.
- *
- *
The returned buffer allows read and write operations and share the memory of the source
- * array, which is equivalent to call {@link #of(short[], boolean, boolean) of(values, false, false}}
- *
- * @param values short values
- * @return a new buffer
- */
- public static ShortDataBuffer of(short... values) {
- return of(values, false, false);
- }
-
- /**
- * Create a buffer from an array of doubles into a data buffer.
- *
- *
The returned buffer allows read and write operations and share the memory of the source
- * array, which is equivalent to call {@link #of(double[], boolean, boolean) of(array, false, false}}
- *
- * @param values double values
- * @return a new buffer
- */
- public static DoubleDataBuffer of(double... values) {
- return of(values, false, false);
- }
-
- /**
- * Create a buffer from an array of booleans into a data buffer.
- *
- *
The returned buffer allows read and write operations and share the memory of the source
- * array, which is equivalent to call {@link #of(boolean[], boolean, boolean) of(values, false, false}}
- *
- * @param values booleans values
- * @return a new buffer
- */
- public static BooleanDataBuffer of(boolean... values) {
- return of(values, false, false);
- }
-
- /**
- * Create a buffer from an array of objects into a data buffer.
- *
- *
The returned buffer allows read and write operations and share the memory of the source
- * array, which is equivalent to call {@link #of(Object[], boolean, boolean) of(values, false, false}}
- *
- * @param values objects values
- * @param data type
- * @return a new buffer
- */
- @SafeVarargs
- public static DataBuffer ofObjects(T... values) {
- return of(values, false, false);
- }
-
- /**
- * Create a buffer from an array of floats into a data buffer.
- *
- * @param array array of floats
- * @param readOnly true if the buffer created must be read-only
- * @param makeCopy true if the array must be copied, false will wrap the provided array
- * @return a new buffer
- */
- public static FloatDataBuffer of(float[] array, boolean readOnly, boolean makeCopy) {
- float[] bufferArray = makeCopy ? Arrays.copyOf(array, array.length) : array;
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(bufferArray, readOnly);
- }
- FloatBuffer buf = FloatBuffer.wrap(bufferArray);
- return NioDataBufferFactory.create(readOnly ? buf.asReadOnlyBuffer() : buf);
- }
-
- /**
- * Create a buffer from an array of bytes into a data buffer.
- *
- * @param array array of bytes
- * @param readOnly true if the buffer created must be read-only
- * @param makeCopy true if the array must be copied, false will wrap the provided array
- * @return a new buffer
- */
- public static ByteDataBuffer of(byte[] array, boolean readOnly, boolean makeCopy) {
- byte[] bufferArray = makeCopy ? Arrays.copyOf(array, array.length) : array;
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(bufferArray, readOnly);
- }
- ByteBuffer buf = ByteBuffer.wrap(bufferArray);
- return NioDataBufferFactory.create(readOnly ? buf.asReadOnlyBuffer() : buf);
- }
-
- /**
- * Create a buffer from an array of longs into a data buffer.
- *
- * @param array array of longs
- * @param readOnly true if the buffer created must be read-only
- * @param makeCopy true if the array must be copied, false will wrap the provided array
- * @return a new buffer
- */
- public static LongDataBuffer of(long[] array, boolean readOnly, boolean makeCopy) {
- long[] bufferArray = makeCopy ? Arrays.copyOf(array, array.length) : array;
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(bufferArray, readOnly);
- }
- LongBuffer buf = LongBuffer.wrap(bufferArray);
- return NioDataBufferFactory.create(readOnly ? buf.asReadOnlyBuffer() : buf);
- }
-
- /**
- * Create a buffer from an array of ints into a data buffer.
- *
- * @param array array of ints
- * @param readOnly true if the buffer created must be read-only
- * @param makeCopy true if the array must be copied, false will wrap the provided array
- * @return a new buffer
- */
- public static IntDataBuffer of(int[] array, boolean readOnly, boolean makeCopy) {
- int[] bufferArray = makeCopy ? Arrays.copyOf(array, array.length) : array;
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(bufferArray, readOnly);
- }
- IntBuffer buf = IntBuffer.wrap(bufferArray);
- return NioDataBufferFactory.create(readOnly ? buf.asReadOnlyBuffer() : buf);
- }
-
- /**
- * Create a buffer from an array of shorts into a data buffer.
- *
- * @param array array of shorts
- * @param readOnly true if the buffer created must be read-only
- * @param makeCopy true if the array must be copied, false will wrap the provided array
- * @return a new buffer
- */
- public static ShortDataBuffer of(short[] array, boolean readOnly, boolean makeCopy) {
- short[] bufferArray = makeCopy ? Arrays.copyOf(array, array.length) : array;
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(bufferArray, readOnly);
- }
- ShortBuffer buf = ShortBuffer.wrap(bufferArray);
- return NioDataBufferFactory.create(readOnly ? buf.asReadOnlyBuffer() : buf);
- }
-
- /**
- * Create a buffer from an array of doubles into a data buffer.
- *
- * @param array array of doubles
- * @param readOnly true if the buffer created must be read-only
- * @param makeCopy true if the array must be copied, false will wrap the provided array
- * @return a new buffer
- */
- public static DoubleDataBuffer of(double[] array, boolean readOnly, boolean makeCopy) {
- double[] bufferArray = makeCopy ? Arrays.copyOf(array, array.length) : array;
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(bufferArray, readOnly);
- }
- DoubleBuffer buf = DoubleBuffer.wrap(bufferArray);
- return NioDataBufferFactory.create(readOnly ? buf.asReadOnlyBuffer() : buf);
- }
-
- /**
- * Create a buffer from an array of booleans into a data buffer.
- *
- * @param array array of booleans
- * @param readOnly true if the buffer created must be read-only
- * @param makeCopy true if the array must be copied, false will wrap the provided array
- * @return a new buffer
- */
- public static BooleanDataBuffer of(boolean[] array, boolean readOnly, boolean makeCopy) {
- boolean[] bufferArray = makeCopy ? Arrays.copyOf(array, array.length) : array;
- if (RawDataBufferFactory.canBeUsed()) {
- return RawDataBufferFactory.create(bufferArray, readOnly);
- }
- return MiscDataBufferFactory.create(bufferArray, readOnly);
- }
-
- /**
- * Create a buffer from an array of objects into a data buffer.
- *
- * @param array array of objects
- * @param readOnly true if the buffer created must be read-only
- * @param makeCopy true if the array must be copied, false will wrap the provided array
- * @param data type
- * @return a new buffer
- */
- public static DataBuffer of(T[] array, boolean readOnly, boolean makeCopy) {
- T[] bufferArray = makeCopy ? Arrays.copyOf(array, array.length) : array;
- return MiscDataBufferFactory.create(bufferArray, readOnly);
- }
-
- /**
- * Wraps a JDK NIO {@link ByteBuffer} into a data buffer.
- *
- * @param buf buffer to wrap
- * @return a new buffer
- */
- public static ByteDataBuffer of(ByteBuffer buf) {
- return NioDataBufferFactory.create(buf.duplicate());
- }
-
- /**
- * Wraps a JDK NIO {@link IntBuffer} into a data buffer.
- *
- * @param buf buffer to wrap
- * @return a new buffer
- */
- public static IntDataBuffer of(IntBuffer buf) {
- return NioDataBufferFactory.create(buf.duplicate());
- }
-
- /**
- * Wraps a JDK NIO {@link ShortBuffer} into a data buffer.
- *
- * @param buf buffer to wrap
- * @return a new buffer
- */
- public static ShortDataBuffer of(ShortBuffer buf) {
- return NioDataBufferFactory.create(buf.duplicate());
- }
-
- /**
- * Wraps a JDK NIO {@link LongBuffer} into a data buffer.
- *
- * @param buf buffer to wrap
- * @return a new buffer
- */
- public static LongDataBuffer of(LongBuffer buf) {
- return NioDataBufferFactory.create(buf.duplicate());
- }
-
- /**
- * Wraps a JDK NIO {@link FloatBuffer} into a data buffer.
- *
- * @param buf buffer to wrap
- * @return a new buffer
- */
- public static FloatDataBuffer of(FloatBuffer buf) {
- return NioDataBufferFactory.create(buf.duplicate());
- }
-
- /**
- * Wraps a JDK NIO {@link DoubleBuffer} into a data buffer.
- *
- * @param buf buffer to wrap
- * @return a new buffer
- */
- public static DoubleDataBuffer of(DoubleBuffer buf) {
- return NioDataBufferFactory.create(buf.duplicate());
- }
-
- /*
- * The maximum size for a buffer of this type, i.e. the maximum number of bytes it can store.
- *
- * As the maximum size may vary depending on the JVM implementation and on the platform, this
- * property returns a value that is safe for most of them.
- */
- static long MAX_32BITS = Integer.MAX_VALUE - 10;
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataStorageVisitor.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataStorageVisitor.java
deleted file mode 100644
index 560320cd7eb..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DataStorageVisitor.java
+++ /dev/null
@@ -1,147 +0,0 @@
-package org.tensorflow.ndarray.buffer;
-
-import java.nio.ByteBuffer;
-import java.nio.DoubleBuffer;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-import java.nio.LongBuffer;
-import java.nio.ShortBuffer;
-import java.util.BitSet;
-
-/**
- * Visit the backing storage of {@link DataBuffer} instances.
- *
- * @param value type returned by the visitor
- */
-public interface DataStorageVisitor {
-
- /**
- * Visit the {@link ByteBuffer} backing a given instance of a {@link DataBuffer}
- *
- * @param buffer underlying buffer
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(ByteBuffer buffer) {
- return fallback();
- }
-
- /**
- * Visit the {@link ShortBuffer} backing a given instance of a {@link DataBuffer}
- *
- * @param buffer underlying buffer
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(ShortBuffer buffer) {
- return fallback();
- }
-
- /**
- * Visit the {@link IntBuffer} backing a given instance of a {@link DataBuffer}
- *
- * @param buffer underlying buffer
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(IntBuffer buffer) {
- return fallback();
- }
-
- /**
- * Visit the {@link LongBuffer} backing a given instance of a {@link DataBuffer}
- *
- * @param buffer underlying buffer
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(LongBuffer buffer) {
- return fallback();
- }
-
- /**
- * Visit the {@link FloatBuffer} backing a given instance of a {@link DataBuffer}
- *
- * @param buffer underlying buffer
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(FloatBuffer buffer) {
- return fallback();
- }
-
- /**
- * Visit the {@link DoubleBuffer} backing a given instance of a {@link DataBuffer}
- *
- * @param buffer underlying buffer
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(DoubleBuffer buffer) {
- return fallback();
- }
-
- /**
- * Visit the boolean array backing a given instance of a {@link DataBuffer}
- *
- * @param array underlying array
- * @param offset offset of the buffer within the array
- * @param length length of the buffer within the array
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(boolean[] array, int offset, int length) {
- return fallback();
- }
-
- /**
- * Visit the bit set backing a given instance of a {@link DataBuffer}
- *
- * @param bitSet underlying bit set
- * @param offset offset of the buffer within the bit set
- * @param numBits number of bits used to represent the buffer within the bit set
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(BitSet bitSet, int offset, long numBits) {
- return fallback();
- }
-
- /**
- * Visit the object array backing a given instance of a {@link DataBuffer}
- *
- * @param array underlying array
- * @param offset offset of the buffer within the array
- * @param length length of the buffer within the array
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(Object[] array, int offset, int length) {
- return fallback();
- }
-
- /**
- * Visit the raw memory segment of a given instance of a {@link DataBuffer}
- *
- * @param address native address of the buffer
- * @param length length of the buffer
- * @param scale number of bytes required to store a single value of this buffer
- * @return any value
- * @see DataBuffer#accept(DataStorageVisitor)
- */
- default R visit(long address, long length, long scale) {
- return fallback();
- }
-
- /**
- * Fallback method called if the visitor implementation does not support the type of backing storage
- * for a given {@link DataBuffer}
- *
- * The implementor of this interface must override the {@code visit} methods for type of storage
- * it supports. If {@link DataBuffer#accept(DataStorageVisitor)} is called on a buffer
- * using a different type of storage, the invocation will fallback to this method.
- *
- * @return any value
- */
- R fallback();
-}
diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DoubleDataBuffer.java b/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DoubleDataBuffer.java
deleted file mode 100644
index f2db925eb78..00000000000
--- a/ndarray/src/main/java/org/tensorflow/ndarray/buffer/DoubleDataBuffer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- 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.buffer;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * A {@link DataBuffer} of doubles.
- */
-public interface DoubleDataBuffer extends DataBuffer {
-
- /**
- * Reads the double at the given index.
- *
- * @param index the index from which the float will be read
- * @return the double at the given index
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- */
- double getDouble(long index);
-
- /**
- * Writes the given double into this buffer at the given index.
- *
- * @param value the double to be written
- * @param index the index at which the value will be written
- * @return this buffer
- * @throws IndexOutOfBoundsException if index is negative or not smaller than the buffer size
- * @throws ReadOnlyBufferException if this buffer is read-only
- */
- DoubleDataBuffer setDouble(double value, long index);
-
- /**
- * Bulk