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 dimensionstride()returns the number of elements to skip when incrementing each dimensionelement_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§
Sourcefn stride(&self) -> &[usize]
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.
Sourcefn element_size(&self) -> usize
fn element_size(&self) -> usize
Number of bytes per element.