Python wrappers
Public Python APIs implemented by this engine symbol.Autograd node for materialising a C-contiguous copy of a tensor.
Forward calls Dispatcher::contiguous, which copies non-contiguous data
into a freshly allocated, densely laid-out buffer. If the input is already
contiguous the backend may return the same storage without performing a
copy; the decision uses is_contiguous together with stride and offset
metadata. Backward is essentially pass-through: because gradients are
always dense, apply simply clones the gradient storage so upstream
nodes receive a concrete, owning buffer with the input shape and dtype.
Math
(identity on elements; the operation differs only in physical layout).
Shape
out.shape == in.shape exactly; only the stride and offset metadata
(and the underlying physical buffer) may change.
See Also
reshape_op — typically immediately follows contiguous_op.
Parameters
aTensorImplPtrAttributes
schema_v1OpSchema"contiguous", AmpPolicy::KeepInput, requires_grad=true.Notes
Required as a fast-path normalisation before any op that assumes
row-major storage (notably reshape_op and most MLX kernels).
The backward pass clones the dense gradient because the original input
could have had any layout — cloning guarantees the upstream gradient is
a concrete buffer regardless of the forward path taken.