tenzr::StridedLayout¶
#include <layout.h>
Public Functions¶
| Name | |
|---|---|
| StridedLayout() =default | |
| StridedLayout(Shape shape) | |
| StridedLayout(Shape shape, std::vector< int64_t > strides, int64_t offset =0) | |
| const Shape & | shape() const The layout's shape. |
| const std::vector< int64_t > & | Strides() const Per-dimension strides, in elements. |
| int64_t | Offset() const Base element offset of the view. |
| size_t | Rank() const Number of dimensions. |
| int64_t | Stride(size_t index) const Stride along dimension index. |
| int64_t | NumElements() const Total number of elements in the shaped view. |
| bool | IsContiguous() const Whether the view is densely packed. |
| bool | IsCContiguous() const Whether the view is C (row-major) contiguous. |
| bool | IsFContiguous() const Whether the view is Fortran (column-major) contiguous. |
| int64_t | LinearOffset(const std::vector< int64_t > & indices) const Flat element offset for multidimensional indices. |
| StridedLayout | Transpose(int64_t dim0 =-1, int64_t dim1 =-2) const View with dimensions dim0 and dim1 swapped. |
| StridedLayout | Permute(const std::vector< int64_t > & axes) const View with dimensions reordered by axes. |
| StridedLayout | Squeeze(std::optional< int64_t > dim =std::nullopt) const View with a length-1 dimension removed; dim selects one, nullopt removes all. |
| StridedLayout | Unsqueeze(int64_t dim) const View with a length-1 dimension inserted at dim. |
| StridedLayout | slice(const std::vector< Slice > & slices) const View restricted by per-axis slices. |
| StridedLayout | BroadcastTo(const Shape & target_shape) const View broadcast to target_shape. |
| std::string | ToString() const Human-readable layout description. |
Detailed Description¶
Strided view of a buffer: a Shape together with per-dimension element strides and a base element offset.
Public Functions Documentation¶
function StridedLayout¶
function StridedLayout¶
Parameters:
- shape Logical shape.
Build a C-contiguous layout for shape.
function StridedLayout¶
Parameters:
- shape Logical shape.
- strides Stride per dimension, which must match the rank.
- offset Element offset of the first logical element.
Build a layout with explicit strides and base offset.
function shape¶
The layout's shape.
function Strides¶
Per-dimension strides, in elements.
function Offset¶
Base element offset of the view.
function Rank¶
Number of dimensions.
function Stride¶
Stride along dimension index.
Parameters:
- index Zero-based dimension index.
Return: Stride in elements.
Stride of the given dimension.
function NumElements¶
Total number of elements in the shaped view.
function IsContiguous¶
Whether the view is densely packed.
Return: true for a contiguous layout.
Whether the layout is contiguous in any supported order (currently C-order).
function IsCContiguous¶
Whether the view is C (row-major) contiguous.
Return: true for a C-contiguous layout.
Whether the layout is C-contiguous (row-major, zero offset).
function IsFContiguous¶
Whether the view is Fortran (column-major) contiguous.
Return: true for an F-contiguous layout.
Whether the layout is Fortran-contiguous (column-major, zero offset).
function LinearOffset¶
Flat element offset for multidimensional indices.
Parameters:
- indices Per-dimension indices, which must match the rank.
Return: Flat element offset including the base offset.
Map multi-dimensional indices to a flat element offset.
function Transpose¶
View with dimensions dim0 and dim1 swapped.
Parameters:
- dim0 First dimension; negative values count from the end.
- dim1 Second dimension.
Return: Transposed layout sharing the same storage.
Swap two dimensions, producing a view.
function Permute¶
View with dimensions reordered by axes.
Parameters:
- axes Target position of each source dimension.
Return: Permuted layout sharing the same storage.
Reorder dimensions according to axes, producing a view.
function Squeeze¶
View with a length-1 dimension removed; dim selects one, nullopt removes all.
Parameters:
- dim Optional dimension to squeeze, which must have size 1.
Return: Squeezed view.
Remove a unit dimension (or all unit dimensions when dim is empty).
function Unsqueeze¶
View with a length-1 dimension inserted at dim.
Parameters:
- dim Position for the new dimension; negative values count from the end.
Return: Unsqueezed view.
Insert a unit dimension at dim.
function slice¶
View restricted by per-axis slices.
Parameters:
- slices Slice specification per dimension; trailing dimensions are kept whole.
Return: Sliced view.
Build a strided view for the given per-dimension slices.
function BroadcastTo¶
View broadcast to target_shape.
Parameters:
- target_shape Shape to broadcast to; rank must be >= the source rank.
Return: Broadcast view.
Broadcast to target_shape, setting stride 0 on expanded dimensions.
function ToString¶
Human-readable layout description.
Return: Human-readable layout description.
Render the shape, strides, and offset as a string.