Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for an arbitrary axis permutation with permutation .
The forward pass is a view — it does not copy data. The output
shares the input's underlying Storage and only rewrites its
shape and stride according to perm, paying an
bookkeeping cost. Materialising the permuted layout into contiguous
memory is the caller's responsibility (via a subsequent
contiguous() call), which keeps simple .T followed by
matmul free of redundant copies.
The backward is the same kind of operation in reverse: apply the
inverse permutation to grad_out so the gradient is reshuffled
back to the input's axis order.
Math
\qquad \frac{\partial L}{\partial x} = \mathrm{permute}\!\Bigl(\frac{\partial L}{\partial y}, p^{-1}\Bigr)$$ where $p^{-1}[p[i]] = i$ is the inverse permutation. **Shape** Output shape is `[input.shape[perm[0]], input.shape[perm[1]], …]`. `ndim` is preserved.Attributes
schema_v1OpSchema"permute", AmpPolicy::KeepInput — pure metadata operation, no promotion required.perm_std::vector<int>forward; used to derive the inverse permutation in apply.Raises
ValueErrorperm is not a permutation of 0..ndim-1 or its length differs from ndim.IndexErrorperm is outside [-ndim, ndim).Notes
Composability: a permute followed by another permute does not
materialise the intermediate layout; both forward passes rewrite
metadata only, so chains like a.T.contiguous() pay exactly one
data copy regardless of how many transposes precede the
contiguous call.
Static methods
1Normalise perm_user, build the output shape / stride, dispatch the (view-only) forward permute through the backend, and wire the backward node.
Parameters
aTensorImplPtrpermstd::vector<int>0..ndim-1. Negative indices are wrapped to axis + ndim before validation.Returns
TensorImplPtrOutput tensor sharing storage with a but with permuted shape and stride.
Raises
ValueErrorperm is not a valid permutation of 0..ndim-1.IndexErrorperm falls outside [-ndim, ndim).Methods
3Eager-mode backward: . out_shape_ is the permuted output shape, which becomes the input shape of the inverse permute call.
Graph-mode backward used when create_graph=True. Applies the inverse permutation through permute_op so the result remains tracked in the autograd graph for second-order differentiation.
Node-name override used by the autograd graph dumper.