Skip to main content

TensorLayout

Trait TensorLayout 

Source
pub trait TensorLayout {
    // Required methods
    fn shape(&self) -> &[usize];
    fn storage_extent(&self) -> usize;
}
Expand description

Interpretation metadata for a paired Storage buffer.

A TensorLayout describes how to read the flat buffer: the logical shape, and the number of element slots the buffer is expected to hold (see storage_extent). Concrete implementors carry additional flavor-specific metadata (memory order on DenseLayout; block structure, indices, and flux on BlockSparseLayout).

Required Methods§

Source

fn shape(&self) -> &[usize]

Logical shape of the tensor.

Source

fn storage_extent(&self) -> usize

Expected flat storage length for any compatible Storage.

For DenseLayout this equals shape().iter().product(); for BlockSparseLayout it equals the sum of allowed block sizes (strictly less than product(shape) when symmetry forbids blocks). This is the quantity checked by TensorData::new at the storage-layout boundary.

Logical / dense extent (always product(shape)) is computed at the call site from shape; it is intentionally not a method here so the two quantities are not silently conflated for BlockSparseLayout.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§