Expand description
Zero-copy, const-generic N-dimensional strided tensor view.
§Design
TensorView<'a, T, const N: usize> is a rank-N view over a borrowed slice.
Shape and strides are [usize; N] arrays resolved at compile time — the const
generic N is erased after monomorphization, leaving no runtime overhead vs.
a hand-written 2-D or 3-D struct.
§Layout Markers
Two zero-sized layout markers tag contiguous storage assumptions:
RowMajor— row-major (C-order) storage;strides[i] = ∏_{j>i} shape[j].ColMajor— column-major (Fortran-order) storage.
§Zero-Copy Contract
new(data, shape)— zero allocation; computes row-major strides from shape.with_strides(data, shape, strides)— zero allocation; caller supplies strides.row_view(i)— returns aTensorView<'_, T, {N-1}>sharing the same slice.reshape(new_shape)— returns a new view if the layout is contiguous; no copy.- All
get/iter_rowsoperations are also zero-copy.
§Module Structure
Re-exports§
pub use cow::TensorCow;pub use error::TensorError;pub use layout::ColMajor;pub use layout::Layout;pub use layout::RowMajor;pub use view::TensorView;
Modules§
- cow
- Clone-on-Write tensor container backed by
AlignedVec. - error
- Error type for tensor construction and indexing.
- layout
- Layout marker ZSTs and the sealed
Layouttrait. - view
- Zero-copy N-dimensional strided tensor view.