Struct rten_tensor::NdLayout
source · 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],
) -> (Range<usize>, NdLayout<M>)
pub fn slice<const M: usize>( &self, range: &[SliceItem], ) -> (Range<usize>, NdLayout<M>)
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],
) -> (Range<usize>, NdLayout<M>)
fn slice<const M: usize>( &self, range: &[SliceItem], ) -> (Range<usize>, NdLayout<M>)
source§fn slice_dyn(&self, range: &[SliceItem]) -> (Range<usize>, DynLayout)
fn slice_dyn(&self, range: &[SliceItem]) -> (Range<usize>, DynLayout)
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 try_slice<R: IntoSliceItems>(
&self,
range: R,
) -> Result<(Range<usize>, DynLayout), SliceError>
fn try_slice<R: IntoSliceItems>( &self, range: R, ) -> Result<(Range<usize>, DynLayout), SliceError>
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.source§impl<'a, const N: usize> TryFrom<&'a DynLayout> for NdLayout<N>
impl<'a, const N: usize> TryFrom<&'a DynLayout> for NdLayout<N>
source§fn try_from(value: &'a DynLayout) -> Result<NdLayout<N>, DimensionError>
fn try_from(value: &'a DynLayout) -> Result<NdLayout<N>, DimensionError>
Convert a dynamic layout into a static layout with N dims. Fails if
value.ndim() != N.
§type Error = DimensionError
type Error = DimensionError
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)