pub struct TensorLayout {
pub strides: Option<Vec<i64>>,
pub format: MemoryFormat,
pub alignment: usize,
}Expand description
First-class strided layout for a value.
strides == None means “contiguous row-major for the value’s shape”; this
is the common case and avoids materializing strides for every value.
Fields§
§strides: Option<Vec<i64>>Physical strides in elements. None == contiguous row-major.
format: MemoryFormatMemory-format hint.
alignment: usizeRequired alignment in bytes for the backing allocation.
Implementations§
Source§impl TensorLayout
impl TensorLayout
Sourcepub fn contiguous() -> Self
pub fn contiguous() -> Self
A contiguous row-major layout (strides implied by shape).
Sourcepub fn strided(strides: Vec<i64>) -> Self
pub fn strided(strides: Vec<i64>) -> Self
A layout with explicit strides (marked MemoryFormat::Custom).
Sourcepub fn is_contiguous(&self, shape: &[usize]) -> bool
pub fn is_contiguous(&self, shape: &[usize]) -> bool
Whether this layout is contiguous row-major for shape.
Sourcepub fn resolved_strides(&self, shape: &[usize]) -> Vec<i64>
pub fn resolved_strides(&self, shape: &[usize]) -> Vec<i64>
The strides for shape under this layout, materializing the implied
contiguous strides when strides == None.
Sourcepub fn transpose(&self, shape: &[usize], perm: &[usize]) -> Self
pub fn transpose(&self, shape: &[usize], perm: &[usize]) -> Self
Reorder axes without copying data (a lazy transpose).
Sourcepub fn storage_size(&self, shape: &[usize], dtype: DataType) -> usize
pub fn storage_size(&self, shape: &[usize], dtype: DataType) -> usize
Total backing storage size in bytes: the largest byte offset reachable via the strides, plus one element. Handles negative strides.
Trait Implementations§
Source§impl Clone for TensorLayout
impl Clone for TensorLayout
Source§fn clone(&self) -> TensorLayout
fn clone(&self) -> TensorLayout
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more