Skip to content

Commit 369b05a

Browse files
authored
Rename read/write to copyTo/From (#19)
1 parent e9ff657 commit 369b05a

Some content is hidden

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

45 files changed

+270
-264
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ IntNdArray vector = matrix3d.get(0, 1);
7575
assertEquals(1, vector.rank());
7676

7777
// Rewriting the values of the vector using a primitive array
78-
vector.write(new int[] { 7, 8 });
78+
vector.copyFrom(DataBuffers.of(new int[] { 7, 8 }));
7979
assertEquals(7, matrix3d.getInt(0, 1, 0));
8080
assertEquals(8, matrix3d.getInt(0, 1, 1));
8181

ndarray/src/main/java/org/tensorflow/ndarray/BooleanNdArray.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ default BooleanNdArray setObject(Boolean value, long... coordinates) {
100100
BooleanNdArray copyTo(NdArray<Boolean> dst);
101101

102102
@Override
103-
BooleanNdArray read(DataBuffer<Boolean> dst);
103+
BooleanNdArray copyTo(DataBuffer<Boolean> dst);
104104

105-
BooleanNdArray read(BooleanDataBuffer dst);
105+
BooleanNdArray copyTo(BooleanDataBuffer dst);
106106

107107
@Override
108-
BooleanNdArray write(DataBuffer<Boolean> src);
108+
BooleanNdArray copyFrom(DataBuffer<Boolean> src);
109109

110-
BooleanNdArray write(BooleanDataBuffer src);
110+
BooleanNdArray copyFrom(BooleanDataBuffer src);
111111
}

ndarray/src/main/java/org/tensorflow/ndarray/ByteNdArray.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ default ByteNdArray setObject(Byte value, long... coordinates) {
100100
ByteNdArray copyTo(NdArray<Byte> dst);
101101

102102
@Override
103-
ByteNdArray read(DataBuffer<Byte> dst);
103+
ByteNdArray copyTo(DataBuffer<Byte> dst);
104104

105-
ByteNdArray read(ByteDataBuffer dst);
105+
ByteNdArray copyTo(ByteDataBuffer dst);
106106

107107
@Override
108-
ByteNdArray write(DataBuffer<Byte> src);
108+
ByteNdArray copyFrom(DataBuffer<Byte> src);
109109

110-
ByteNdArray write(ByteDataBuffer src);
110+
ByteNdArray copyFrom(ByteDataBuffer src);
111111
}

ndarray/src/main/java/org/tensorflow/ndarray/DoubleNdArray.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ default DoubleNdArray setObject(Double value, long... coordinates) {
115115
DoubleNdArray copyTo(NdArray<Double> dst);
116116

117117
@Override
118-
DoubleNdArray read(DataBuffer<Double> dst);
118+
DoubleNdArray copyTo(DataBuffer<Double> dst);
119119

120-
DoubleNdArray read(DoubleDataBuffer dst);
120+
DoubleNdArray copyTo(DoubleDataBuffer dst);
121121

122122
@Override
123-
DoubleNdArray write(DataBuffer<Double> src);
123+
DoubleNdArray copyFrom(DataBuffer<Double> src);
124124

125-
DoubleNdArray write(DoubleDataBuffer src);
125+
DoubleNdArray copyFrom(DoubleDataBuffer src);
126126
}

ndarray/src/main/java/org/tensorflow/ndarray/FloatNdArray.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ default FloatNdArray setObject(Float value, long... coordinates) {
100100
FloatNdArray copyTo(NdArray<Float> dst);
101101

102102
@Override
103-
FloatNdArray read(DataBuffer<Float> dst);
103+
FloatNdArray copyTo(DataBuffer<Float> dst);
104104

105-
FloatNdArray read(FloatDataBuffer dst);
105+
FloatNdArray copyTo(FloatDataBuffer dst);
106106

107107
@Override
108-
FloatNdArray write(DataBuffer<Float> src);
108+
FloatNdArray copyFrom(DataBuffer<Float> src);
109109

110-
FloatNdArray write(FloatDataBuffer src);
110+
FloatNdArray copyFrom(FloatDataBuffer src);
111111
}

ndarray/src/main/java/org/tensorflow/ndarray/IntNdArray.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ default IntNdArray setObject(Integer value, long... coordinates) {
115115
IntNdArray copyTo(NdArray<Integer> dst);
116116

117117
@Override
118-
IntNdArray read(DataBuffer<Integer> dst);
118+
IntNdArray copyTo(DataBuffer<Integer> dst);
119119

120-
IntNdArray read(IntDataBuffer dst);
120+
IntNdArray copyTo(IntDataBuffer dst);
121121

122122
@Override
123-
IntNdArray write(DataBuffer<Integer> src);
123+
IntNdArray copyFrom(DataBuffer<Integer> src);
124124

125-
IntNdArray write(IntDataBuffer src);
125+
IntNdArray copyFrom(IntDataBuffer src);
126126
}

ndarray/src/main/java/org/tensorflow/ndarray/LongNdArray.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ default LongNdArray setObject(Long value, long... coordinates) {
115115
LongNdArray copyTo(NdArray<Long> dst);
116116

117117
@Override
118-
LongNdArray read(DataBuffer<Long> dst);
118+
LongNdArray copyTo(DataBuffer<Long> dst);
119119

120-
LongNdArray read(LongDataBuffer dst);
120+
LongNdArray copyTo(LongDataBuffer dst);
121121

122122
@Override
123-
LongNdArray write(DataBuffer<Long> src);
123+
LongNdArray copyFrom(DataBuffer<Long> src);
124124

125-
LongNdArray write(LongDataBuffer src);
125+
LongNdArray copyFrom(LongDataBuffer src);
126126
}

ndarray/src/main/java/org/tensorflow/ndarray/NdArray.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,33 +285,39 @@ default Stream<T> streamOfObjects() {
285285
NdArray<T> copyTo(NdArray<T> dst);
286286

287287
/**
288-
* Read the content of this N-dimensional array into the destination buffer.
288+
* Copy the content of this N-dimensional array into the destination buffer.
289289
*
290290
* <p>The size of the buffer must be equal or greater to the {@link #size()} of this
291291
* array, or an exception is thrown. After the copy, content of the buffer and of the array can be
292292
* altered independently, without affecting each other.
293293
*
294+
* <p><i>Note: in version 0.4.0 and earlier, this method was named {@code read(DataBuffer<T>)}. It has been renamed to
295+
* explicitly indicate the direction of the data flow to avoid confusion.</i>
296+
*
294297
* @param dst the destination buffer
295298
* @return this array
296299
* @throws java.nio.BufferOverflowException if the buffer cannot hold the content of this array
297300
* @see DataBuffer#size()
298301
*/
299-
NdArray<T> read(DataBuffer<T> dst);
302+
NdArray<T> copyTo(DataBuffer<T> dst);
300303

301304
/**
302-
* Write the content of this N-dimensional array from the source buffer.
305+
* Copy the content of the source buffer into this N-dimensional array.
303306
*
304307
* <p>The size of the buffer must be equal or greater to the {@link #size()} of this
305308
* array, or an exception is thrown. After the copy, content of the buffer and of the array can be
306309
* altered independently, without affecting each other.
307310
*
311+
* <p><i>Note: in version 0.4.0 and earlier, this method was named {@code write(DataBuffer<T>)}. It has been renamed to
312+
* explicitly indicate the direction of the data flow to avoid confusion.</i>
313+
*
308314
* @param src the source buffer
309315
* @return this array
310316
* @throws java.nio.BufferUnderflowException if the buffer has not enough remaining data to write
311317
* into this array
312318
* @see DataBuffer#size()
313319
*/
314-
NdArray<T> write(DataBuffer<T> src);
320+
NdArray<T> copyFrom(DataBuffer<T> src);
315321

316322
/**
317323
* Checks equality between n-dimensional arrays.

ndarray/src/main/java/org/tensorflow/ndarray/ShortNdArray.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ default ShortNdArray setObject(Short value, long... coordinates) {
100100
ShortNdArray copyTo(NdArray<Short> dst);
101101

102102
@Override
103-
ShortNdArray read(DataBuffer<Short> dst);
103+
ShortNdArray copyTo(DataBuffer<Short> dst);
104104

105-
ShortNdArray read(ShortDataBuffer dst);
105+
ShortNdArray copyTo(ShortDataBuffer dst);
106106

107107
@Override
108-
ShortNdArray write(DataBuffer<Short> src);
108+
ShortNdArray copyFrom(DataBuffer<Short> src);
109109

110-
ShortNdArray write(ShortDataBuffer src);
110+
ShortNdArray copyFrom(ShortDataBuffer src);
111111
}

ndarray/src/main/java/org/tensorflow/ndarray/StdArrays.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ public static void copyFrom(IntNdArray src, int[] dst) {
20102010
if (src.size() > dst.length) {
20112011
throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
20122012
}
2013-
src.read(DataBuffers.of(dst, false, false));
2013+
src.copyTo(DataBuffers.of(dst, false, false));
20142014
}
20152015

20162016
/**
@@ -2113,7 +2113,7 @@ public static void copyFrom(LongNdArray src, long[] dst) {
21132113
if (src.size() > dst.length) {
21142114
throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
21152115
}
2116-
src.read(DataBuffers.of(dst, false, false));
2116+
src.copyTo(DataBuffers.of(dst, false, false));
21172117
}
21182118

21192119
/**
@@ -2216,7 +2216,7 @@ public static void copyFrom(FloatNdArray src, float[] dst) {
22162216
if (src.size() > dst.length) {
22172217
throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
22182218
}
2219-
src.read(DataBuffers.of(dst, false, false));
2219+
src.copyTo(DataBuffers.of(dst, false, false));
22202220
}
22212221

22222222
/**
@@ -2319,7 +2319,7 @@ public static void copyFrom(DoubleNdArray src, double[] dst) {
23192319
if (src.size() > dst.length) {
23202320
throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
23212321
}
2322-
src.read(DataBuffers.of(dst, false, false));
2322+
src.copyTo(DataBuffers.of(dst, false, false));
23232323
}
23242324

23252325
/**
@@ -2422,7 +2422,7 @@ public static void copyFrom(ByteNdArray src, byte[] dst) {
24222422
if (src.size() > dst.length) {
24232423
throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
24242424
}
2425-
src.read(DataBuffers.of(dst, false, false));
2425+
src.copyTo(DataBuffers.of(dst, false, false));
24262426
}
24272427

24282428
/**
@@ -2525,7 +2525,7 @@ public static void copyFrom(ShortNdArray src, short[] dst) {
25252525
if (src.size() > dst.length) {
25262526
throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
25272527
}
2528-
src.read(DataBuffers.of(dst, false, false));
2528+
src.copyTo(DataBuffers.of(dst, false, false));
25292529
}
25302530

25312531
/**
@@ -2628,7 +2628,7 @@ public static void copyFrom(BooleanNdArray src, boolean[] dst) {
26282628
if (src.size() > dst.length) {
26292629
throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
26302630
}
2631-
src.read(DataBuffers.of(dst, false, false));
2631+
src.copyTo(DataBuffers.of(dst, false, false));
26322632
}
26332633

26342634
/**
@@ -2732,7 +2732,7 @@ public static <T> void copyFrom(NdArray<T> src, T[] dst) {
27322732
if (src.size() > dst.length) {
27332733
throw new ArrayIndexOutOfBoundsException(String.valueOf(src.size()) + " > " + dst.length);
27342734
}
2735-
src.read(DataBuffers.of(dst, false, false));
2735+
src.copyTo(DataBuffers.of(dst, false, false));
27362736
}
27372737

27382738
/**

0 commit comments

Comments
 (0)