wrap_axes_to_positive

Description

Wraps negative axis sizes to positive.

For example, If axes (1, 0, –2, –1) and rank 4 are passed to the call to wrap_axis_to_positive, axes (1, 0, 2, 3) is returned.

That is, for rank 4 with axes (1, 0, –2, –1), the negative axes –1 and –2 correspond to axis 3 and axis 2 respectively, counting backwards from the end.

Prototype

def wrap_axes_to_positive(axes, rank)

Parameters

Parameter

Description

axes

Axis or axis list to wrap.

rank

Rank of the shape.

If any element in axes is not within the range of [–rank, +rank), the following exception is thrown:

RuntimeError "Axis must between [-%d, %d)."

Returns

The result axes

Restrictions

None

Example

from tbe.common.utils import shape_util
axes = shape_util.wrap_axis_to_positive([-2, -1], 4)

Return: [2, 3].