pub struct MemoryLayout {
pub shape: Vec<usize>,
pub strides: Vec<isize>,
pub element_size: usize,
pub total_size: usize,
pub order: LayoutOrder,
pub is_contiguous: bool,
pub alignment: usize,
}Expand description
Memory layout information for arrays
Fields§
§shape: Vec<usize>Shape of the array
strides: Vec<isize>Strides for each dimension (in bytes)
element_size: usizeElement size in bytes
total_size: usizeTotal size in bytes
order: LayoutOrderLayout order
is_contiguous: boolWhether the layout is contiguous
alignment: usizeMemory alignment in bytes
Implementations§
Source§impl MemoryLayout
impl MemoryLayout
Sourcepub fn new_c_order(shape: &[usize]) -> Self
pub fn new_c_order(shape: &[usize]) -> Self
Create a new C-order (row-major) layout
Sourcepub fn new_f_order(shape: &[usize]) -> Self
pub fn new_f_order(shape: &[usize]) -> Self
Create a new F-order (column-major) layout
Sourcepub fn new_with_order(
shape: &[usize],
order: LayoutOrder,
element_size: usize,
alignment: usize,
) -> Self
pub fn new_with_order( shape: &[usize], order: LayoutOrder, element_size: usize, alignment: usize, ) -> Self
Create a new layout with specified order and element size
Sourcepub fn from_array<S, D>(array: &ArrayBase<S, D>) -> Self
pub fn from_array<S, D>(array: &ArrayBase<S, D>) -> Self
Create layout from existing array
Sourcepub fn calculate_strides(
shape: &[usize],
order: LayoutOrder,
element_size: usize,
) -> Vec<isize>
pub fn calculate_strides( shape: &[usize], order: LayoutOrder, element_size: usize, ) -> Vec<isize>
Calculate strides for given shape and order
Sourcepub fn is_c_contiguous(&self) -> bool
pub fn is_c_contiguous(&self) -> bool
Check if layout is C-contiguous
Sourcepub fn is_f_contiguous(&self) -> bool
pub fn is_f_contiguous(&self) -> bool
Check if layout is F-contiguous
Sourcepub fn to_order(&self, neworder: LayoutOrder) -> CoreResult<Self>
pub fn to_order(&self, neworder: LayoutOrder) -> CoreResult<Self>
Convert to different layout order
Sourcepub fn linear_index(&self, indices: &[usize]) -> CoreResult<usize>
pub fn linear_index(&self, indices: &[usize]) -> CoreResult<usize>
Get linear index for multi-dimensional indices
Sourcepub fn multi_indices(&self, linearidx: usize) -> CoreResult<Vec<usize>>
pub fn multi_indices(&self, linearidx: usize) -> CoreResult<Vec<usize>>
Get multi-dimensional indices for linear index
Sourcepub fn memory_offset(&self, indices: &[usize]) -> CoreResult<usize>
pub fn memory_offset(&self, indices: &[usize]) -> CoreResult<usize>
Calculate memory offset for given indices
Sourcepub fn is_compatible_with(&self, other: &MemoryLayout) -> bool
pub fn is_compatible_with(&self, other: &MemoryLayout) -> bool
Check if layout is compatible with another layout
Sourcepub fn transpose(&self, axes: Option<&[usize]>) -> CoreResult<Self>
pub fn transpose(&self, axes: Option<&[usize]>) -> CoreResult<Self>
Create a transposed layout
Sourcepub fn reshape(&self, newshape: &[usize]) -> CoreResult<Self>
pub fn reshape(&self, newshape: &[usize]) -> CoreResult<Self>
Reshape the layout to new shape
Sourcepub fn new_withshape_and_strides(
&self,
newshape: &[usize],
new_strides: Option<&[isize]>,
) -> CoreResult<Self>
pub fn new_withshape_and_strides( &self, newshape: &[usize], new_strides: Option<&[isize]>, ) -> CoreResult<Self>
Create a view with different shape (without copying data)
Trait Implementations§
Source§impl Clone for MemoryLayout
impl Clone for MemoryLayout
Source§fn clone(&self) -> MemoryLayout
fn clone(&self) -> MemoryLayout
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for MemoryLayout
impl RefUnwindSafe for MemoryLayout
impl Send for MemoryLayout
impl Sync for MemoryLayout
impl Unpin for MemoryLayout
impl UnwindSafe for MemoryLayout
Blanket Implementations§
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
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 moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.