DynLayout

Struct DynLayout 

Source
pub struct DynLayout { /* 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 can be varied at runtime.

The layout specifies the size of each dimension of the tensor (the shape) and the stride (gap) between offsets in each dimension.

Implementations§

Trait Implementations§

Source§

impl<T: AsRef<[usize]>> AsIndex<DynLayout> for T

Source§

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

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

impl Clone for DynLayout

Source§

fn clone(&self) -> DynLayout

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 Debug for DynLayout

Source§

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

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

impl<L: Layout> From<&L> for DynLayout

Source§

fn from(layout: &L) -> DynLayout

Converts to this type from the input type.
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 Layout for DynLayout

Source§

fn len(&self) -> usize

Return the number of elements in the tensor shape described by this layout.

Source§

fn ndim(&self) -> usize

Return the number of dimensions.

Source§

fn shape(&self) -> &[usize]

Return the sizes of each dimension.

Source§

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

Returns the size of the dimension dim.

Source§

fn strides(&self) -> &[usize]

Return the stride (offset between elements) in the tensor’s element array.

Source§

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

Return the stride for a specific dimension.

Source§

type Index<'a> = &'a [usize]

Type used to represent indices. Read more
Source§

type Indices = DynIndices

Iterator over indices in this tensor.
Source§

fn offset(&self, index: Self::Index<'_>) -> 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 is_empty(&self) -> bool

Returns true if the array has no elements.
Source§

fn indices(&self) -> DynIndices

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

fn offset_unchecked(&self, index: Self::Index<'_>) -> 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

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 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 MutLayout for DynLayout

Source§

fn from_shape(shape: &[usize]) -> Self

Create a new contiguous layout with a given shape.
Source§

fn from_shape_and_strides( shape: &[usize], strides: &[usize], 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, order: &[usize]) -> DynLayout

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) -> DynLayout

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 PartialEq for DynLayout

Source§

fn eq(&self, other: &DynLayout) -> 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 ResizeLayout for DynLayout

Source§

fn insert_axis(&mut self, index: usize)

Insert a size-one axis at the given index in the shape. This will have the same stride as the dimension that follows it.
Source§

fn remove_axis_of_any_size(&mut self, index: usize)

Remove an axis that may have any size. Read more
Source§

fn merge_axes(&mut self)

Merge consecutive axes where possible. Read more
Source§

fn remove_axis(&mut self, index: usize)

Remove a size-1 axis at the given index. Read more
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 StructuralPartialEq for DynLayout

Source§

impl TrustedLayout for DynLayout

Auto Trait Implementations§

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.