pub struct LayoutDescriptor {
pub shape: TensorShape,
pub strides: Vec<usize>,
pub byte_offset: usize,
pub element_size_bytes: usize,
pub order: LayoutOrder,
}Expand description
Complete memory layout descriptor for a tensor.
Fields§
§shape: TensorShapeLogical shape of the tensor.
strides: Vec<usize>Stride (in elements, not bytes) for each dimension.
byte_offset: usizeByte offset from the start of the backing buffer to element [0,…,0].
element_size_bytes: usizeSize of a single element in bytes (e.g. 4 for f32, 8 for f64).
order: LayoutOrderMemory ordering of this layout.
Implementations§
Source§impl LayoutDescriptor
impl LayoutDescriptor
Sourcepub fn row_major_strides(dims: &[usize]) -> Vec<usize>
pub fn row_major_strides(dims: &[usize]) -> Vec<usize>
Compute row-major (C-style) strides for dims.
The last dimension has stride 1; each preceding stride equals the
product of all following dimensions. For [3, 4, 5] the result is
[20, 5, 1].
Sourcepub fn col_major_strides(dims: &[usize]) -> Vec<usize>
pub fn col_major_strides(dims: &[usize]) -> Vec<usize>
Compute column-major (Fortran-style) strides for dims.
The first dimension has stride 1; each following stride equals the
product of all preceding dimensions. For [3, 4, 5] the result is
[1, 3, 12].
Sourcepub fn new(
shape: TensorShape,
order: LayoutOrder,
element_size_bytes: usize,
) -> Self
pub fn new( shape: TensorShape, order: LayoutOrder, element_size_bytes: usize, ) -> Self
Create a new layout descriptor.
Strides are computed from order; byte_offset starts at 0.
Sourcepub fn linear_index(&self, indices: &[usize]) -> Option<usize>
pub fn linear_index(&self, indices: &[usize]) -> Option<usize>
Compute the flat (linear) element index for the given multi-dimensional
indices.
Returns None when:
indices.len() != ndim, or- any
indices[i] >= shape.dims[i].
Sourcepub fn byte_offset_for(&self, indices: &[usize]) -> Option<usize>
pub fn byte_offset_for(&self, indices: &[usize]) -> Option<usize>
Compute the byte offset into the backing buffer for indices.
Returns None under the same conditions as linear_index.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Returns true if this layout has row-major (C-contiguous) strides.
Sourcepub fn total_bytes(&self) -> usize
pub fn total_bytes(&self) -> usize
Total bytes occupied by all elements.
Sourcepub fn transposed(&self) -> Self
pub fn transposed(&self) -> Self
Return a new LayoutDescriptor representing the transpose of this
layout.
Dimension and stride order are reversed; memory ordering is flipped
(RowMajor ↔ ColMajor).
Trait Implementations§
Source§impl Clone for LayoutDescriptor
impl Clone for LayoutDescriptor
Source§fn clone(&self) -> LayoutDescriptor
fn clone(&self) -> LayoutDescriptor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for LayoutDescriptor
impl RefUnwindSafe for LayoutDescriptor
impl Send for LayoutDescriptor
impl Sync for LayoutDescriptor
impl Unpin for LayoutDescriptor
impl UnsafeUnpin for LayoutDescriptor
impl UnwindSafe for LayoutDescriptor
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more