Helper endpoint methods for Python like indexing.
See Also
Public Constructors
Public Methods
static <T extends TType> StridedSlice<T> | |
static <T extends TType> StridedSliceAssign<T> |
stridedSliceAssign(Scope scope, Operand<T> ref, Operand<T> value, Index... indices)
Assign `value` to the sliced l-value reference of `ref`.
|
Inherited Methods
Public Constructors
public StridedSliceHelper ()
Public Methods
public static StridedSlice<T> stridedSlice (Scope scope, Operand<T> input, Index... indices)
Return a strided slice from `input`.
The goal of this op is to produce a new tensor with a subset of the elements from the `n` dimensional `input` tensor. The subset is chosen using a sequence of `m` sparse range specifications encoded into the arguments of this function. Note, in some cases `m` could be equal to `n`, but this need not be the case. Each range specification entry can be one of the following:
- An ellipsis (...) using ellipsis()
. Ellipses are used to imply zero or more dimensions of
full-dimension selection. For example, stridedSlice(foo, Indices.ellipsis()
is the identity slice.
- A new axis using newAxis()
. This is used to insert a new shape=1 dimension.
For example, `stridedSlice(foo, Indices.newAxis())
where foo
is shape (3, 4)
produces a (1, 3, 4)
tensor.
- A range begin:end:stride
using slice(Long, Long, long)
Index.slice()} or all()
. This is used to specify
how much to choose from a given dimension. stride
can be any integer but 0. begin
is an integer which
represents the index of the first value to select while end
represents the index of the last value to select
(exclusive). Begin and end can be null, in which case the index begins or ends at the beginning or end of the dimension,
respectively (reversed if stride is negative). When both are null, slice()
is the same as all()
.
The number of values selected in each dimension is end - begin
if stride > 0
and begin - end
if stride < 0
. begin
and end
can be negative where -1
is the last element, -2
is the second to last. For example, given a shape (3,)
tensor stridedSlice(foo, Indices.all())
, the
effective begin
and end
are 0
and 3
. Do not assume this is equivalent to
stridedSlice(foo, Indices.slice(0, -1))
which has an effective begin
and end
of 0
and
2
. Another example is stridedSlice(foo, Indices.slice(-2, null, -1))
which reverses the first dimension
of a tensor while dropping the last two (in the original order elements). For example foo = [1,2,3,4];
stridedSlice(foo, Indices.slice(-2, null, -1)
is [4,3]
.
- A single index using at(long)
. This is used to keep only elements that have a given index. For
example (stridedSlice(foo, Indices.at(2))
on a shape (5,6)
tensor produces a shape (6,)
tensor.
The dimension can be kept with size one using at(long, boolean)
.
These semantics generally follow NumPy's indexing semantics, which can be found here: https://numpy.org/doc/stable/reference/arrays.indexing.html
Requirements: `0 != strides[i] for i in [0, m)` Only one ellipsis.
Parameters
scope | current scope |
---|---|
indices | The indices to slice. See Indices . |
Returns
- a new instance of StridedSlice
See Also
public static StridedSliceAssign<T> stridedSliceAssign (Scope scope, Operand<T> ref, Operand<T> value, Index... indices)
Assign `value` to the sliced l-value reference of `ref`.
The values of `value` are assigned to the positions in the variable `ref` that are selected by the slice parameters. The slice parameters `begin`, `end`, `strides`, etc. work exactly as in `StridedSlice`.
NOTE this op currently does not support broadcasting and so `value`'s shape must be exactly the shape produced by the slice of `ref`.
Parameters
scope | current scope |
---|---|
ref | the tensor to assign to. |
value | the value to assign. |
indices | The indices to slice. See Indices . |
Returns
- a new instance of StridedSliceAssign