pub struct NdLayout<const N: usize> { /* private fields */ }
Expand description
Defines the valid indices for an N-dimensional array and how to map them to offsets in a linear buffer, where N is known at compile time.
Implementations§
Trait Implementations§
Source§impl<const N: usize> Layout for NdLayout<N>
impl<const N: usize> Layout for NdLayout<N>
Source§fn offset(&self, index: [usize; N]) -> Option<usize>
fn offset(&self, index: [usize; N]) -> Option<usize>
Map an index to a storage offset, or return
None
if the index is out
of bounds along any dimension. Read moreSource§fn offset_unchecked(&self, index: [usize; N]) -> usize
fn offset_unchecked(&self, index: [usize; N]) -> usize
Map an index to a storage offset, without checking if it is valid for
the tensor’s shape. Read more
Source§fn is_contiguous(&self) -> bool
fn is_contiguous(&self) -> bool
Return true if this layout describes a contiguous tensor, where the
logical order of elements matches the order in which they are stored.
Source§fn is_broadcast(&self) -> bool
fn is_broadcast(&self) -> bool
Return true if iterating over elements in this layout will visit
elements multiple times.
Source§fn stride(&self, dim: usize) -> usize
fn stride(&self, dim: usize) -> usize
Returns the offset between adjacent indices along dimension
dim
.Source§fn can_broadcast_to(&self, target_shape: &[usize]) -> bool
fn can_broadcast_to(&self, target_shape: &[usize]) -> bool
Return true if this layout’s shape can be broadcast to the given shape.
Source§fn can_broadcast_with(&self, shape: &[usize]) -> bool
fn can_broadcast_with(&self, shape: &[usize]) -> bool
Return true if the tensor/view can be broadcast with another tensor or
view with a given
shape
as part of a binary operation. Read moreSource§fn min_data_len(&self) -> usize
fn min_data_len(&self) -> usize
Return the minimum length required for the element data buffer used
with this layout.
Source§impl MatrixLayout for NdLayout<2>
impl MatrixLayout for NdLayout<2>
Source§impl<const N: usize> MutLayout for NdLayout<N>
impl<const N: usize> MutLayout for NdLayout<N>
Source§fn from_shape(shape: [usize; N]) -> Self
fn from_shape(shape: [usize; N]) -> Self
Create a new contiguous layout with a given shape.
Source§fn from_shape_and_strides(
shape: Self::Index<'_>,
strides: Self::Index<'_>,
overlap: OverlapPolicy,
) -> Result<Self, FromDataError>
fn from_shape_and_strides( shape: Self::Index<'_>, strides: Self::Index<'_>, overlap: OverlapPolicy, ) -> Result<Self, FromDataError>
Create a layout with custom strides. Read more
Source§fn move_axis(&mut self, from: usize, to: usize)
fn move_axis(&mut self, from: usize, to: usize)
Move the axis at position
from
to to
by swapping their strides.Source§fn permuted(&self, dims: [usize; N]) -> NdLayout<N>
fn permuted(&self, dims: [usize; N]) -> NdLayout<N>
Return a layout with the axes permuted according to the given order.
fn resize_dim(&mut self, dim: usize, size: usize)
Source§fn transposed(&self) -> NdLayout<N>
fn transposed(&self) -> NdLayout<N>
Reverse the order of dimensions. This is equivalent to
self.permuted([N-1, N-2, ... 0])
.Source§fn slice<const M: usize>(
&self,
range: &[SliceItem],
) -> Result<(Range<usize>, NdLayout<M>), SliceError>
fn slice<const M: usize>( &self, range: &[SliceItem], ) -> Result<(Range<usize>, NdLayout<M>), SliceError>
Slice the layout and return a static-rank layout. Read more
Source§fn slice_dyn(
&self,
range: &[SliceItem],
) -> Result<(Range<usize>, DynLayout), SliceError>
fn slice_dyn( &self, range: &[SliceItem], ) -> Result<(Range<usize>, DynLayout), SliceError>
Slice the layout and return a dynamic rank layout. Read more
Source§fn split(
&self,
axis: usize,
mid: usize,
) -> ((Range<usize>, Self), (Range<usize>, Self))
fn split( &self, axis: usize, mid: usize, ) -> ((Range<usize>, Self), (Range<usize>, Self))
Split the layout along the given axis into two. Read more
Source§fn index_axis(
&self,
axis: usize,
index: usize,
) -> (Range<usize>, <Self as RemoveDim>::Output)where
Self: RemoveDim,
fn index_axis(
&self,
axis: usize,
index: usize,
) -> (Range<usize>, <Self as RemoveDim>::Output)where
Self: RemoveDim,
Slice a layout by selecting a single entry from a given axis. Read more
Source§fn reshaped_for_view<S: IntoLayout>(
&self,
shape: S,
) -> Result<S::Layout, ReshapeError>
fn reshaped_for_view<S: IntoLayout>( &self, shape: S, ) -> Result<S::Layout, ReshapeError>
Return a new layout formed by reshaping this one to
shape
. Read moreSource§fn reshaped_for_copy<S: IntoLayout>(
&self,
shape: S,
) -> Result<S::Layout, ReshapeError>
fn reshaped_for_copy<S: IntoLayout>( &self, shape: S, ) -> Result<S::Layout, ReshapeError>
Return a new layout formed by reshaping this one to
shape
.impl<const N: usize> Copy for NdLayout<N>
impl<const N: usize> StructuralPartialEq for NdLayout<N>
impl<const N: usize> TrustedLayout for NdLayout<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for NdLayout<N>
impl<const N: usize> RefUnwindSafe for NdLayout<N>
impl<const N: usize> Send for NdLayout<N>
impl<const N: usize> Sync for NdLayout<N>
impl<const N: usize> Unpin for NdLayout<N>
impl<const N: usize> UnwindSafe for NdLayout<N>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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