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§
Source§impl DynLayout
impl DynLayout
pub fn make_contiguous(&mut self)
Trait Implementations§
Source§impl Layout for DynLayout
impl Layout for DynLayout
Source§fn len(&self) -> usize
fn len(&self) -> usize
Return the number of elements in the tensor shape described by this layout.
Source§fn strides(&self) -> &[usize]
fn strides(&self) -> &[usize]
Return the stride (offset between elements) in the tensor’s element array.
Source§type Indices = DynIndices
type Indices = DynIndices
Iterator over indices in this tensor.
Source§fn offset(&self, index: Self::Index<'_>) -> Option<usize>
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 moreSource§fn indices(&self) -> DynIndices ⓘ
fn indices(&self) -> DynIndices ⓘ
Return an iterator over all valid indices in this tensor.
Source§fn offset_unchecked(&self, index: Self::Index<'_>) -> usize
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
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 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 MutLayout for DynLayout
impl MutLayout for DynLayout
Source§fn from_shape(shape: &[usize]) -> Self
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>
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)
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
fn permuted(&self, order: &[usize]) -> DynLayout
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) -> DynLayout
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>
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
.Source§impl ResizeLayout for DynLayout
impl ResizeLayout for DynLayout
Source§fn insert_axis(&mut self, index: usize)
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)
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)
fn merge_axes(&mut self)
Merge consecutive axes where possible. Read more
Source§fn remove_axis(&mut self, index: usize)
fn remove_axis(&mut self, index: usize)
Remove a size-1 axis at the given index. Read more
impl StructuralPartialEq for DynLayout
impl TrustedLayout for DynLayout
Auto Trait Implementations§
impl Freeze for DynLayout
impl RefUnwindSafe for DynLayout
impl Send for DynLayout
impl Sync for DynLayout
impl Unpin for DynLayout
impl UnwindSafe for DynLayout
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