Skip to content
fn

normalize_axes

→std::vector<int>
int normalize_axes(const int & axes, int ndim, const char * op)

Canonicalise a list of axis indices for an ndim-rank tensor.

Checks the list through distinct_dims, then sorts it ascending. When axes is empty the function treats the call as "reduce over everything" and returns [0, ndim). A 0-d tensor has no axis to reduce, so any accepted axis list comes back empty.

Parameters

axesconst std::vector<int>&
Raw axis list; may contain negatives.
ndimint
Rank of the tensor the axes refer to.
opconst char*
Op name the errors carry.

Returns

std::vector<int>

Sorted, all-positive axis list.

Raises

IndexError
Some entry of axes is refused by wrap_dim.
LucidError
Two entries name the same axis.