Skip to content

Commit a6756a2

Browse files
committed
Javadocs cleanup, new names
Signed-off-by: Ryan Nett <[email protected]>
1 parent 2a962a8 commit a6756a2

File tree

8 files changed

+107
-90
lines changed

8 files changed

+107
-90
lines changed

ndarray/src/main/java/org/tensorflow/ndarray/index/At.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ public long end() {
6464
return coord + 1;
6565
}
6666

67-
@Override
68-
public boolean shrinkAxisMask() {
69-
return !keepDim;
70-
}
71-
7267
@Override
7368
public String toString() {
7469
return new StringJoiner(", ", At.class.getSimpleName() + "(", ")")

ndarray/src/main/java/org/tensorflow/ndarray/index/Ellipsis.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ public boolean isEllipsis() {
4141
return true;
4242
}
4343

44-
@Override
45-
public boolean ellipsisMask() {
46-
return true;
47-
}
48-
4944
@Override
5045
public String toString() {
5146
return Ellipsis.class.getSimpleName() + "()";

ndarray/src/main/java/org/tensorflow/ndarray/index/Indices.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public static Index step(long stepLength) {
197197
* @param start coordinate of the first element of the sequence
198198
* @return index
199199
*/
200-
public static Index from(long start) {
200+
public static Index sliceFrom(long start) {
201201
return slice(start, null);
202202
}
203203

@@ -211,10 +211,42 @@ public static Index from(long start) {
211211
* @param end coordinate of the last element of the sequence (exclusive)
212212
* @return index
213213
*/
214-
public static Index to(long end) {
214+
public static Index sliceTo(long end) {
215215
return slice(null, end);
216216
}
217217

218+
/**
219+
* An index that returns only elements on a given dimension starting at a
220+
* specific coordinate, using the given stride.
221+
*
222+
* <p>For example, given a vector with {@code n} elements on the {@code x} axis, and {@code n > k},
223+
* {@code from(k)} returns x<sub>k</sub>, x<sub>k+1</sub>, ..., x<sub>n-1</sub>
224+
*
225+
* @param start coordinate of the first element of the sequence
226+
* @param stride the stride to use
227+
* @return index
228+
* @see #slice(long, long, long)
229+
*/
230+
public static Index sliceFrom(long start, long stride) {
231+
return slice(start, null, stride);
232+
}
233+
234+
/**
235+
* An index that returns only elements on a given dimension up to a
236+
* specific coordinate, using the given stride.
237+
*
238+
* <p>For example, given a vector with {@code n} elements on the {@code x} axis, and {@code n > k},
239+
* {@code to(k)} returns x<sub>0</sub>, x<sub>1</sub>, ..., x<sub>k</sub>
240+
*
241+
* @param end coordinate of the last element of the sequence (exclusive)
242+
* @param stride the stride to use
243+
* @return index
244+
* @see #slice(long, long, long)
245+
*/
246+
public static Index sliceTo(long end, long stride) {
247+
return slice(null, end, stride);
248+
}
249+
218250
/**
219251
* An index that returns only elements on a given dimension between two coordinates.
220252
*

ndarray/src/main/java/org/tensorflow/ndarray/index/NewAxis.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ public boolean isNewAxis() {
4646
return true;
4747
}
4848

49-
@Override
50-
public boolean newAxisMask() {
51-
return true;
52-
}
53-
5449
@Override
5550
public String toString() {
5651
return NewAxis.class.getSimpleName() + "()";

ndarray/src/test/java/org/tensorflow/ndarray/NdArrayTestBase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import static org.tensorflow.ndarray.index.Indices.at;
2525
import static org.tensorflow.ndarray.index.Indices.even;
2626
import static org.tensorflow.ndarray.index.Indices.flip;
27-
import static org.tensorflow.ndarray.index.Indices.from;
27+
import static org.tensorflow.ndarray.index.Indices.sliceFrom;
2828
import static org.tensorflow.ndarray.index.Indices.odd;
2929
import static org.tensorflow.ndarray.index.Indices.range;
3030
import static org.tensorflow.ndarray.index.Indices.seq;
31-
import static org.tensorflow.ndarray.index.Indices.to;
31+
import static org.tensorflow.ndarray.index.Indices.sliceTo;
3232

3333
import java.nio.BufferOverflowException;
3434
import java.nio.BufferUnderflowException;
@@ -212,13 +212,13 @@ public void slices() {
212212
assertEquals(val101, vector10_flip.getObject(3));
213213

214214
// Vector (1,0,[from 1]) from vector (1,0,*)
215-
NdArray<T> vector10_1toX = vector10X.slice(from(1));
215+
NdArray<T> vector10_1toX = vector10X.slice(sliceFrom(1));
216216
assertEquals(vector10_1toX.shape(), Shape.of(4));
217217
assertEquals(val101, vector10_1toX.getObject(0));
218218
assertEquals(val102, vector10_1toX.getObject(1));
219219

220220
// Vector (1,0,[to 1]) from vector (1,0,*)
221-
NdArray<T> vector10_Xto1 = vector10X.slice(to(2));
221+
NdArray<T> vector10_Xto1 = vector10X.slice(sliceTo(2));
222222
assertEquals(vector10_Xto1.shape(), Shape.of(2));
223223
assertEquals(val100, vector10_Xto1.getObject(0));
224224
assertEquals(val101, vector10_Xto1.getObject(1));

ndarray/src/test/java/org/tensorflow/ndarray/impl/dense/DenseNdArrayTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void equalsAndHashCodeOnSlices() {
4040
{{3, 4}, {6, 7}}
4141
});
4242

43-
assertTrue(vector1.equals(vector2.slice(Indices.from(2))));
43+
assertTrue(vector1.equals(vector2.slice(Indices.sliceFrom(2))));
4444
assertTrue(vector1.equals(matrix1.get(1)));
4545
assertTrue(vector1.equals(matrix2.get(1).slice(Indices.even())));
4646
assertTrue(matrix1.equals(matrix2.slice(Indices.all(), Indices.even())));

tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/Ops.java

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ public final class Ops {
349349

350350
public final SignalOps signal;
351351

352-
public final QuantizationOps quantization;
353-
354352
public final TrainOps train;
355353

354+
public final QuantizationOps quantization;
355+
356356
private final Scope scope;
357357

358358
private Ops(Scope scope) {
@@ -374,8 +374,8 @@ private Ops(Scope scope) {
374374
math = new MathOps(this);
375375
audio = new AudioOps(this);
376376
signal = new SignalOps(this);
377-
quantization = new QuantizationOps(this);
378377
train = new TrainOps(this);
378+
quantization = new QuantizationOps(this);
379379
}
380380

381381
/**
@@ -5905,51 +5905,46 @@ public <T extends TType> StopGradient<T> stopGradient(Operand<T> input) {
59055905

59065906
/**
59075907
* Return a strided slice from `input`.
5908-
* <p>
5909-
* The goal of this op is to produce a new tensor with a subset of
5910-
* the elements from the `n` dimensional `input` tensor. The subset is chosen using
5911-
* a sequence of `m` sparse range specifications encoded into the arguments
5912-
* of this function. Note, in some cases
5913-
* `m` could be equal to `n`, but this need not be the case. Each
5914-
* range specification entry can be one of the following:
5915-
* <p>
5916-
* - An ellipsis (...) using {@link Indices#ellipsis()}. Ellipses are used to imply zero or more
5917-
* dimensions of full-dimension selection and are produced using
5918-
* `ellipsis_mask`. For example, `foo[...]` is the identity slice.
5919-
* <p>
5920-
* - A new axis using {@link Indices#newAxis()}. This is used to insert a new shape=1 dimension and is
5921-
* produced using `new_axis_mask`. For example, `foo[:, ...]` where
5922-
* `foo` is shape `(3, 4)` produces a `(1, 3, 4)` tensor.
5923-
* <p>
5924-
* - A range `begin:end:stride` using {@link Indices#slice(Long, Long, long)} Index.slice()}. This is used to specify how much to choose from
5925-
* a given dimension. `stride` can be any integer but 0. `begin` is an integer
5926-
* which represents the index of the first value to select while `end` represents
5927-
* the index of the last value to select. The number of values selected in each
5928-
* dimension is `end - begin` if `stride > 0` and `begin - end` if `stride < 0`.
5929-
* `begin` and `end` can be negative where `-1` is the last element, `-2` is
5930-
* the second to last. `begin_mask` controls whether to replace the explicitly
5931-
* given `begin` with an implicit effective value of `0` if `stride > 0` and
5932-
* `-1` if `stride < 0`. `end_mask` is analogous but produces the number
5933-
* required to create the largest open interval. For example, given a shape
5934-
* `(3,)` tensor `foo[:]`, the effective `begin` and `end` are `0` and `3`. Do
5935-
* not assume this is equivalent to `foo[0:-1]` which has an effective `begin`
5936-
* and `end` of `0` and `2`. Another example is `foo[-2::-1]` which reverses the
5937-
* first dimension of a tensor while dropping the last two (in the original
5938-
* order elements). For example `foo = [1,2,3,4]; foo[-2::-1]` is `[4,3]`.
5939-
* <p>
5940-
* - A single index using {@link Indices#at(long)}. This is used to keep only elements that have a given
5941-
* index. For example (`foo[2, :]` on a shape `(5,6)` tensor produces a
5942-
* shape `(6,)` tensor. This is encoded in `begin` and `end` and
5943-
* `shrink_axis_mask`.
5944-
* <p>
5945-
*
5946-
* <i>Requirements</i>:
5947-
* `0 != strides[i] for i in [0, m)`
5948-
* Only one ellipsis.
5908+
* <p>
5909+
* The goal of this op is to produce a new tensor with a subset of the elements from the `n` dimensional `input`
5910+
* tensor. The subset is chosen using a sequence of `m` sparse range specifications encoded into the arguments of this
5911+
* function. Note, in some cases `m` could be equal to `n`, but this need not be the case. Each range specification
5912+
* entry can be one of the following:
5913+
* <p>
5914+
* - An ellipsis (...) using {@link Indices#ellipsis()}. Ellipses are used to imply zero or more dimensions of
5915+
* full-dimension selection. For example, {@code stridedSlice(foo, Indices.ellipsis()} is the identity slice.
5916+
* <p>
5917+
* - A new axis using {@link Indices#newAxis()}. This is used to insert a new shape=1 dimension.
5918+
* For example, `{@code stridedSlice(foo, Indices.newAxis())} where {@code foo} is shape {@code (3, 4)}
5919+
* produces a {@code (1, 3, 4)} tensor.
5920+
* <p>
5921+
* - A range {@code begin:end:stride} using {@link Indices#slice(Long, Long, long)} Index.slice()} or {@link Indices#all()}. This is used to specify
5922+
* how much to choose from a given dimension. {@code stride} can be any integer but 0. {@code begin} is an integer which
5923+
* represents the index of the first value to select while {@code end} represents the index of the last value to select
5924+
* (exclusive). Begin and end can be null, in which case the index begins or ends at the beginning or end of the dimension,
5925+
* respectively (reversed if stride is negative). When both are null, {@code slice()} is the same as {@code all()}.
5926+
* The number of values selected in each dimension is {@code end - begin} if {@code stride > 0} and {@code begin - end}
5927+
* if {@code stride < 0}. {@code begin} and {@code end} can be negative where {@code -1} is the last element, {@code -2}
5928+
* is the second to last. For example, given a shape {@code (3,)} tensor {@code stridedSlice(foo, Indices.all())}, the
5929+
* effective {@code begin} and {@code end} are {@code 0} and {@code 3}. Do not assume this is equivalent to
5930+
* {@code stridedSlice(foo, Indices.slice(0, -1))} which has an effective {@code begin} and {@code end} of {@code 0} and
5931+
* {@code 2}. Another example is {@code stridedSlice(foo, Indices.slice(-2, null, -1))} which reverses the first dimension
5932+
* of a tensor while dropping the last two (in the original order elements). For example {@code foo = [1,2,3,4];
5933+
* stridedSlice(foo, Indices.slice(-2, null, -1)} is {@code [4,3]}.
5934+
* <p>
5935+
* - A single index using {@link Indices#at(long)}. This is used to keep only elements that have a given index. For
5936+
* example ({@code stridedSlice(foo, Indices.at(2))} on a shape {@code (5,6)} tensor produces a shape {@code (6,)} tensor.
5937+
* The dimension can be kept with size one using {@link Indices#at(long, boolean)}.
5938+
* <p>
5939+
* These semantics generally follow NumPy's indexing semantics, which can be found here:
5940+
* <a href="https://numpy.org/doc/stable/reference/arrays.indexing.html">https://numpy.org/doc/stable/reference/arrays.indexing.html</a>
5941+
* <p>
5942+
*
5943+
* <i>Requirements</i>:
5944+
* `0 != strides[i] for i in [0, m)` Only one ellipsis.
59495945
*
59505946
* @param scope current scope
59515947
* @param <T> data type for {@code output()} output
5952-
* @param input
59535948
* @param indices The indices to slice. See {@link Indices}.
59545949
* @return a new instance of StridedSlice
59555950
* @see Indices
@@ -6072,13 +6067,12 @@ public <T extends TType, U extends TNumber> StridedSlice<T> stridedSlice(Operand
60726067

60736068
/**
60746069
* Assign `value` to the sliced l-value reference of `ref`.
6075-
* <p>
6076-
* The values of `value` are assigned to the positions in the variable
6077-
* `ref` that are selected by the slice parameters. The slice parameters
6078-
* `begin`, `end`, `strides`, etc. work exactly as in `StridedSlice`.
6079-
* <p>
6080-
* NOTE this op currently does not support broadcasting and so `value`'s
6081-
* shape must be exactly the shape produced by the slice of `ref`.
6070+
* <p>
6071+
* The values of `value` are assigned to the positions in the variable `ref` that are selected by the slice
6072+
* parameters. The slice parameters `begin`, `end`, `strides`, etc. work exactly as in `StridedSlice`.
6073+
* <p>
6074+
* NOTE this op currently does not support broadcasting and so `value`'s shape must be exactly the shape produced by
6075+
* the slice of `ref`.
60826076
*
60836077
* @param <T> data type for {@code outputRef()} output
60846078
* @param scope current scope

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/op/core/StridedSliceHelper.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -128,26 +128,32 @@ static StridedSliceArgs mergeIndexes(Index[] indices) {
128128
* entry can be one of the following:
129129
* <p>
130130
* - An ellipsis (...) using {@link Indices#ellipsis()}. Ellipses are used to imply zero or more dimensions of
131-
* full-dimension selection and are produced using `ellipsis_mask`. For example, `foo[...]` is the identity slice.
131+
* full-dimension selection. For example, {@code stridedSlice(foo, Indices.ellipsis()} is the identity slice.
132132
* <p>
133-
* - A new axis using {@link Indices#newAxis()}. This is used to insert a new shape=1 dimension and is produced using
134-
* `new_axis_mask`. For example, `foo[:, ...]` where `foo` is shape `(3, 4)` produces a `(1, 3, 4)` tensor.
133+
* - A new axis using {@link Indices#newAxis()}. This is used to insert a new shape=1 dimension.
134+
* For example, `{@code stridedSlice(foo, Indices.newAxis())} where {@code foo} is shape {@code (3, 4)}
135+
* produces a {@code (1, 3, 4)} tensor.
135136
* <p>
136-
* - A range `begin:end:stride` using {@link Indices#slice(Long, Long, long)} Index.slice()}. This is used to specify
137-
* how much to choose from a given dimension. `stride` can be any integer but 0. `begin` is an integer which
138-
* represents the index of the first value to select while `end` represents the index of the last value to select. The
139-
* number of values selected in each dimension is `end - begin` if `stride > 0` and `begin - end` if `stride < 0`.
140-
* `begin` and `end` can be negative where `-1` is the last element, `-2` is the second to last. `begin_mask` controls
141-
* whether to replace the explicitly given `begin` with an implicit effective value of `0` if `stride > 0` and `-1` if
142-
* `stride < 0`. `end_mask` is analogous but produces the number required to create the largest open interval. For
143-
* example, given a shape `(3,)` tensor `foo[:]`, the effective `begin` and `end` are `0` and `3`. Do not assume this
144-
* is equivalent to `foo[0:-1]` which has an effective `begin` and `end` of `0` and `2`. Another example is
145-
* `foo[-2::-1]` which reverses the first dimension of a tensor while dropping the last two (in the original order
146-
* elements). For example `foo = [1,2,3,4]; foo[-2::-1]` is `[4,3]`.
137+
* - A range {@code begin:end:stride} using {@link Indices#slice(Long, Long, long)} Index.slice()} or {@link Indices#all()}. This is used to specify
138+
* how much to choose from a given dimension. {@code stride} can be any integer but 0. {@code begin} is an integer which
139+
* represents the index of the first value to select while {@code end} represents the index of the last value to select
140+
* (exclusive). Begin and end can be null, in which case the index begins or ends at the beginning or end of the dimension,
141+
* respectively (reversed if stride is negative). When both are null, {@code slice()} is the same as {@code all()}.
142+
* The number of values selected in each dimension is {@code end - begin} if {@code stride > 0} and {@code begin - end}
143+
* if {@code stride < 0}. {@code begin} and {@code end} can be negative where {@code -1} is the last element, {@code -2}
144+
* is the second to last. For example, given a shape {@code (3,)} tensor {@code stridedSlice(foo, Indices.all())}, the
145+
* effective {@code begin} and {@code end} are {@code 0} and {@code 3}. Do not assume this is equivalent to
146+
* {@code stridedSlice(foo, Indices.slice(0, -1))} which has an effective {@code begin} and {@code end} of {@code 0} and
147+
* {@code 2}. Another example is {@code stridedSlice(foo, Indices.slice(-2, null, -1))} which reverses the first dimension
148+
* of a tensor while dropping the last two (in the original order elements). For example {@code foo = [1,2,3,4];
149+
* stridedSlice(foo, Indices.slice(-2, null, -1)} is {@code [4,3]}.
147150
* <p>
148151
* - A single index using {@link Indices#at(long)}. This is used to keep only elements that have a given index. For
149-
* example (`foo[2, :]` on a shape `(5,6)` tensor produces a shape `(6,)` tensor. This is encoded in `begin` and `end`
150-
* and `shrink_axis_mask`.
152+
* example ({@code stridedSlice(foo, Indices.at(2))} on a shape {@code (5,6)} tensor produces a shape {@code (6,)} tensor.
153+
* The dimension can be kept with size one using {@link Indices#at(long, boolean)}.
154+
* <p>
155+
* These semantics generally follow NumPy's indexing semantics, which can be found here:
156+
* <a href="https://numpy.org/doc/stable/reference/arrays.indexing.html">https://numpy.org/doc/stable/reference/arrays.indexing.html</a>
151157
* <p>
152158
*
153159
* <i>Requirements</i>:

0 commit comments

Comments
 (0)