Trait rten_tensor::MutLayout
source · pub trait MutLayout: Layout + Clone {
// Required methods
fn from_shape(shape: Self::Index<'_>) -> Self;
fn from_shape_and_strides(
shape: Self::Index<'_>,
strides: Self::Index<'_>,
overlap: OverlapPolicy
) -> Result<Self, FromDataError>;
fn move_axis(&mut self, from: usize, to: usize);
fn permuted(&self, order: Self::Index<'_>) -> Self;
fn resize_dim(&mut self, dim: usize, size: usize);
fn transposed(&self) -> Self;
fn slice<const M: usize>(
&self,
range: &[SliceItem]
) -> (Range<usize>, NdLayout<M>);
fn slice_dyn(&self, range: &[SliceItem]) -> (Range<usize>, DynLayout);
fn squeezed(&self) -> DynLayout;
fn try_slice<R: IntoSliceItems>(
&self,
range: R
) -> Result<(Range<usize>, DynLayout), SliceError>;
// Provided method
fn reshaped<S: IntoLayout>(&self, shape: S) -> S::Layout { ... }
}Expand description
MutLayout extends Layout with methods for creating, modifying and transforming layouts.
Required Methods§
sourcefn from_shape(shape: Self::Index<'_>) -> Self
fn from_shape(shape: Self::Index<'_>) -> Self
Create a new contiguous layout with a given shape.
sourcefn 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>
Create a layout with custom strides.
The strides specify the offset gap between successive entries along a
given axis. overlap controls whether the layout is allowed to map
multiple indices to the same element. This can be true for immutable
views, but must be false for tensors or views that are mutable.
sourcefn 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.
sourcefn permuted(&self, order: Self::Index<'_>) -> Self
fn permuted(&self, order: Self::Index<'_>) -> Self
Return a layout with the axes permuted according to the given order.
fn resize_dim(&mut self, dim: usize, size: usize)
sourcefn transposed(&self) -> Self
fn transposed(&self) -> Self
Reverse the order of dimensions. This is equivalent to
self.permuted([N-1, N-2, ... 0]).
sourcefn slice<const M: usize>(
&self,
range: &[SliceItem]
) -> (Range<usize>, NdLayout<M>)
fn slice<const M: usize>( &self, range: &[SliceItem] ) -> (Range<usize>, NdLayout<M>)
Slice the layout and return a static rank layout with M dimensions.
Provided Methods§
sourcefn reshaped<S: IntoLayout>(&self, shape: S) -> S::Layout
fn reshaped<S: IntoLayout>(&self, shape: S) -> S::Layout
Combine or split dimensions by reshaping the layout to a given shape.
This will fail if the layout is not contiguous.