Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename read/write to copyTo/From #19

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ default BooleanNdArray setObject(Boolean value, long... coordinates) {
BooleanNdArray copyTo(NdArray<Boolean> dst);

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

BooleanNdArray read(BooleanDataBuffer dst);
BooleanNdArray copyTo(BooleanDataBuffer dst);

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

BooleanNdArray write(BooleanDataBuffer src);
BooleanNdArray copyFrom(BooleanDataBuffer src);
}
8 changes: 4 additions & 4 deletions ndarray/src/main/java/org/tensorflow/ndarray/ByteNdArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ default ByteNdArray setObject(Byte value, long... coordinates) {
ByteNdArray copyTo(NdArray<Byte> dst);

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

ByteNdArray read(ByteDataBuffer dst);
ByteNdArray copyTo(ByteDataBuffer dst);

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

ByteNdArray write(ByteDataBuffer src);
ByteNdArray copyFrom(ByteDataBuffer src);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ default DoubleNdArray setObject(Double value, long... coordinates) {
DoubleNdArray copyTo(NdArray<Double> dst);

@Override
DoubleNdArray read(DataBuffer<Double> dst);
DoubleNdArray copyTo(DataBuffer<Double> dst);

DoubleNdArray read(DoubleDataBuffer dst);
DoubleNdArray copyTo(DoubleDataBuffer dst);

@Override
DoubleNdArray write(DataBuffer<Double> src);
DoubleNdArray copyFrom(DataBuffer<Double> src);

DoubleNdArray write(DoubleDataBuffer src);
DoubleNdArray copyFrom(DoubleDataBuffer src);
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ default FloatNdArray setObject(Float value, long... coordinates) {
FloatNdArray copyTo(NdArray<Float> dst);

@Override
FloatNdArray read(DataBuffer<Float> dst);
FloatNdArray copyTo(DataBuffer<Float> dst);

FloatNdArray read(FloatDataBuffer dst);
FloatNdArray copyTo(FloatDataBuffer dst);

@Override
FloatNdArray write(DataBuffer<Float> src);
FloatNdArray copyFrom(DataBuffer<Float> src);

FloatNdArray write(FloatDataBuffer src);
FloatNdArray copyFrom(FloatDataBuffer src);
}
8 changes: 4 additions & 4 deletions ndarray/src/main/java/org/tensorflow/ndarray/IntNdArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ default IntNdArray setObject(Integer value, long... coordinates) {
IntNdArray copyTo(NdArray<Integer> dst);

@Override
IntNdArray read(DataBuffer<Integer> dst);
IntNdArray copyTo(DataBuffer<Integer> dst);

IntNdArray read(IntDataBuffer dst);
IntNdArray copyTo(IntDataBuffer dst);

@Override
IntNdArray write(DataBuffer<Integer> src);
IntNdArray copyFrom(DataBuffer<Integer> src);

IntNdArray write(IntDataBuffer src);
IntNdArray copyFrom(IntDataBuffer src);
}
8 changes: 4 additions & 4 deletions ndarray/src/main/java/org/tensorflow/ndarray/LongNdArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ default LongNdArray setObject(Long value, long... coordinates) {
LongNdArray copyTo(NdArray<Long> dst);

@Override
LongNdArray read(DataBuffer<Long> dst);
LongNdArray copyTo(DataBuffer<Long> dst);

LongNdArray read(LongDataBuffer dst);
LongNdArray copyTo(LongDataBuffer dst);

@Override
LongNdArray write(DataBuffer<Long> src);
LongNdArray copyFrom(DataBuffer<Long> src);

LongNdArray write(LongDataBuffer src);
LongNdArray copyFrom(LongDataBuffer src);
}
14 changes: 10 additions & 4 deletions ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,33 +285,39 @@ default Stream<T> streamOfObjects() {
NdArray<T> copyTo(NdArray<T> 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.
*
* <p>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.
*
* <p><i>Note: in version 0.4.0 and earlier, this method was named {@code read(DataBuffer<T>)}. It has been renamed to
* explicitly indicate the direction of the data flow to avoid confusion.</i>
*
* @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<T> read(DataBuffer<T> dst);
NdArray<T> copyTo(DataBuffer<T> 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.
*
* <p>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.
*
* <p><i>Note: in version 0.4.0 and earlier, this method was named {@code write(DataBuffer<T>)}. It has been renamed to
* explicitly indicate the direction of the data flow to avoid confusion.</i>
*
* @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<T> write(DataBuffer<T> src);
NdArray<T> copyFrom(DataBuffer<T> src);

/**
* Checks equality between n-dimensional arrays.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ default ShortNdArray setObject(Short value, long... coordinates) {
ShortNdArray copyTo(NdArray<Short> dst);

@Override
ShortNdArray read(DataBuffer<Short> dst);
ShortNdArray copyTo(DataBuffer<Short> dst);

ShortNdArray read(ShortDataBuffer dst);
ShortNdArray copyTo(ShortDataBuffer dst);

@Override
ShortNdArray write(DataBuffer<Short> src);
ShortNdArray copyFrom(DataBuffer<Short> src);

ShortNdArray write(ShortDataBuffer src);
ShortNdArray copyFrom(ShortDataBuffer src);
}
16 changes: 8 additions & 8 deletions ndarray/src/main/java/org/tensorflow/ndarray/StdArrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -2732,7 +2732,7 @@ public static <T> void copyFrom(NdArray<T> 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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ public U setObject(T value, long... coords) {
}

@Override
public U read(DataBuffer<T> dst) {
Validator.readToBufferArgs(this, dst);
public U copyTo(DataBuffer<T> dst) {
Validator.copyToBufferArgs(this, dst);
DataTransfer.execute(buffer(), dimensions(), dst, DataTransfer::ofValue);
return (U)this;
}

@Override
public U write(DataBuffer<T> src) {
Validator.writeFromBufferArgs(this, src);
public U copyFrom(DataBuffer<T> src) {
Validator.copyFromBufferArgs(this, src);
DataTransfer.execute(src, buffer(), dimensions(), DataTransfer::ofValue);
return (U)this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public BooleanNdArray copyTo(NdArray<Boolean> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public ByteNdArray copyTo(NdArray<Byte> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public DoubleNdArray copyTo(NdArray<Double> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public FloatNdArray copyTo(NdArray<Float> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public IntNdArray copyTo(NdArray<Integer> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public LongNdArray copyTo(NdArray<Long> 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;
}
Expand Down
Loading
Loading