NdLayout

Struct 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>

Source

pub fn as_dyn(&self) -> DynLayout

Convert this layout to one with a dynamic rank.

Trait Implementations§

Source§

impl AsIndex<NdLayout<1>> for usize

Source§

fn as_index(&self) -> [usize; 1]

Convert self into an index for use the layout L.
Source§

impl<const N: usize> AsIndex<NdLayout<N>> for [usize; N]

Source§

fn as_index(&self) -> [usize; N]

Convert self into an index for use the layout L.
Source§

impl<const N: usize> Clone for NdLayout<N>

Source§

fn clone(&self) -> NdLayout<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for NdLayout<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> From<NdLayout<N>> for DynLayout

Source§

fn from(value: NdLayout<N>) -> DynLayout

Converts to this type from the input type.
Source§

impl<const N: usize> Layout for NdLayout<N>

Source§

type Index<'a> = [usize; N]

Type used to represent indices. Read more
Source§

type Indices = NdIndices<N>

Iterator over indices in this tensor.
Source§

fn ndim(&self) -> usize

Return the number of dimensions.
Source§

fn len(&self) -> usize

Returns the number of elements in the array.
Source§

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 more
Source§

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 shape(&self) -> Self::Index<'_>

Returns an array of the sizes of each dimension.
Source§

fn strides(&self) -> Self::Index<'_>

Returns an array of the strides of each dimension.
Source§

fn indices(&self) -> Self::Indices

Return an iterator over all valid indices in this tensor.
Source§

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

Return true if iterating over elements in this layout will visit elements multiple times.
Source§

fn is_empty(&self) -> bool

Returns true if the array has no elements.
Source§

fn size(&self, dim: usize) -> usize

Returns the size of the dimension dim.
Source§

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

Return true if this layout’s shape can be broadcast to the given shape.
Source§

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 more
Source§

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>

Source§

fn rows(&self) -> usize

Source§

fn cols(&self) -> usize

Source§

fn row_stride(&self) -> usize

Source§

fn col_stride(&self) -> usize

Source§

impl<const N: usize> MutLayout for NdLayout<N>

Source§

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>

Create a layout with custom strides. Read more
Source§

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>

Return a layout with the axes permuted according to the given order.
Source§

fn resize_dim(&mut self, dim: usize, size: usize)

Source§

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>

Slice the layout and return a static-rank layout. Read more
Source§

fn slice_dyn( &self, range: &[SliceItem], ) -> Result<(Range<usize>, DynLayout), SliceError>

Slice the layout and return a dynamic rank layout. Read more
Source§

fn squeezed(&self) -> DynLayout

Return a layout with all size-one dimensions removed.
Source§

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,

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>

Return a new layout formed by reshaping this one to shape. Read more
Source§

fn reshaped_for_copy<S: IntoLayout>( &self, shape: S, ) -> Result<S::Layout, ReshapeError>

Return a new layout formed by reshaping this one to shape.
Source§

fn slice_axis( &self, axis: usize, range: Range<usize>, ) -> Result<(Range<usize>, Self), SliceError>

Slice the layout along a given axis. Read more
Source§

impl<const N: usize> PartialEq for NdLayout<N>

Source§

fn eq(&self, other: &NdLayout<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, const N: usize> TryFrom<&'a DynLayout> for NdLayout<N>

Source§

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.

Source§

type Error = DimensionError

The type returned in the event of a conversion error.
Source§

impl<const N: usize> Copy for NdLayout<N>

Source§

impl<const N: usize> StructuralPartialEq for NdLayout<N>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.