From d0022a1d2c232b1a6e5c36926ea0425fd616228e Mon Sep 17 00:00:00 2001 From: Karl Lessard Date: Sun, 18 Feb 2024 21:37:15 -0500 Subject: [PATCH 1/2] Rename read/write to copyTo/From --- README.md | 2 +- .../tensorflow/ndarray/BooleanNdArray.java | 8 +++---- .../org/tensorflow/ndarray/ByteNdArray.java | 8 +++---- .../org/tensorflow/ndarray/DoubleNdArray.java | 8 +++---- .../org/tensorflow/ndarray/FloatNdArray.java | 8 +++---- .../org/tensorflow/ndarray/IntNdArray.java | 8 +++---- .../org/tensorflow/ndarray/LongNdArray.java | 8 +++---- .../java/org/tensorflow/ndarray/NdArray.java | 12 ++++++---- .../org/tensorflow/ndarray/ShortNdArray.java | 8 +++---- .../org/tensorflow/ndarray/StdArrays.java | 16 ++++++------- .../tensorflow/ndarray/impl/Validator.java | 4 ++-- .../impl/dense/AbstractDenseNdArray.java | 8 +++---- .../impl/dense/BooleanDenseNdArray.java | 8 +++---- .../ndarray/impl/dense/ByteDenseNdArray.java | 8 +++---- .../impl/dense/DoubleDenseNdArray.java | 8 +++---- .../ndarray/impl/dense/FloatDenseNdArray.java | 8 +++---- .../ndarray/impl/dense/IntDenseNdArray.java | 8 +++---- .../ndarray/impl/dense/LongDenseNdArray.java | 8 +++---- .../ndarray/impl/dense/ShortDenseNdArray.java | 8 +++---- .../impl/sparse/BooleanSparseNdArray.java | 24 +++++++++---------- .../impl/sparse/ByteSparseNdArray.java | 24 +++++++++---------- .../impl/sparse/DoubleSparseNdArray.java | 24 +++++++++---------- .../impl/sparse/FloatSparseNdArray.java | 24 +++++++++---------- .../ndarray/impl/sparse/IntSparseNdArray.java | 24 +++++++++---------- .../impl/sparse/LongSparseNdArray.java | 24 +++++++++---------- .../impl/sparse/ShortSparseNdArray.java | 24 +++++++++---------- .../ndarray/impl/sparse/SparseNdArray.java | 16 ++++++------- .../impl/sparse/slice/BooleanSparseSlice.java | 12 +++++----- .../impl/sparse/slice/ByteSparseSlice.java | 12 +++++----- .../impl/sparse/slice/DoubleSparseSlice.java | 12 +++++----- .../impl/sparse/slice/FloatSparseSlice.java | 12 +++++----- .../impl/sparse/slice/IntSparseSlice.java | 12 +++++----- .../impl/sparse/slice/LongSparseSlice.java | 12 +++++----- .../impl/sparse/slice/ObjectSparseSlice.java | 4 ++-- .../impl/sparse/slice/ShortSparseSlice.java | 12 +++++----- .../impl/sparse/slice/SparseSlice.java | 2 +- .../tensorflow/ndarray/NdArrayTestBase.java | 8 +++---- .../impl/sparse/BooleanSparseNdArrayTest.java | 12 +++++----- .../impl/sparse/ByteSparseNdArrayTest.java | 12 +++++----- .../impl/sparse/DoubleSparseNdArrayTest.java | 12 +++++----- .../impl/sparse/FloatSparseNdArrayTest.java | 12 +++++----- .../impl/sparse/IntSparseNdArrayTest.java | 12 +++++----- .../impl/sparse/LongSparseNdArrayTest.java | 12 +++++----- .../impl/sparse/ShortSparseNdArrayTest.java | 12 +++++----- .../impl/sparse/StringSparseNdArrayTest.java | 12 +++++----- 45 files changed, 268 insertions(+), 264 deletions(-) diff --git a/README.md b/README.md index 5e860b6..780d50c 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ IntNdArray vector = matrix3d.get(0, 1); assertEquals(1, vector.rank()); // Rewriting the values of the vector using a primitive array -vector.write(new int[] { 7, 8 }); +vector.copyFrom(DataBuffers.of(new int[] { 7, 8 })); assertEquals(7, matrix3d.getInt(0, 1, 0)); assertEquals(8, matrix3d.getInt(0, 1, 1)); diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/BooleanNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/BooleanNdArray.java index bd16a9a..a762896 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/BooleanNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/BooleanNdArray.java @@ -100,12 +100,12 @@ default BooleanNdArray setObject(Boolean value, long... coordinates) { BooleanNdArray copyTo(NdArray dst); @Override - BooleanNdArray read(DataBuffer dst); + BooleanNdArray copyTo(DataBuffer dst); - BooleanNdArray read(BooleanDataBuffer dst); + BooleanNdArray copyTo(BooleanDataBuffer dst); @Override - BooleanNdArray write(DataBuffer src); + BooleanNdArray copyFrom(DataBuffer src); - BooleanNdArray write(BooleanDataBuffer src); + BooleanNdArray copyFrom(BooleanDataBuffer src); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/ByteNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/ByteNdArray.java index 47e5a0d..7a6f0cd 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/ByteNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/ByteNdArray.java @@ -100,12 +100,12 @@ default ByteNdArray setObject(Byte value, long... coordinates) { ByteNdArray copyTo(NdArray dst); @Override - ByteNdArray read(DataBuffer dst); + ByteNdArray copyTo(DataBuffer dst); - ByteNdArray read(ByteDataBuffer dst); + ByteNdArray copyTo(ByteDataBuffer dst); @Override - ByteNdArray write(DataBuffer src); + ByteNdArray copyFrom(DataBuffer src); - ByteNdArray write(ByteDataBuffer src); + ByteNdArray copyFrom(ByteDataBuffer src); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/DoubleNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/DoubleNdArray.java index da42bab..d8d2312 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/DoubleNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/DoubleNdArray.java @@ -115,12 +115,12 @@ default DoubleNdArray setObject(Double value, long... coordinates) { DoubleNdArray copyTo(NdArray dst); @Override - DoubleNdArray read(DataBuffer dst); + DoubleNdArray copyTo(DataBuffer dst); - DoubleNdArray read(DoubleDataBuffer dst); + DoubleNdArray copyTo(DoubleDataBuffer dst); @Override - DoubleNdArray write(DataBuffer src); + DoubleNdArray copyFrom(DataBuffer src); - DoubleNdArray write(DoubleDataBuffer src); + DoubleNdArray copyFrom(DoubleDataBuffer src); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/FloatNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/FloatNdArray.java index 34e4201..98ec87e 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/FloatNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/FloatNdArray.java @@ -100,12 +100,12 @@ default FloatNdArray setObject(Float value, long... coordinates) { FloatNdArray copyTo(NdArray dst); @Override - FloatNdArray read(DataBuffer dst); + FloatNdArray copyTo(DataBuffer dst); - FloatNdArray read(FloatDataBuffer dst); + FloatNdArray copyTo(FloatDataBuffer dst); @Override - FloatNdArray write(DataBuffer src); + FloatNdArray copyFrom(DataBuffer src); - FloatNdArray write(FloatDataBuffer src); + FloatNdArray copyFrom(FloatDataBuffer src); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/IntNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/IntNdArray.java index 71f19b9..b165900 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/IntNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/IntNdArray.java @@ -115,12 +115,12 @@ default IntNdArray setObject(Integer value, long... coordinates) { IntNdArray copyTo(NdArray dst); @Override - IntNdArray read(DataBuffer dst); + IntNdArray copyTo(DataBuffer dst); - IntNdArray read(IntDataBuffer dst); + IntNdArray copyTo(IntDataBuffer dst); @Override - IntNdArray write(DataBuffer src); + IntNdArray copyFrom(DataBuffer src); - IntNdArray write(IntDataBuffer src); + IntNdArray copyFrom(IntDataBuffer src); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/LongNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/LongNdArray.java index a55b2ab..5d5766a 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/LongNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/LongNdArray.java @@ -115,12 +115,12 @@ default LongNdArray setObject(Long value, long... coordinates) { LongNdArray copyTo(NdArray dst); @Override - LongNdArray read(DataBuffer dst); + LongNdArray copyTo(DataBuffer dst); - LongNdArray read(LongDataBuffer dst); + LongNdArray copyTo(LongDataBuffer dst); @Override - LongNdArray write(DataBuffer src); + LongNdArray copyFrom(DataBuffer src); - LongNdArray write(LongDataBuffer src); + LongNdArray copyFrom(LongDataBuffer src); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java index a75da48..c1da370 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java @@ -285,33 +285,37 @@ default Stream streamOfObjects() { NdArray copyTo(NdArray dst); /** - * Read the content of this N-dimensional array into the destination buffer. + * Copy 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. * + *

