Skip to content
fn

index_select_op

→TensorImplPtr
int index_select_op(const int & a, int dim, const int & indices)

Python wrappers

Public Python APIs implemented by this engine symbol.

Pick indices.size slices along dim of a.

Composite over reshape_op + expand_op + gather_op. The 1-D index list is reshaped to rank a.ndim (size kk along dim, 1 elsewhere) and expanded to the source shape so gather_op's same-rank contract holds.

Math

For each output coordinate (…,j,…)(\ldots, j, \ldots) along dim:

y…,j,…=a…,idxj,… y_{\ldots, j, \ldots} = a_{\ldots, \mathrm{idx}_j, \ldots}

See Also

take_op — flat indexing; narrow_op — contiguous window.

Parameters

aTensorImplPtr
Source tensor of rank ≥1\ge 1.
dimint
Axis to index along. Negative values wrap modulo a.ndim.
indicesTensorImplPtr
1-D integer tensor (int32 or int64) of length kk.

Returns

TensorImplPtr

Tensor with the same shape as a except size kk along dim.

Raises

IndexError
If dim is out of range.
Failure
If indices is not 1-D or not an integer dtype.