Skip to content
fn

narrow_op

→TensorImplPtr
int narrow_op(const int & a, int dim, int start, int length)

Python wrappers

Public Python APIs implemented by this engine symbol.

Slice a contiguous window [start, start + length) along dim.

Composite over split_at_op. Returns the input unchanged when the window covers the full axis (zero-cost fast path). Gradient flows through SplitSliceBackward.

Math

y…,j,…=a…,j+start,…,0≤j<length y_{\ldots, j, \ldots} = a_{\ldots, j + \mathrm{start}, \ldots}, \qquad 0 \le j < \mathrm{length}

See Also

split_at_op — underlying primitive.

Parameters

aTensorImplPtr
Source tensor of rank ≥1\ge 1.
dimint
Axis to slice along. Negative values wrap modulo a.ndim.
startint64
Inclusive start index along dim. Must be non-negative.
lengthint64
Window length. Must satisfy start + length <= a.shape[dim].

Returns

TensorImplPtr

Tensor with the same shape as a except size length along dim. When the window covers the full axis, the input is returned by identity.

Raises

IndexError
If dim is out of range or the window falls outside a.