Note: this method was previously named `read(DataBuffer)`, which led to confusion. + * * @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); + NdArray copyTo(DataBuffer dst); /** - * Write the content of this N-dimensional array from the source buffer. + * Copy the content of the source buffer into this N-dimensional array. * *

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. * + *

Note: this method was previously named `write(DataBuffer)`, which led to confusion. + * * @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); + NdArray copyFrom(DataBuffer src); /** * Checks equality between n-dimensional arrays. diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java index 92b608f..022ccf7 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java @@ -100,12 +100,12 @@ default ShortNdArray setObject(Short value, long... coordinates) { ShortNdArray copyTo(NdArray dst); @Override - ShortNdArray read(DataBuffer dst); + ShortNdArray copyTo(DataBuffer dst); - ShortNdArray read(ShortDataBuffer dst); + ShortNdArray copyTo(ShortDataBuffer dst); @Override - ShortNdArray write(DataBuffer src); + ShortNdArray copyFrom(DataBuffer src); - ShortNdArray write(ShortDataBuffer src); + ShortNdArray copyFrom(ShortDataBuffer src); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/StdArrays.java b/ndarray/src/main/java/org/tensorflow/ndarray/StdArrays.java index 249e69a..7367165 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/StdArrays.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/StdArrays.java @@ -2010,7 +2010,7 @@ public static void copyFrom(IntNdArray src, int[] dst) { if (src.size() > dst.length) { throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length); } - src.read(DataBuffers.of(dst, false, false)); + src.copyTo(DataBuffers.of(dst, false, false)); } /** @@ -2113,7 +2113,7 @@ public static void copyFrom(LongNdArray src, long[] dst) { if (src.size() > dst.length) { throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length); } - src.read(DataBuffers.of(dst, false, false)); + src.copyTo(DataBuffers.of(dst, false, false)); } /** @@ -2216,7 +2216,7 @@ public static void copyFrom(FloatNdArray src, float[] dst) { if (src.size() > dst.length) { throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length); } - src.read(DataBuffers.of(dst, false, false)); + src.copyTo(DataBuffers.of(dst, false, false)); } /** @@ -2319,7 +2319,7 @@ public static void copyFrom(DoubleNdArray src, double[] dst) { if (src.size() > dst.length) { throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length); } - src.read(DataBuffers.of(dst, false, false)); + src.copyTo(DataBuffers.of(dst, false, false)); } /** @@ -2422,7 +2422,7 @@ public static void copyFrom(ByteNdArray src, byte[] dst) { if (src.size() > dst.length) { throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length); } - src.read(DataBuffers.of(dst, false, false)); + src.copyTo(DataBuffers.of(dst, false, false)); } /** @@ -2525,7 +2525,7 @@ public static void copyFrom(ShortNdArray src, short[] dst) { if (src.size() > dst.length) { throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length); } - src.read(DataBuffers.of(dst, false, false)); + src.copyTo(DataBuffers.of(dst, false, false)); } /** @@ -2628,7 +2628,7 @@ public static void copyFrom(BooleanNdArray src, boolean[] dst) { if (src.size() > dst.length) { throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length); } - src.read(DataBuffers.of(dst, false, false)); + src.copyTo(DataBuffers.of(dst, false, false)); } /** @@ -2732,7 +2732,7 @@ public static void copyFrom(NdArray src, T[] dst) { if (src.size() > dst.length) { throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length); } - src.read(DataBuffers.of(dst, false, false)); + src.copyTo(DataBuffers.of(dst, false, false)); } /** diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/Validator.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/Validator.java index 285d099..3e0ba20 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/Validator.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/Validator.java @@ -30,13 +30,13 @@ public static void copyToNdArrayArgs(NdArray ndArray, NdArray otherNdArray } } - public static void readToBufferArgs(NdArray ndArray, DataBuffer dst) { + public static void copyToBufferArgs(NdArray ndArray, DataBuffer dst) { if (dst.size() < ndArray.size()) { throw new BufferOverflowException(); } } - public static void writeFromBufferArgs(NdArray ndArray, DataBuffer src) { + public static void copyFromBufferArgs(NdArray ndArray, DataBuffer src) { if (src.size() < ndArray.size()) { throw new BufferUnderflowException(); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/AbstractDenseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/AbstractDenseNdArray.java index baaf23e..a22518d 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/AbstractDenseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/AbstractDenseNdArray.java @@ -101,15 +101,15 @@ public U setObject(T value, long... coords) { } @Override - public U read(DataBuffer dst) { - Validator.readToBufferArgs(this, dst); + public U copyTo(DataBuffer dst) { + Validator.copyToBufferArgs(this, dst); DataTransfer.execute(buffer(), dimensions(), dst, DataTransfer::ofValue); return (U)this; } @Override - public U write(DataBuffer src) { - Validator.writeFromBufferArgs(this, src); + public U copyFrom(DataBuffer src) { + Validator.copyFromBufferArgs(this, src); DataTransfer.execute(src, buffer(), dimensions(), DataTransfer::ofValue); return (U)this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/BooleanDenseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/BooleanDenseNdArray.java index 9c134b5..c3df6e8 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/BooleanDenseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/BooleanDenseNdArray.java @@ -55,15 +55,15 @@ public BooleanNdArray copyTo(NdArray dst) { } @Override - public BooleanNdArray read(BooleanDataBuffer dst) { - Validator.readToBufferArgs(this, dst); + public BooleanNdArray copyTo(BooleanDataBuffer dst) { + Validator.copyToBufferArgs(this, dst); DataTransfer.execute(buffer, dimensions(), dst, DataTransfer::ofBoolean); return this; } @Override - public BooleanNdArray write(BooleanDataBuffer src) { - Validator.writeFromBufferArgs(this, src); + public BooleanNdArray copyFrom(BooleanDataBuffer src) { + Validator.copyFromBufferArgs(this, src); DataTransfer.execute(src, buffer, dimensions(), DataTransfer::ofBoolean); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/ByteDenseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/ByteDenseNdArray.java index a2525c6..1f01ce6 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/ByteDenseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/ByteDenseNdArray.java @@ -55,15 +55,15 @@ public ByteNdArray copyTo(NdArray dst) { } @Override - public ByteNdArray read(ByteDataBuffer dst) { - Validator.readToBufferArgs(this, dst); + public ByteNdArray copyTo(ByteDataBuffer dst) { + Validator.copyToBufferArgs(this, dst); DataTransfer.execute(buffer, dimensions(), dst, DataTransfer::ofByte); return this; } @Override - public ByteNdArray write(ByteDataBuffer src) { - Validator.writeFromBufferArgs(this, src); + public ByteNdArray copyFrom(ByteDataBuffer src) { + Validator.copyFromBufferArgs(this, src); DataTransfer.execute(src, buffer, dimensions(), DataTransfer::ofByte); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/DoubleDenseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/DoubleDenseNdArray.java index a967ce1..d983d16 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/DoubleDenseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/DoubleDenseNdArray.java @@ -55,15 +55,15 @@ public DoubleNdArray copyTo(NdArray dst) { } @Override - public DoubleNdArray read(DoubleDataBuffer dst) { - Validator.readToBufferArgs(this, dst); + public DoubleNdArray copyTo(DoubleDataBuffer dst) { + Validator.copyToBufferArgs(this, dst); DataTransfer.execute(buffer, dimensions(), dst, DataTransfer::ofDouble); return this; } @Override - public DoubleNdArray write(DoubleDataBuffer src) { - Validator.writeFromBufferArgs(this, src); + public DoubleNdArray copyFrom(DoubleDataBuffer src) { + Validator.copyFromBufferArgs(this, src); DataTransfer.execute(src, buffer, dimensions(), DataTransfer::ofDouble); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/FloatDenseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/FloatDenseNdArray.java index a04c192..779e047 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/FloatDenseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/FloatDenseNdArray.java @@ -55,15 +55,15 @@ public FloatNdArray copyTo(NdArray dst) { } @Override - public FloatNdArray read(FloatDataBuffer dst) { - Validator.readToBufferArgs(this, dst); + public FloatNdArray copyTo(FloatDataBuffer dst) { + Validator.copyToBufferArgs(this, dst); DataTransfer.execute(buffer, dimensions(), dst, DataTransfer::ofFloat); return this; } @Override - public FloatNdArray write(FloatDataBuffer src) { - Validator.writeFromBufferArgs(this, src); + public FloatNdArray copyFrom(FloatDataBuffer src) { + Validator.copyFromBufferArgs(this, src); DataTransfer.execute(src, buffer, dimensions(), DataTransfer::ofFloat); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/IntDenseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/IntDenseNdArray.java index e1a726f..4e2183d 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/IntDenseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/IntDenseNdArray.java @@ -55,15 +55,15 @@ public IntNdArray copyTo(NdArray dst) { } @Override - public IntNdArray read(IntDataBuffer dst) { - Validator.readToBufferArgs(this, dst); + public IntNdArray copyTo(IntDataBuffer dst) { + Validator.copyToBufferArgs(this, dst); DataTransfer.execute(buffer, dimensions(), dst, DataTransfer::ofInt); return this; } @Override - public IntNdArray write(IntDataBuffer src) { - Validator.writeFromBufferArgs(this, src); + public IntNdArray copyFrom(IntDataBuffer src) { + Validator.copyFromBufferArgs(this, src); DataTransfer.execute(src, buffer, dimensions(), DataTransfer::ofInt); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/LongDenseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/LongDenseNdArray.java index 802cbcd..cde91a3 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/LongDenseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/LongDenseNdArray.java @@ -55,15 +55,15 @@ public LongNdArray copyTo(NdArray dst) { } @Override - public LongNdArray read(LongDataBuffer dst) { - Validator.readToBufferArgs(this, dst); + public LongNdArray copyTo(LongDataBuffer dst) { + Validator.copyToBufferArgs(this, dst); DataTransfer.execute(buffer, dimensions(), dst, DataTransfer::ofLong); return this; } @Override - public LongNdArray write(LongDataBuffer src) { - Validator.writeFromBufferArgs(this, src); + public LongNdArray copyFrom(LongDataBuffer src) { + Validator.copyFromBufferArgs(this, src); DataTransfer.execute(src, buffer, dimensions(), DataTransfer::ofLong); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/ShortDenseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/ShortDenseNdArray.java index 434b260..8d0dfc8 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/ShortDenseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/dense/ShortDenseNdArray.java @@ -55,15 +55,15 @@ public ShortNdArray copyTo(NdArray dst) { } @Override - public ShortNdArray read(ShortDataBuffer dst) { - Validator.readToBufferArgs(this, dst); + public ShortNdArray copyTo(ShortDataBuffer dst) { + Validator.copyToBufferArgs(this, dst); DataTransfer.execute(buffer, dimensions(), dst, DataTransfer::ofShort); return this; } @Override - public ShortNdArray write(ShortDataBuffer src) { - Validator.writeFromBufferArgs(this, src); + public ShortNdArray copyFrom(ShortDataBuffer src) { + Validator.copyFromBufferArgs(this, src); DataTransfer.execute(src, buffer, dimensions(), DataTransfer::ofShort); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/BooleanSparseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/BooleanSparseNdArray.java index f5b984f..d5d8d72 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/BooleanSparseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/BooleanSparseNdArray.java @@ -124,7 +124,7 @@ protected BooleanSparseNdArray( BooleanDataBuffer dataBuffer, boolean defaultValue, DimensionalSpace dimensions) { super(defaultValue, dimensions); // use write to set up the indices and values - write(dataBuffer); + copyFrom(dataBuffer); } /** @@ -266,7 +266,7 @@ public static BooleanSparseNdArray create( */ public static BooleanSparseNdArray create(BooleanNdArray src) { BooleanDataBuffer buffer = DataBuffers.ofBooleans(src.size()); - src.read(buffer); + src.copyTo(buffer); return new BooleanSparseNdArray(buffer, DimensionalSpace.create(src.shape())); } /** @@ -278,7 +278,7 @@ public static BooleanSparseNdArray create(BooleanNdArray src) { */ public static BooleanSparseNdArray create(BooleanNdArray src, boolean defaultValue) { BooleanDataBuffer buffer = DataBuffers.ofBooleans(src.size()); - src.read(buffer); + src.copyTo(buffer); return new BooleanSparseNdArray(buffer, defaultValue, DimensionalSpace.create(src.shape())); } @@ -318,13 +318,13 @@ public BooleanNdArray setBoolean(boolean value, long... coordinates) { /** {@inheritDoc} */ @Override - public BooleanNdArray read(DataBuffer dst) { - return read((BooleanDataBuffer) dst); + public BooleanNdArray copyTo(DataBuffer dst) { + return copyTo((BooleanDataBuffer) dst); } /** {@inheritDoc} */ @Override - public BooleanNdArray read(BooleanDataBuffer dst) { + public BooleanNdArray copyTo(BooleanDataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Boolean[] defaults = new Boolean[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -344,7 +344,7 @@ public BooleanNdArray read(BooleanDataBuffer dst) { /** {@inheritDoc} */ @Override - public BooleanNdArray write(BooleanDataBuffer src) { + public BooleanNdArray copyFrom(BooleanDataBuffer src) { List indices = new ArrayList<>(); List values = new ArrayList<>(); @@ -368,8 +368,8 @@ public BooleanNdArray write(BooleanDataBuffer src) { /** {@inheritDoc} */ @Override - public BooleanNdArray write(DataBuffer src) { - return write((BooleanDataBuffer) src); + public BooleanNdArray copyFrom(DataBuffer src) { + return copyFrom((BooleanDataBuffer) src); } /** @@ -379,7 +379,7 @@ public BooleanNdArray write(DataBuffer src) { */ public BooleanNdArray toDense() { BooleanDataBuffer dataBuffer = DataBuffers.ofBooleans(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -391,8 +391,8 @@ public BooleanNdArray toDense() { */ public BooleanNdArray fromDense(BooleanNdArray src) { BooleanDataBuffer buffer = DataBuffers.ofBooleans(src.size()); - src.read(buffer); - write(buffer); + src.copyTo(buffer); + copyFrom(buffer); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ByteSparseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ByteSparseNdArray.java index 259aefe..633ca49 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ByteSparseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ByteSparseNdArray.java @@ -118,7 +118,7 @@ protected ByteSparseNdArray( ByteSparseNdArray(ByteDataBuffer dataBuffer, byte defaultValue, DimensionalSpace dimensions) { super(defaultValue, dimensions); // use write to set up the indices and values - write(dataBuffer); + copyFrom(dataBuffer); } /** @@ -255,7 +255,7 @@ public static ByteSparseNdArray create(ByteDataBuffer buffer, byte defaultValue, */ public static ByteSparseNdArray create(ByteNdArray src) { ByteDataBuffer buffer = DataBuffers.ofBytes(src.size()); - src.read(buffer); + src.copyTo(buffer); return new ByteSparseNdArray(buffer, DimensionalSpace.create(src.shape())); } @@ -268,7 +268,7 @@ public static ByteSparseNdArray create(ByteNdArray src) { */ public static ByteSparseNdArray create(ByteNdArray src, byte defaultValue) { ByteDataBuffer buffer = DataBuffers.ofBytes(src.size()); - src.read(buffer); + src.copyTo(buffer); return new ByteSparseNdArray(buffer, defaultValue, DimensionalSpace.create(src.shape())); } @@ -302,13 +302,13 @@ public ByteNdArray setByte(byte value, long... coordinates) { /** {@inheritDoc} */ @Override - public ByteNdArray read(DataBuffer dst) { - return read((ByteDataBuffer) dst); + public ByteNdArray copyTo(DataBuffer dst) { + return copyTo((ByteDataBuffer) dst); } /** {@inheritDoc} */ @Override - public ByteNdArray read(ByteDataBuffer dst) { + public ByteNdArray copyTo(ByteDataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Byte[] defaults = new Byte[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -328,7 +328,7 @@ public ByteNdArray read(ByteDataBuffer dst) { /** {@inheritDoc} */ @Override - public ByteNdArray write(ByteDataBuffer src) { + public ByteNdArray copyFrom(ByteDataBuffer src) { List indices = new ArrayList<>(); List values = new ArrayList<>(); @@ -352,8 +352,8 @@ public ByteNdArray write(ByteDataBuffer src) { /** {@inheritDoc} */ @Override - public ByteNdArray write(DataBuffer src) { - return write((ByteDataBuffer) src); + public ByteNdArray copyFrom(DataBuffer src) { + return copyFrom((ByteDataBuffer) src); } /** @@ -363,7 +363,7 @@ public ByteNdArray write(DataBuffer src) { */ public ByteNdArray toDense() { ByteDataBuffer dataBuffer = DataBuffers.ofBytes(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -375,8 +375,8 @@ public ByteNdArray toDense() { */ public ByteNdArray fromDense(ByteNdArray src) { ByteDataBuffer buffer = DataBuffers.ofBytes(src.size()); - src.read(buffer); - write(buffer); + src.copyTo(buffer); + copyFrom(buffer); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/DoubleSparseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/DoubleSparseNdArray.java index 07a6d2a..35b3541 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/DoubleSparseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/DoubleSparseNdArray.java @@ -118,7 +118,7 @@ protected DoubleSparseNdArray( DoubleDataBuffer dataBuffer, double defaultValue, DimensionalSpace dimensions) { super(defaultValue, dimensions); // use write to set up the indices and values - write(dataBuffer); + copyFrom(dataBuffer); } /** @@ -257,7 +257,7 @@ public static DoubleSparseNdArray create( */ public static DoubleSparseNdArray create(DoubleNdArray src) { DoubleDataBuffer buffer = DataBuffers.ofDoubles(src.size()); - src.read(buffer); + src.copyTo(buffer); return new DoubleSparseNdArray(buffer, DimensionalSpace.create(src.shape())); } /** @@ -269,7 +269,7 @@ public static DoubleSparseNdArray create(DoubleNdArray src) { */ public static DoubleSparseNdArray create(DoubleNdArray src, double defaultValue) { DoubleDataBuffer buffer = DataBuffers.ofDoubles(src.size()); - src.read(buffer); + src.copyTo(buffer); return new DoubleSparseNdArray(buffer, defaultValue, DimensionalSpace.create(src.shape())); } @@ -303,13 +303,13 @@ public DoubleNdArray setDouble(double value, long... coordinates) { /** {@inheritDoc} */ @Override - public DoubleNdArray read(DataBuffer dst) { - return read((DoubleDataBuffer) dst); + public DoubleNdArray copyTo(DataBuffer dst) { + return copyTo((DoubleDataBuffer) dst); } /** {@inheritDoc} */ @Override - public DoubleNdArray read(DoubleDataBuffer dst) { + public DoubleNdArray copyTo(DoubleDataBuffer dst) { // set buf to the default values, then overwrite with the indices/values. Double[] defaults = new Double[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -329,7 +329,7 @@ public DoubleNdArray read(DoubleDataBuffer dst) { /** {@inheritDoc} */ @Override - public DoubleNdArray write(DoubleDataBuffer src) { + public DoubleNdArray copyFrom(DoubleDataBuffer src) { List indices = new ArrayList<>(); List values = new ArrayList<>(); @@ -353,8 +353,8 @@ public DoubleNdArray write(DoubleDataBuffer src) { /** {@inheritDoc} */ @Override - public DoubleNdArray write(DataBuffer src) { - return write((DoubleDataBuffer) src); + public DoubleNdArray copyFrom(DataBuffer src) { + return copyFrom((DoubleDataBuffer) src); } /** @@ -364,7 +364,7 @@ public DoubleNdArray write(DataBuffer src) { */ public DoubleNdArray toDense() { DoubleDataBuffer dataBuffer = DataBuffers.ofDoubles(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -376,8 +376,8 @@ public DoubleNdArray toDense() { */ public DoubleNdArray fromDense(DoubleNdArray src) { DoubleDataBuffer buffer = DataBuffers.ofDoubles(src.size()); - src.read(buffer); - write(buffer); + src.copyTo(buffer); + copyFrom(buffer); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/FloatSparseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/FloatSparseNdArray.java index 9b224a0..88f34b1 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/FloatSparseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/FloatSparseNdArray.java @@ -118,7 +118,7 @@ protected FloatSparseNdArray( FloatSparseNdArray(FloatDataBuffer dataBuffer, float defaultValue, DimensionalSpace dimensions) { super(defaultValue, dimensions); // use write to set up the indices and values - write(dataBuffer); + copyFrom(dataBuffer); } /** @@ -255,7 +255,7 @@ public static FloatSparseNdArray create(FloatDataBuffer buffer, float defaultVal */ public static FloatSparseNdArray create(FloatNdArray src) { FloatDataBuffer buffer = DataBuffers.ofFloats(src.size()); - src.read(buffer); + src.copyTo(buffer); return new FloatSparseNdArray(buffer, DimensionalSpace.create(src.shape())); } /** @@ -267,7 +267,7 @@ public static FloatSparseNdArray create(FloatNdArray src) { */ public static FloatSparseNdArray create(FloatNdArray src, float defaultValue) { FloatDataBuffer buffer = DataBuffers.ofFloats(src.size()); - src.read(buffer); + src.copyTo(buffer); return new FloatSparseNdArray(buffer, defaultValue, DimensionalSpace.create(src.shape())); } @@ -301,13 +301,13 @@ public FloatNdArray setFloat(float value, long... coordinates) { /** {@inheritDoc} */ @Override - public FloatNdArray read(DataBuffer dst) { - return read((FloatDataBuffer) dst); + public FloatNdArray copyTo(DataBuffer dst) { + return copyTo((FloatDataBuffer) dst); } /** {@inheritDoc} */ @Override - public FloatNdArray read(FloatDataBuffer dst) { + public FloatNdArray copyTo(FloatDataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Float[] defaults = new Float[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -327,7 +327,7 @@ public FloatNdArray read(FloatDataBuffer dst) { /** {@inheritDoc} */ @Override - public FloatNdArray write(FloatDataBuffer src) { + public FloatNdArray copyFrom(FloatDataBuffer src) { List indices = new ArrayList<>(); List values = new ArrayList<>(); @@ -351,8 +351,8 @@ public FloatNdArray write(FloatDataBuffer src) { /** {@inheritDoc} */ @Override - public FloatNdArray write(DataBuffer src) { - return write((FloatDataBuffer) src); + public FloatNdArray copyFrom(DataBuffer src) { + return copyFrom((FloatDataBuffer) src); } /** @@ -362,7 +362,7 @@ public FloatNdArray write(DataBuffer src) { */ public FloatNdArray toDense() { FloatDataBuffer dataBuffer = DataBuffers.ofFloats(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -374,8 +374,8 @@ public FloatNdArray toDense() { */ public FloatNdArray fromDense(FloatNdArray src) { FloatDataBuffer buffer = DataBuffers.ofFloats(src.size()); - src.read(buffer); - write(buffer); + src.copyTo(buffer); + copyFrom(buffer); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/IntSparseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/IntSparseNdArray.java index 757363f..d79c441 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/IntSparseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/IntSparseNdArray.java @@ -116,7 +116,7 @@ protected IntSparseNdArray( IntSparseNdArray(IntDataBuffer dataBuffer, int defaultValue, DimensionalSpace dimensions) { super(defaultValue, dimensions); // use write to set up the indices and values - write(dataBuffer); + copyFrom(dataBuffer); } /** @@ -269,7 +269,7 @@ public static IntSparseNdArray create(IntDataBuffer buffer, int defaultValue, Sh */ public static IntSparseNdArray create(IntNdArray src) { IntDataBuffer buffer = DataBuffers.ofInts(src.size()); - src.read(buffer); + src.copyTo(buffer); return new IntSparseNdArray(buffer, DimensionalSpace.create(src.shape())); } @@ -282,7 +282,7 @@ public static IntSparseNdArray create(IntNdArray src) { */ public static IntSparseNdArray create(IntNdArray src, int defaultValue) { IntDataBuffer buffer = DataBuffers.ofInts(src.size()); - src.read(buffer); + src.copyTo(buffer); return new IntSparseNdArray(buffer, defaultValue, DimensionalSpace.create(src.shape())); } @@ -316,13 +316,13 @@ public IntNdArray setInt(int value, long... coordinates) { /** {@inheritDoc} */ @Override - public IntNdArray read(DataBuffer dst) { - return read((IntDataBuffer) dst); + public IntNdArray copyTo(DataBuffer dst) { + return copyTo((IntDataBuffer) dst); } /** {@inheritDoc} */ @Override - public IntNdArray read(IntDataBuffer dst) { + public IntNdArray copyTo(IntDataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Integer[] defaults = new Integer[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -342,7 +342,7 @@ public IntNdArray read(IntDataBuffer dst) { /** {@inheritDoc} */ @Override - public IntNdArray write(IntDataBuffer src) { + public IntNdArray copyFrom(IntDataBuffer src) { List indices = new ArrayList<>(); List values = new ArrayList<>(); @@ -366,8 +366,8 @@ public IntNdArray write(IntDataBuffer src) { /** {@inheritDoc} */ @Override - public IntNdArray write(DataBuffer src) { - return write((IntDataBuffer) src); + public IntNdArray copyFrom(DataBuffer src) { + return copyFrom((IntDataBuffer) src); } /** @@ -377,7 +377,7 @@ public IntNdArray write(DataBuffer src) { */ public IntNdArray toDense() { IntDataBuffer dataBuffer = DataBuffers.ofInts(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -389,8 +389,8 @@ public IntNdArray toDense() { */ public IntNdArray fromDense(IntNdArray src) { IntDataBuffer buffer = DataBuffers.ofInts(src.size()); - src.read(buffer); - write(buffer); + src.copyTo(buffer); + copyFrom(buffer); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/LongSparseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/LongSparseNdArray.java index 242ba50..1c01198 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/LongSparseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/LongSparseNdArray.java @@ -117,7 +117,7 @@ protected LongSparseNdArray( LongSparseNdArray(LongDataBuffer dataBuffer, long defaultValue, DimensionalSpace dimensions) { super(defaultValue, dimensions); // use write to set up the indices and values - write(dataBuffer); + copyFrom(dataBuffer); } /** @@ -254,7 +254,7 @@ public static LongSparseNdArray create(LongDataBuffer buffer, long defaultValue, */ public static LongSparseNdArray create(LongNdArray src) { LongDataBuffer buffer = DataBuffers.ofLongs(src.size()); - src.read(buffer); + src.copyTo(buffer); return new LongSparseNdArray(buffer, DimensionalSpace.create(src.shape())); } @@ -267,7 +267,7 @@ public static LongSparseNdArray create(LongNdArray src) { */ public static LongSparseNdArray create(LongNdArray src, long defaultValue) { LongDataBuffer buffer = DataBuffers.ofLongs(src.size()); - src.read(buffer); + src.copyTo(buffer); return new LongSparseNdArray(buffer, defaultValue, DimensionalSpace.create(src.shape())); } @@ -301,13 +301,13 @@ public LongNdArray setLong(long value, long... coordinates) { /** {@inheritDoc} */ @Override - public LongNdArray read(DataBuffer dst) { - return read((LongDataBuffer) dst); + public LongNdArray copyTo(DataBuffer dst) { + return copyTo((LongDataBuffer) dst); } /** {@inheritDoc} */ @Override - public LongNdArray read(LongDataBuffer dst) { + public LongNdArray copyTo(LongDataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Long[] defaults = new Long[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -327,7 +327,7 @@ public LongNdArray read(LongDataBuffer dst) { /** {@inheritDoc} */ @Override - public LongNdArray write(LongDataBuffer src) { + public LongNdArray copyFrom(LongDataBuffer src) { List indices = new ArrayList<>(); List values = new ArrayList<>(); @@ -351,8 +351,8 @@ public LongNdArray write(LongDataBuffer src) { /** {@inheritDoc} */ @Override - public LongNdArray write(DataBuffer src) { - return write((LongDataBuffer) src); + public LongNdArray copyFrom(DataBuffer src) { + return copyFrom((LongDataBuffer) src); } /** @@ -362,7 +362,7 @@ public LongNdArray write(DataBuffer src) { */ public LongNdArray toDense() { LongDataBuffer dataBuffer = DataBuffers.ofLongs(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -374,8 +374,8 @@ public LongNdArray toDense() { */ public LongNdArray fromDense(LongNdArray src) { LongDataBuffer buffer = DataBuffers.ofLongs(src.size()); - src.read(buffer); - write(buffer); + src.copyTo(buffer); + copyFrom(buffer); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ShortSparseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ShortSparseNdArray.java index 63dde22..051a7cb 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ShortSparseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/ShortSparseNdArray.java @@ -118,7 +118,7 @@ protected ShortSparseNdArray( ShortSparseNdArray(ShortDataBuffer dataBuffer, short defaultValue, DimensionalSpace dimensions) { super(defaultValue, dimensions); // use write to set up the indices and values - write(dataBuffer); + copyFrom(dataBuffer); } /** @@ -255,7 +255,7 @@ public static ShortSparseNdArray create(ShortDataBuffer buffer, short defaultVal */ public static ShortSparseNdArray create(ShortNdArray src) { ShortDataBuffer buffer = DataBuffers.ofShorts(src.size()); - src.read(buffer); + src.copyTo(buffer); return new ShortSparseNdArray(buffer, DimensionalSpace.create(src.shape())); } @@ -268,7 +268,7 @@ public static ShortSparseNdArray create(ShortNdArray src) { */ public static ShortSparseNdArray create(ShortNdArray src, short defaultValue) { ShortDataBuffer buffer = DataBuffers.ofShorts(src.size()); - src.read(buffer); + src.copyTo(buffer); return new ShortSparseNdArray(buffer, defaultValue, DimensionalSpace.create(src.shape())); } @@ -302,13 +302,13 @@ public ShortNdArray setShort(short value, long... coordinates) { /** {@inheritDoc} */ @Override - public ShortNdArray read(DataBuffer dst) { - return read((ShortDataBuffer) dst); + public ShortNdArray copyTo(DataBuffer dst) { + return copyTo((ShortDataBuffer) dst); } /** {@inheritDoc} */ @Override - public ShortNdArray read(ShortDataBuffer dst) { + public ShortNdArray copyTo(ShortDataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Short[] defaults = new Short[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -328,7 +328,7 @@ public ShortNdArray read(ShortDataBuffer dst) { /** {@inheritDoc} */ @Override - public ShortNdArray write(ShortDataBuffer src) { + public ShortNdArray copyFrom(ShortDataBuffer src) { List indices = new ArrayList<>(); List values = new ArrayList<>(); @@ -352,8 +352,8 @@ public ShortNdArray write(ShortDataBuffer src) { /** {@inheritDoc} */ @Override - public ShortNdArray write(DataBuffer src) { - return write((ShortDataBuffer) src); + public ShortNdArray copyFrom(DataBuffer src) { + return copyFrom((ShortDataBuffer) src); } /** @@ -363,7 +363,7 @@ public ShortNdArray write(DataBuffer src) { */ public ShortNdArray toDense() { ShortDataBuffer dataBuffer = DataBuffers.ofShorts(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -375,8 +375,8 @@ public ShortNdArray toDense() { */ public ShortNdArray fromDense(ShortNdArray src) { ShortDataBuffer buffer = DataBuffers.ofShorts(src.size()); - src.read(buffer); - write(buffer); + src.copyTo(buffer); + copyFrom(buffer); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/SparseNdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/SparseNdArray.java index 52b3867..c6d93f2 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/SparseNdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/SparseNdArray.java @@ -123,7 +123,7 @@ protected SparseNdArray( super(defaultValue, dimensions); this.type = type; // use write to set up the indices and values - write(dataBuffer); + copyFrom(dataBuffer); } /** @@ -266,7 +266,7 @@ public static > SparseNdArray create( */ public static > SparseNdArray create(Class type, U src) { DataBuffer buffer = DataBuffers.ofObjects(type, src.size()); - src.read(buffer); + src.copyTo(buffer); return new SparseNdArray<>(type, buffer, DimensionalSpace.create(src.shape())); } /** @@ -279,7 +279,7 @@ public static > SparseNdArray create(Class type public static > SparseNdArray create( Class type, U src, T defaultValue) { DataBuffer buffer = DataBuffers.ofObjects(type, src.size()); - src.read(buffer); + src.copyTo(buffer); return new SparseNdArray<>(type, buffer, defaultValue, DimensionalSpace.create(src.shape())); } @@ -312,7 +312,7 @@ public U slice(long position, DimensionalSpace sliceDimensions) { /** {@inheritDoc} */ @Override - public NdArray read(DataBuffer dst) { + public NdArray copyTo(DataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values @SuppressWarnings("unchecked") T[] defaults = (T[]) Array.newInstance(type, (int) dst.size()); @@ -336,7 +336,7 @@ public NdArray read(DataBuffer dst) { @SuppressWarnings({ "unchecked", }) - public NdArray write(DataBuffer src) { + public NdArray copyFrom(DataBuffer src) { List indices = new ArrayList<>(); List values = new ArrayList<>(); @@ -368,7 +368,7 @@ public NdArray write(DataBuffer src) { @SuppressWarnings("unchecked") public U toDense() { DataBuffer dataBuffer = DataBuffers.ofObjects(type, shape().size()); - read(dataBuffer); + copyTo(dataBuffer); // unchecked cast, suppressed. return (U) NdArrays.wrap(shape(), dataBuffer); } @@ -381,8 +381,8 @@ public U toDense() { */ public NdArray fromDense(NdArray src) { DataBuffer buffer = DataBuffers.ofObjects(type, src.size()); - src.read(buffer); - write(buffer); + src.copyTo(buffer); + copyFrom(buffer); return this; } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/BooleanSparseSlice.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/BooleanSparseSlice.java index 24283db..945ccdc 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/BooleanSparseSlice.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/BooleanSparseSlice.java @@ -49,7 +49,7 @@ public BooleanSparseSlice( @Override public BooleanNdArray toDense() { BooleanDataBuffer dataBuffer = DataBuffers.ofBooleans(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -75,7 +75,7 @@ public BooleanNdArray set(NdArray src, long... coordinates) { /** {@inheritDoc} */ @Override - public BooleanNdArray read(DataBuffer dst) { + public BooleanNdArray copyTo(DataBuffer dst) { // zero out buf. Boolean[] defaults = new Boolean[(int) shape().size()]; dst.write(defaults); @@ -93,17 +93,17 @@ public BooleanNdArray read(DataBuffer dst) { } @Override - public BooleanNdArray read(BooleanDataBuffer dst) { - return read((DataBuffer) dst); + public BooleanNdArray copyTo(BooleanDataBuffer dst) { + return copyTo((DataBuffer) dst); } @Override - public BooleanNdArray write(DataBuffer src) { + public BooleanNdArray copyFrom(DataBuffer src) { throw new ReadOnlyBufferException(); } @Override - public BooleanNdArray write(BooleanDataBuffer src) { + public BooleanNdArray copyFrom(BooleanDataBuffer src) { throw new ReadOnlyBufferException(); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ByteSparseSlice.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ByteSparseSlice.java index a8ced3b..35e33d9 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ByteSparseSlice.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ByteSparseSlice.java @@ -48,7 +48,7 @@ public ByteSparseSlice( @Override public ByteNdArray toDense() { ByteDataBuffer dataBuffer = DataBuffers.ofBytes(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -74,7 +74,7 @@ public ByteNdArray set(NdArray src, long... coordinates) { /** {@inheritDoc} */ @Override - public ByteNdArray read(DataBuffer dst) { + public ByteNdArray copyTo(DataBuffer dst) { // zero out buf. Byte[] defaults = new Byte[(int) shape().size()]; dst.write(defaults); @@ -92,17 +92,17 @@ public ByteNdArray read(DataBuffer dst) { } @Override - public ByteNdArray read(ByteDataBuffer dst) { - return read((DataBuffer) dst); + public ByteNdArray copyTo(ByteDataBuffer dst) { + return this.copyTo((DataBuffer) dst); } @Override - public ByteNdArray write(DataBuffer src) { + public ByteNdArray copyFrom(DataBuffer src) { throw new ReadOnlyBufferException(); } @Override - public ByteNdArray write(ByteDataBuffer src) { + public ByteNdArray copyFrom(ByteDataBuffer src) { throw new ReadOnlyBufferException(); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/DoubleSparseSlice.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/DoubleSparseSlice.java index 596be18..3f66308 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/DoubleSparseSlice.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/DoubleSparseSlice.java @@ -49,7 +49,7 @@ public DoubleSparseSlice( @Override public DoubleNdArray toDense() { DoubleDataBuffer dataBuffer = DataBuffers.ofDoubles(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -75,7 +75,7 @@ public DoubleNdArray set(NdArray src, long... coordinates) { /** {@inheritDoc} */ @Override - public DoubleNdArray read(DataBuffer dst) { + public DoubleNdArray copyTo(DataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Double[] defaults = new Double[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -94,17 +94,17 @@ public DoubleNdArray read(DataBuffer dst) { } @Override - public DoubleNdArray read(DoubleDataBuffer dst) { - return read((DataBuffer) dst); + public DoubleNdArray copyTo(DoubleDataBuffer dst) { + return this.copyTo((DataBuffer) dst); } @Override - public DoubleNdArray write(DataBuffer src) { + public DoubleNdArray copyFrom(DataBuffer src) { throw new ReadOnlyBufferException(); } @Override - public DoubleNdArray write(DoubleDataBuffer src) { + public DoubleNdArray copyFrom(DoubleDataBuffer src) { throw new ReadOnlyBufferException(); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/FloatSparseSlice.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/FloatSparseSlice.java index 5e6094d..8e2204d 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/FloatSparseSlice.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/FloatSparseSlice.java @@ -49,7 +49,7 @@ public FloatSparseSlice( @Override public FloatNdArray toDense() { FloatDataBuffer dataBuffer = DataBuffers.ofFloats(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -75,7 +75,7 @@ public FloatNdArray set(NdArray src, long... coordinates) { /** {@inheritDoc} */ @Override - public FloatNdArray read(DataBuffer dst) { + public FloatNdArray copyTo(DataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Float[] defaults = new Float[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -94,17 +94,17 @@ public FloatNdArray read(DataBuffer dst) { } @Override - public FloatNdArray read(FloatDataBuffer dst) { - return read((DataBuffer) dst); + public FloatNdArray copyTo(FloatDataBuffer dst) { + return this.copyTo((DataBuffer) dst); } @Override - public FloatNdArray write(DataBuffer src) { + public FloatNdArray copyFrom(DataBuffer src) { throw new ReadOnlyBufferException(); } @Override - public FloatNdArray write(FloatDataBuffer src) { + public FloatNdArray copyFrom(FloatDataBuffer src) { throw new ReadOnlyBufferException(); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/IntSparseSlice.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/IntSparseSlice.java index 067c64b..988551b 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/IntSparseSlice.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/IntSparseSlice.java @@ -49,7 +49,7 @@ public IntSparseSlice( @Override public IntNdArray toDense() { IntDataBuffer dataBuffer = DataBuffers.ofInts(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -75,7 +75,7 @@ public IntNdArray set(NdArray src, long... coordinates) { /** {@inheritDoc} */ @Override - public IntNdArray read(DataBuffer dst) { + public IntNdArray copyTo(DataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Integer[] defaults = new Integer[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -94,17 +94,17 @@ public IntNdArray read(DataBuffer dst) { } @Override - public IntNdArray read(IntDataBuffer dst) { - return read((DataBuffer) dst); + public IntNdArray copyTo(IntDataBuffer dst) { + return this.copyTo((DataBuffer) dst); } @Override - public IntNdArray write(DataBuffer src) { + public IntNdArray copyFrom(DataBuffer src) { throw new ReadOnlyBufferException(); } @Override - public IntNdArray write(IntDataBuffer src) { + public IntNdArray copyFrom(IntDataBuffer src) { throw new ReadOnlyBufferException(); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/LongSparseSlice.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/LongSparseSlice.java index ea182b7..0916293 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/LongSparseSlice.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/LongSparseSlice.java @@ -49,7 +49,7 @@ public LongSparseSlice( @Override public LongNdArray toDense() { LongDataBuffer dataBuffer = DataBuffers.ofLongs(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -75,7 +75,7 @@ public LongNdArray set(NdArray src, long... coordinates) { /** {@inheritDoc} */ @Override - public LongNdArray read(DataBuffer dst) { + public LongNdArray copyTo(DataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Long[] defaults = new Long[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -94,17 +94,17 @@ public LongNdArray read(DataBuffer dst) { } @Override - public LongNdArray read(LongDataBuffer dst) { - return read((DataBuffer) dst); + public LongNdArray copyTo(LongDataBuffer dst) { + return copyTo((DataBuffer) dst); } @Override - public LongNdArray write(DataBuffer src) { + public LongNdArray copyFrom(DataBuffer src) { throw new ReadOnlyBufferException(); } @Override - public LongNdArray write(LongDataBuffer src) { + public LongNdArray copyFrom(LongDataBuffer src) { throw new ReadOnlyBufferException(); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ObjectSparseSlice.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ObjectSparseSlice.java index be7f9f4..9f62bf8 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ObjectSparseSlice.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ObjectSparseSlice.java @@ -48,7 +48,7 @@ public ObjectSparseSlice( @SuppressWarnings("unchecked") public U toDense() { DataBuffer dataBuffer = DataBuffers.ofObjects(getType(), shape().size()); - read(dataBuffer); + copyTo(dataBuffer); // unchecked NdArray to U return (U) NdArrays.wrap(shape(), dataBuffer); } @@ -66,7 +66,7 @@ public U set(NdArray src, long... coordinates) { /** {@inheritDoc} */ @Override @SuppressWarnings("unchecked") - public U read(DataBuffer dst) { + public U copyTo(DataBuffer dst) { // unchecked Object to T[] T[] defaults = (T[]) Array.newInstance(getType(), (int) dst.size()); Arrays.fill(defaults, getDefaultValue()); diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ShortSparseSlice.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ShortSparseSlice.java index 16aa561..2da0f8c 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ShortSparseSlice.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/ShortSparseSlice.java @@ -49,7 +49,7 @@ public ShortSparseSlice( @Override public ShortNdArray toDense() { ShortDataBuffer dataBuffer = DataBuffers.ofShorts(shape().size()); - read(dataBuffer); + copyTo(dataBuffer); return NdArrays.wrap(shape(), dataBuffer); } @@ -75,7 +75,7 @@ public ShortNdArray set(NdArray src, long... coordinates) { /** {@inheritDoc} */ @Override - public ShortNdArray read(DataBuffer dst) { + public ShortNdArray copyTo(DataBuffer dst) { // set the values in buf to the default, then overwrite with indices/values Short[] defaults = new Short[(int) shape().size()]; Arrays.fill(defaults, getDefaultValue()); @@ -94,17 +94,17 @@ public ShortNdArray read(DataBuffer dst) { } @Override - public ShortNdArray read(ShortDataBuffer dst) { - return read((DataBuffer) dst); + public ShortNdArray copyTo(ShortDataBuffer dst) { + return this.copyTo((DataBuffer) dst); } @Override - public ShortNdArray write(DataBuffer src) { + public ShortNdArray copyFrom(DataBuffer src) { throw new ReadOnlyBufferException(); } @Override - public ShortNdArray write(ShortDataBuffer src) { + public ShortNdArray copyFrom(ShortDataBuffer src) { throw new ReadOnlyBufferException(); } diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/SparseSlice.java b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/SparseSlice.java index e0db839..3e5be6f 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/SparseSlice.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/impl/sparse/slice/SparseSlice.java @@ -133,7 +133,7 @@ public NdArraySequence elements(int dimensionIdx) { /** {@inheritDoc} */ @Override - public NdArray write(DataBuffer src) { + public NdArray copyFrom(DataBuffer src) { throw new ReadOnlyBufferException(); } diff --git a/ndarray/src/test/java/org/tensorflow/ndarray/NdArrayTestBase.java b/ndarray/src/test/java/org/tensorflow/ndarray/NdArrayTestBase.java index 577c2b7..36064d2 100644 --- a/ndarray/src/test/java/org/tensorflow/ndarray/NdArrayTestBase.java +++ b/ndarray/src/test/java/org/tensorflow/ndarray/NdArrayTestBase.java @@ -258,7 +258,7 @@ public void writeAndReadWithBuffers() { buffer.setObject(valueOf(val), val); } NdArray matrix = allocate(Shape.of(3, 5)); - matrix.write(buffer); + matrix.copyFrom(buffer); assertEquals(valueOf(0L), matrix.getObject(0, 0)); assertEquals(valueOf(4L), matrix.getObject(0, 4)); assertEquals(valueOf(5L), matrix.getObject(1, 0)); @@ -266,7 +266,7 @@ public void writeAndReadWithBuffers() { assertEquals(valueOf(14L), matrix.getObject(2, 4)); matrix.setObject(valueOf(100L), 1, 0); - matrix.read(buffer); + matrix.copyTo(buffer); assertEquals(valueOf(0L), buffer.getObject(0)); assertEquals(valueOf(4L), buffer.getObject(4)); assertEquals(valueOf(100L), buffer.getObject(5)); @@ -274,13 +274,13 @@ public void writeAndReadWithBuffers() { assertEquals(valueOf(14L), buffer.getObject(14)); try { - matrix.write(buffer.narrow(10)); + matrix.copyFrom(buffer.narrow(10)); fail(); } catch (BufferUnderflowException e) { // as expected } try { - matrix.read(buffer.narrow(10)); + matrix.copyTo(buffer.narrow(10)); fail(); } catch (BufferOverflowException e) { // as expected diff --git a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/BooleanSparseNdArrayTest.java b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/BooleanSparseNdArrayTest.java index bcb7235..ecd9e85 100644 --- a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/BooleanSparseNdArrayTest.java +++ b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/BooleanSparseNdArrayTest.java @@ -47,12 +47,12 @@ public void testBasic() { } @Test - public void testRead() { + public void testCopyToBuffer() { BooleanSparseNdArray instance = new BooleanSparseNdArray(indices, values, DimensionalSpace.create(shape)); BooleanDataBuffer dataBuffer = DataBuffers.ofBooleans(instance.shape().size()); - instance.read(dataBuffer); + instance.copyTo(dataBuffer); boolean[] array = new boolean[denseArray.length]; dataBuffer.read(array); @@ -60,12 +60,12 @@ public void testRead() { } @Test - public void testWrite() { + public void testCopyFromBuffer() { BooleanDataBuffer dataBuffer = RawDataBufferFactory.create(denseArray, false); // use a zero buffer BooleanSparseNdArray instance = BooleanSparseNdArray.create(DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -84,7 +84,7 @@ public void testWriteDefaultValue() { // use a zero buffer BooleanSparseNdArray instance = BooleanSparseNdArray.create(true, DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(valuesDefault, instance.getValues()); @@ -274,7 +274,7 @@ public void testCreate() { BooleanDataBuffer dataBuffer = RawDataBufferFactory.create(denseArray, false); // use a zero buffer BooleanSparseNdArray instanceB = BooleanSparseNdArray.create(DimensionalSpace.create(shape)); - instanceB.write(dataBuffer); + instanceB.copyFrom(dataBuffer); assertEquals(instance, instanceB); BooleanSparseNdArray instanceC = diff --git a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/ByteSparseNdArrayTest.java b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/ByteSparseNdArrayTest.java index 7dd9df2..efa0572 100644 --- a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/ByteSparseNdArrayTest.java +++ b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/ByteSparseNdArrayTest.java @@ -45,12 +45,12 @@ public void testBasic() { } @Test - public void testRead() { + public void testCopyToBuffer() { ByteSparseNdArray instance = new ByteSparseNdArray(indices, values, DimensionalSpace.create(shape)); ByteDataBuffer dataBuffer = DataBuffers.ofBytes(instance.shape().size()); - instance.read(dataBuffer); + instance.copyTo(dataBuffer); byte[] array = new byte[denseArray.length]; dataBuffer.read(array); @@ -58,12 +58,12 @@ public void testRead() { } @Test - public void testWrite() { + public void testCopyFromBuffer() { ByteDataBuffer dataBuffer = RawDataBufferFactory.create(denseArray, false); // use a zero buffer ByteSparseNdArray instance = ByteSparseNdArray.create(DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -80,7 +80,7 @@ public void testWriteDefaultValue() { // use a zero buffer ByteSparseNdArray instance = ByteSparseNdArray.create((byte) -1, DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -265,7 +265,7 @@ public void testCreate() { ByteDataBuffer dataBuffer = RawDataBufferFactory.create(denseArray, false); // use a zero buffer ByteSparseNdArray instanceB = ByteSparseNdArray.create(DimensionalSpace.create(shape)); - instanceB.write(dataBuffer); + instanceB.copyFrom(dataBuffer); assertEquals(instance, instanceB); ByteSparseNdArray instanceC = diff --git a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/DoubleSparseNdArrayTest.java b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/DoubleSparseNdArrayTest.java index 616863e..f7ff65f 100644 --- a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/DoubleSparseNdArrayTest.java +++ b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/DoubleSparseNdArrayTest.java @@ -49,12 +49,12 @@ public void testBasic() { } @Test - public void testRead() { + public void testCopyToBuffer() { DoubleSparseNdArray instance = new DoubleSparseNdArray(indices, values, DimensionalSpace.create(shape)); DoubleDataBuffer dataBuffer = DataBuffers.ofDoubles(instance.shape().size()); - instance.read(dataBuffer); + instance.copyTo(dataBuffer); double[] array = new double[denseArray.length]; dataBuffer.read(array); @@ -62,12 +62,12 @@ public void testRead() { } @Test - public void testWrite() { + public void testCopyFromBuffer() { DoubleDataBuffer dataBuffer = NioDataBufferFactory.create(DoubleBuffer.wrap(denseArray)); // use a zero buffer DoubleSparseNdArray instance = DoubleSparseNdArray.create(DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -80,7 +80,7 @@ public void testWriteDefaultValue() { DoubleDataBuffer dataBuffer = RawDataBufferFactory.create(denseArrayDefaultValue, false); // use a zero buffer DoubleSparseNdArray instance = DoubleSparseNdArray.create(-1d, DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -266,7 +266,7 @@ public void testCreate() { DoubleDataBuffer dataBuffer = RawDataBufferFactory.create(denseArray, false); // use a zero buffer DoubleSparseNdArray instanceB = DoubleSparseNdArray.create(DimensionalSpace.create(shape)); - instanceB.write(dataBuffer); + instanceB.copyFrom(dataBuffer); assertEquals(instance, instanceB); DoubleSparseNdArray instanceC = diff --git a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/FloatSparseNdArrayTest.java b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/FloatSparseNdArrayTest.java index f5f6ba4..d948d1e 100644 --- a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/FloatSparseNdArrayTest.java +++ b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/FloatSparseNdArrayTest.java @@ -46,12 +46,12 @@ public void testBasic() { } @Test - public void testRead() { + public void testCopyToBuffer() { FloatSparseNdArray instance = new FloatSparseNdArray(indices, values, DimensionalSpace.create(shape)); FloatDataBuffer dataBuffer = DataBuffers.ofFloats(instance.shape().size()); - instance.read(dataBuffer); + instance.copyTo(dataBuffer); float[] array = new float[denseArray.length]; dataBuffer.read(array); @@ -59,12 +59,12 @@ public void testRead() { } @Test - public void testWrite() { + public void testCopyFromBuffer() { FloatDataBuffer dataBuffer = NioDataBufferFactory.create(FloatBuffer.wrap(denseArray)); // use a zero buffer FloatSparseNdArray instance = FloatSparseNdArray.create(DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -80,7 +80,7 @@ public void testWriteDefaultValue() { FloatDataBuffer dataBuffer = RawDataBufferFactory.create(denseArrayDefaultValue, false); // use a zero buffer FloatSparseNdArray instance = FloatSparseNdArray.create(-1f, DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -274,7 +274,7 @@ public void testCreate() { FloatDataBuffer dataBuffer = RawDataBufferFactory.create(denseArray, false); // use a zero buffer FloatSparseNdArray instanceB = FloatSparseNdArray.create(DimensionalSpace.create(shape)); - instanceB.write(dataBuffer); + instanceB.copyFrom(dataBuffer); assertEquals(instance, instanceB); FloatSparseNdArray instanceC = diff --git a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/IntSparseNdArrayTest.java b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/IntSparseNdArrayTest.java index 8492493..b60b7db 100644 --- a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/IntSparseNdArrayTest.java +++ b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/IntSparseNdArrayTest.java @@ -47,12 +47,12 @@ public void testBasic() { } @Test - public void testRead() { + public void testCopyToBuffer() { IntSparseNdArray instance = new IntSparseNdArray(indices, values, DimensionalSpace.create(shape)); IntDataBuffer dataBuffer = DataBuffers.ofInts(instance.shape().size()); - instance.read(dataBuffer); + instance.copyTo(dataBuffer); int[] array = new int[denseArray.length]; dataBuffer.read(array); @@ -60,12 +60,12 @@ public void testRead() { } @Test - public void testWrite() { + public void testCopyFromBufferBuffer() { IntDataBuffer dataBuffer = NioDataBufferFactory.create(IntBuffer.wrap(denseArray)); // use a zero buffer IntSparseNdArray instance = IntSparseNdArray.create(DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -79,7 +79,7 @@ public void testWriteDefaultValue() { IntDataBuffer dataBuffer = RawDataBufferFactory.create(denseArrayDefaultValue, false); // use a zero buffer IntSparseNdArray instance = IntSparseNdArray.create(-1, DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -272,7 +272,7 @@ public void testCreate() { IntDataBuffer dataBuffer = RawDataBufferFactory.create(denseArray, false); // use a zero buffer IntSparseNdArray instanceB = IntSparseNdArray.create(DimensionalSpace.create(shape)); - instanceB.write(dataBuffer); + instanceB.copyFrom(dataBuffer); assertEquals(instance, instanceB); IntSparseNdArray instanceC = diff --git a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/LongSparseNdArrayTest.java b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/LongSparseNdArrayTest.java index 0a4b6c6..7f9a136 100644 --- a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/LongSparseNdArrayTest.java +++ b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/LongSparseNdArrayTest.java @@ -46,12 +46,12 @@ public void testBasic() { } @Test - public void testRead() { + public void testCopyToBuffer() { LongSparseNdArray instance = new LongSparseNdArray(indices, values, DimensionalSpace.create(shape)); LongDataBuffer dataBuffer = DataBuffers.ofLongs(instance.shape().size()); - instance.read(dataBuffer); + instance.copyTo(dataBuffer); long[] array = new long[denseArray.length]; dataBuffer.read(array); @@ -59,12 +59,12 @@ public void testRead() { } @Test - public void testWrite() { + public void testCopyFromBuffer() { LongDataBuffer dataBuffer = NioDataBufferFactory.create(LongBuffer.wrap(denseArray)); // use a zero buffer LongSparseNdArray instance = LongSparseNdArray.create(DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -78,7 +78,7 @@ public void testWriteDefaultValue() { LongDataBuffer dataBuffer = RawDataBufferFactory.create(denseArrayDefaultValue, false); // use a zero buffer LongSparseNdArray instance = LongSparseNdArray.create(-1L, DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -271,7 +271,7 @@ public void testCreate() { LongDataBuffer dataBuffer = RawDataBufferFactory.create(denseArray, false); // use a zero buffer LongSparseNdArray instanceB = LongSparseNdArray.create(DimensionalSpace.create(shape)); - instanceB.write(dataBuffer); + instanceB.copyFrom(dataBuffer); assertEquals(instance, instanceB); LongSparseNdArray instanceC = diff --git a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/ShortSparseNdArrayTest.java b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/ShortSparseNdArrayTest.java index cec1358..5f85413 100644 --- a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/ShortSparseNdArrayTest.java +++ b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/ShortSparseNdArrayTest.java @@ -45,12 +45,12 @@ public void testBasic() { } @Test - public void testRead() { + public void testCopyToBuffer() { ShortSparseNdArray instance = new ShortSparseNdArray(indices, values, DimensionalSpace.create(shape)); ShortDataBuffer dataBuffer = DataBuffers.ofShorts(instance.shape().size()); - instance.read(dataBuffer); + instance.copyTo(dataBuffer); short[] array = new short[denseArray.length]; dataBuffer.read(array); @@ -58,12 +58,12 @@ public void testRead() { } @Test - public void testWrite() { + public void testCopyFromBuffer() { ShortDataBuffer dataBuffer = NioDataBufferFactory.create(ShortBuffer.wrap(denseArray)); // use a zero buffer ShortSparseNdArray instance = ShortSparseNdArray.create(DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -81,7 +81,7 @@ public void testWriteDefaultValue() { // use a zero buffer ShortSparseNdArray instance = ShortSparseNdArray.create((short) -1, DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -275,7 +275,7 @@ public void testCreate() { ShortDataBuffer dataBuffer = RawDataBufferFactory.create(denseArray, false); // use a zero buffer ShortSparseNdArray instanceB = ShortSparseNdArray.create(DimensionalSpace.create(shape)); - instanceB.write(dataBuffer); + instanceB.copyFrom(dataBuffer); assertEquals(instance, instanceB); ShortSparseNdArray instanceC = diff --git a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/StringSparseNdArrayTest.java b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/StringSparseNdArrayTest.java index 152a13e..a93cd45 100644 --- a/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/StringSparseNdArrayTest.java +++ b/ndarray/src/test/java/org/tensorflow/ndarray/impl/sparse/StringSparseNdArrayTest.java @@ -64,12 +64,12 @@ public void testBasic() { } @Test - public void testRead() { + public void testCopyToBuffer() { SparseNdArray> instance = new SparseNdArray<>(String.class, indices, values, DimensionalSpace.create(shape)); DataBuffer dataBuffer = DataBuffers.ofObjects(String.class, instance.shape().size()); - instance.read(dataBuffer); + instance.copyTo(dataBuffer); String[] array = new String[denseArray.length]; dataBuffer.read(array); @@ -77,13 +77,13 @@ public void testRead() { } @Test - public void testWrite() { + public void testCopyFromBuffer() { DataBuffer dataBuffer = DataBuffers.ofObjects(denseArray); // use a zero buffer SparseNdArray> instance = SparseNdArray.create(String.class, DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -103,7 +103,7 @@ public void testWriteDefaultValue() { // use a zero buffer SparseNdArray> instance = SparseNdArray.create(String.class, defaultValue, DimensionalSpace.create(shape)); - instance.write(dataBuffer); + instance.copyFrom(dataBuffer); assertEquals(indices, instance.getIndices()); assertEquals(values, instance.getValues()); @@ -282,7 +282,7 @@ public void testCreate() { // use a zero buffer SparseNdArray> instanceB = SparseNdArray.create(String.class, DimensionalSpace.create(shape)); - instanceB.write(dataBuffer); + instanceB.copyFrom(dataBuffer); assertEquals(instance, instanceB); SparseNdArray> instanceC = From 24b2907c69ec6c298401f75439bbfe2de16fc6a6 Mon Sep 17 00:00:00 2001 From: Karl Lessard Date: Mon, 19 Feb 2024 09:08:53 -0500 Subject: [PATCH 2/2] Add version in name change notice --- ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java b/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java index c1da370..da34fd3 100644 --- a/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java +++ b/ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java @@ -291,7 +291,8 @@ default Stream streamOfObjects() { * 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. * - *

Note: this method was previously named `read(DataBuffer)`, which led to confusion. + *

Note: in version 0.4.0 and earlier, this method was named {@code read(DataBuffer)}. It has been renamed to + * explicitly indicate the direction of the data flow to avoid confusion. * * @param dst the destination buffer * @return this array @@ -307,7 +308,8 @@ default Stream streamOfObjects() { * 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. * - *

Note: this method was previously named `write(DataBuffer)`, which led to confusion. + *

Note: in version 0.4.0 and earlier, this method was named {@code write(DataBuffer)}. It has been renamed to + * explicitly indicate the direction of the data flow to avoid confusion. * * @param src the source buffer * @return this array