Skip to content
fn

wrap_dim

int wrap_dim(int dim, int ndim, const char * op)

Resolve one signed dim against a tensor of rank ndim.

The rule every dim argument follows. A 0-d tensor answers to dim 0 and -1 as if it had one axis, as the reference does; the result is then 0 and names no real axis, so an op that indexes shape()[dim] must take the 0-d case apart first (ops/utils/ScalarAxis.h).

Raises

IndexError
dim falls outside [-max(ndim, 1), max(ndim, 1)).