Skip to main content

TensorDescriptor

Trait TensorDescriptor 

Source
pub trait TensorDescriptor: MemoryDescriptor {
    // Required methods
    fn shape(&self) -> &[usize];
    fn stride(&self) -> &[usize];
    fn element_size(&self) -> usize;
}
Expand description

A tensor is memory with shape, stride, and element size metadata.

This trait extends MemoryDescriptor with tensor-specific metadata. The underlying memory could be externally owned, self-owned, or a view.

§Shape and Stride

  • shape() returns the number of elements in each dimension
  • stride() returns the number of elements to skip when incrementing each dimension
  • element_size() returns the number of bytes per element

For a contiguous tensor with shape [2, 3, 4]:

  • stride would be [12, 4, 1] (row-major/C order)
  • total elements = 2 * 3 * 4 = 24
  • total bytes = 24 * element_size()

Required Methods§

Source

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

Shape of the tensor (number of elements per dimension).

Source

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

Stride of the tensor (elements to skip per dimension).

stride[i] indicates how many elements to skip when incrementing dimension i.

Source

fn element_size(&self) -> usize

Number of bytes per element.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl TensorDescriptor for Arc<dyn TensorDescriptor + Send + Sync>

Source§

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

Source§

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

Source§

fn element_size(&self) -> usize

Source§

impl TensorDescriptor for Arc<dyn TensorDescriptor>

Source§

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

Source§

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

Source§

fn element_size(&self) -> usize

Implementors§