Skip to main content

Module tensor

Module tensor 

Source
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 a TensorView<'_, T, {N-1}> sharing the same slice.
  • reshape(new_shape) — returns a new view if the layout is contiguous; no copy.
  • All get / iter_rows operations are also zero-copy.

§Module Structure

Leaf moduleContents
layoutRowMajor, ColMajor ZSTs; sealed Layout trait
errorTensorError enum
viewTensorView core + rank_ops/simd_bridge leaves
cowTensorCow enum + all impl blocks
helpers (priv)row_major_strides, compute_offset

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 Layout trait.
view
Zero-copy N-dimensional strided tensor view.