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§
Source§impl<const N: usize> NdLayout<N>
impl<const N: usize> NdLayout<N>
Sourcepub fn from_dyn(l: DynLayout) -> Self
pub fn from_dyn(l: DynLayout) -> Self
Convert a layout with dynamic rank to a layout with a static rank.
Panics if l does not have N dimensions.
Sourcepub fn index_valid(&self, index: [usize; N]) -> bool
pub fn index_valid(&self, index: [usize; N]) -> bool
Return true if all components of index are in-bounds.
Sourcepub fn contiguous_strides(shape: [usize; N]) -> [usize; N]
pub fn contiguous_strides(shape: [usize; N]) -> [usize; N]
Return the strides that a contiguous layout with a given shape would have.
Sourcepub fn from_shape(shape: [usize; N]) -> Self
pub fn from_shape(shape: [usize; N]) -> Self
Create a layout with a given shape and a contiguous layout.
Sourcepub fn try_from_shape_and_strides(
shape: [usize; N],
strides: [usize; N],
overlap: OverlapPolicy,
) -> Result<NdLayout<N>, FromDataError>
pub fn try_from_shape_and_strides( shape: [usize; N], strides: [usize; N], overlap: OverlapPolicy, ) -> Result<NdLayout<N>, FromDataError>
Create a layout with given shape and strides, intended for use with
data storage of length data_len.
overlap determines whether this method will fail if the layout
may have internal overlap.
Sourcepub fn broadcast<const M: usize>(&self, to_shape: [usize; M]) -> NdLayout<M>
pub fn broadcast<const M: usize>(&self, to_shape: [usize; M]) -> NdLayout<M>
Construct a layout which broadcasts elements to to_shape by setting
the stride to 0 in broadcasted dimensions.
Sourcepub fn permuted(&self, dims: [usize; N]) -> Self
pub fn permuted(&self, dims: [usize; N]) -> Self
Swap strides of this layout to put axes in the given order.
Values in dims must be < N.
Sourcepub fn transposed(&self) -> Self
pub fn transposed(&self) -> Self
Reverse the order of dimensions in this layout.
Sourcepub fn slice<const M: usize>(
&self,
range: &[SliceItem],
) -> Result<(Range<usize>, NdLayout<M>), SliceError>
pub fn slice<const M: usize>( &self, range: &[SliceItem], ) -> Result<(Range<usize>, NdLayout<M>), SliceError>
Compute the new layout and offset of the first element for a slice into an existing tensor view.
Returns a tuple of (offset_range, layout) for the sliced view.
pub fn resize_dim(&mut self, dim: usize, new_size: usize)
Trait Implementations§
Source§impl<const N: usize> Layout for NdLayout<N>
impl<const N: usize> Layout for NdLayout<N>
Source§fn try_offset(&self, index: [usize; N]) -> Option<usize>
fn try_offset(&self, index: [usize; N]) -> Option<usize>
None if the index is out
of bounds along any dimension.Source§fn offset_unchecked(&self, index: [usize; N]) -> usize
fn offset_unchecked(&self, index: [usize; N]) -> usize
Source§fn is_contiguous(&self) -> bool
fn is_contiguous(&self) -> bool
Source§fn is_broadcast(&self) -> bool
fn is_broadcast(&self) -> bool
Source§fn stride(&self, dim: usize) -> usize
fn stride(&self, dim: usize) -> usize
dim.Source§fn can_broadcast_to(&self, target_shape: &[usize]) -> bool
fn can_broadcast_to(&self, target_shape: &[usize]) -> bool
Source§fn can_broadcast_with(&self, shape: &[usize]) -> bool
fn can_broadcast_with(&self, shape: &[usize]) -> bool
shape as part of a binary operation. Read moreSource§fn min_data_len(&self) -> usize
fn min_data_len(&self) -> usize
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
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>
Source§fn move_axis(&mut self, from: usize, to: usize)
fn move_axis(&mut self, from: usize, to: usize)
from to to by swapping their strides.Source§fn permuted(&self, order: [usize; N]) -> NdLayout<N>
fn permuted(&self, order: [usize; N]) -> NdLayout<N>
fn resize_dim(&mut self, dim: usize, size: usize)
Source§fn transposed(&self) -> NdLayout<N>
fn transposed(&self) -> NdLayout<N>
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>
Source§fn slice_dyn(
&self,
range: &[SliceItem],
) -> Result<(Range<usize>, DynLayout), SliceError>
fn slice_dyn( &self, range: &[SliceItem], ) -> Result<(Range<usize>, DynLayout), SliceError>
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))
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,
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>
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>
shape.impl<const N: usize> Copy for NdLayout<N>
impl<const N: usize> StructuralPartialEq 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)