Module shape

Module shape 

Source
Expand description

Shape and Strides - Tensor Dimension Management

Provides types and functions for managing tensor shapes, strides, and broadcasting rules. Shapes define the dimensions of a tensor, while strides define how to traverse the underlying storage.

§Key Features

  • Efficient shape representation with small-vector optimization
  • Stride computation for contiguous and transposed layouts
  • Broadcasting support following NumPy rules
  • Shape validation and manipulation

@version 0.1.0 @author AutomataNexus Development Team

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.