Skip to main content

Module shape

Module shape 

Source
Expand description

Shape and stride metadata for multi-dimensional tensors.

A Shape is an ordered list of dimension extents (e.g. [3, 4] for a 3×4 matrix). A Strides is the corresponding list of byte-offsets (in elements, not bytes) that map a multi-index to a flat memory offset.

§Broadcasting

Following NumPy semantics, a dimension of size 1 can be broadcast against any larger dimension. The stride for that dimension is set to 0, so the same element is reused for every index along that axis without any copying.

§Row-major (C-order) layout

By default Shape::row_major_strides() computes C-order strides so that the last axis is contiguous. Column-major (Fortran/BLAS) strides can be constructed manually for interop with BLAS calls.

Structs§

Shape
Dimension extents for a tensor (e.g. [batch, rows, cols]).
Strides
Stride values (element-offset per index step) for each dimension.