Computes the row-major (C-contiguous) byte-stride vector for a tensor with the given shape and element size.
The stride is built back-to-front: the innermost (last) axis has stride
elem_size, and each outer axis's stride is the product of the inner
stride and the inner dimension size. This matches NumPy's default
'C' order and is the layout expected by Apple Accelerate BLAS / vDSP
routines.
Math
See Also
TensorMeta::is_contiguous_for
Reverse check — verifies a stored stride against the canonical one.
Parameters
shapeShapeTarget shape. Empty shape yields an empty stride.
elem_sizestd::size_tElement size in bytes — typically obtained from
dtype_size.Returns
StrideVector of the same length as shape. When the result is fed back into TensorMeta, TensorImpl::is_contiguous returns true.
Examples
contiguous_stride({2, 3, 4}, 4) // {48, 16, 4} (float32)
contiguous_stride({}, 4) // {} (scalar)