Skip to main content

Module shape

Module shape 

Source
Expand description

Shape and Strides - Tensor Dimension Management

§File

crates/axonml-tensor/src/shape.rs

§Author

Andrew Jewell Sr - AutomataNexus

§Updated

March 8, 2026

§Disclaimer

Use at own risk. This software is provided “as is”, without warranty of any kind, express or implied. The author and AutomataNexus shall not be held liable for any damages arising from the use of this software.

Functions§

broadcast_shape
Computes the broadcast shape of two shapes.
broadcast_strides
Computes broadcast strides for a shape to match a target shape.
can_broadcast
Checks if two shapes are broadcastable.
contiguous_strides
Computes row-major (C-order) strides for a shape.
is_contiguous
Checks if strides represent a contiguous memory layout.
linear_index
Computes the linear index from multi-dimensional indices.
normalize_dim
Normalizes a dimension index, supporting negative indexing.
numel
Computes the total number of elements from a shape.
reshape
Reshapes a tensor shape, validating that total elements match.
squeeze
Computes the shape after squeezing (removing dimensions of size 1).
transpose_shape
Computes the shape after transposing dimensions.
transpose_strides
Swaps two stride values.
unravel_index
Converts a linear index to multi-dimensional indices.
unsqueeze
Computes the shape after unsqueezing (adding a dimension of size 1).
validate_indices
Validates that indices are within bounds for a shape.

Type Aliases§

Shape
Shape type - dimensions of a tensor. Uses SmallVec for stack allocation of small shapes (up to 6 dimensions).
Strides
Strides type - step sizes for each dimension.