pub struct Shape { /* private fields */ }
Expand description
A shape is a Slice
with labeled dimensions and a selection API.
Implementations§
Source§impl Shape
impl Shape
Sourcepub fn new(labels: Vec<String>, slice: Slice) -> Result<Self, ShapeError>
pub fn new(labels: Vec<String>, slice: Slice) -> Result<Self, ShapeError>
Creates a new shape with the provided labels, which describe the provided Slice.
Shapes can also be constructed by way of the [shape
] macro, which
creates a by-construction correct slice in row-major order given a set of
sized dimensions.
Sourcepub fn at(&self, label: &str, index: usize) -> Result<Self, ShapeError>
pub fn at(&self, label: &str, index: usize) -> Result<Self, ShapeError>
Select a single index along a named dimension, removing that dimension entirely. This reduces the dimensionality by 1. In effect it results in a cross section of the shape at the given index in the given dimension.
Sourcepub fn select<R: Into<Range>>(
&self,
label: &str,
range: R,
) -> Result<Self, ShapeError>
pub fn select<R: Into<Range>>( &self, label: &str, range: R, ) -> Result<Self, ShapeError>
Restrict this shape along a named dimension using a Range
.
The provided range must be nonempty.
select
is composable, it can be applied repeatedly, even on
the same dimension, to refine the view incrementally.
Sourcepub fn select_iter(&self, dims: usize) -> Result<SelectIterator<'_>, ShapeError>
pub fn select_iter(&self, dims: usize) -> Result<SelectIterator<'_>, ShapeError>
Produces an iterator over subshapes by fixing the first dims
dimensions.
For a shape of rank n
, this yields ∏ sizes[0..dims]
subshapes, each with the first dims
dimensions restricted to
size 1. The remaining dimensions are left unconstrained.
This is useful for structured traversal of slices within a
multidimensional shape. See SelectIterator
for details and
examples.
§Errors
Returns an error if dims == 0
or dims >= self.rank()
.
Sourcepub fn index(&self, indices: Vec<(String, usize)>) -> Result<Shape, ShapeError>
pub fn index(&self, indices: Vec<(String, usize)>) -> Result<Shape, ShapeError>
Sub-set this shape by select a particular row of the given indices The resulting shape will no longer have dimensions for the given indices Example shape.index(vec![(“gpu”, 3), (“host”, 0)])
Sourcepub fn coordinates(
&self,
rank: usize,
) -> Result<Vec<(String, usize)>, ShapeError>
pub fn coordinates( &self, rank: usize, ) -> Result<Vec<(String, usize)>, ShapeError>
Return a set of labeled coordinates for the given rank.
pub fn dim(&self, label: &str) -> Result<usize, ShapeError>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Shape
impl<'de> Deserialize<'de> for Shape
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl ReshapeShapeExt for Shape
impl ReshapeShapeExt for Shape
Source§fn reshape(&self, limit: Limit) -> ReshapedShape
fn reshape(&self, limit: Limit) -> ReshapedShape
impl StructuralPartialEq for Shape
Auto Trait Implementations§
impl Freeze for Shape
impl RefUnwindSafe for Shape
impl Send for Shape
impl Sync for Shape
impl Unpin for Shape
impl UnwindSafe for Shape
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§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>
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>
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