Skip to content
fn

movedim_op

→TensorImplPtr
int movedim_op(const int & a, const int & source, const int & destination)

Python wrappers

Public Python APIs implemented by this engine symbol.

Move dimensions from source to destination positions.

Composite over permute_op. Builds an explicit permutation in which every axis listed in source is placed at the matching index in destination; axes not listed preserve their original relative order and fill the remaining slots left to right. No new backward node — gradient flows through PermuteBackward.

Math

If π\pi is the constructed permutation of [0,n)[0, n), then

yi0,…,in−1=aiπ(0),…,iπ(n−1) y_{i_0, \ldots, i_{n-1}} = a_{i_{\pi(0)}, \ldots, i_{\pi(n-1)}}

See Also

permute_op — underlying primitive.

Parameters

aTensorImplPtr
Source tensor.
sourcevector<int>
Axes of a to move. Negative values wrap modulo a.ndim. Must be unique.
destinationvector<int>
Target positions for the moved axes, parallel to source. Negative values wrap. Must be unique and have the same length as source.

Returns

TensorImplPtr

A view (or contiguous copy, per the primitive's policy) of a with the requested axis order.

Raises

Failure
If a is null, the lists differ in length, or either list contains duplicates.
IndexError
If any axis is out of range.

Examples

``movedim_op(a, {0}, {-1})`` moves the leading axis to the trailing
position — equivalent to a cyclic left rotation of axes.