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<Shape, ShapeError>
pub fn new(labels: Vec<String>, slice: Slice) -> Result<Shape, 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<Shape, ShapeError>
pub fn at(&self, label: &str, index: usize) -> Result<Shape, 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>(&self, label: &str, range: R) -> Result<Shape, ShapeError>
pub fn select<R>(&self, label: &str, range: R) -> Result<Shape, 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<Shape, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Shape, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Named for Shape
impl Named for Shape
Source§fn typename() -> &'static str
fn typename() -> &'static str
Source§fn typehash() -> u64
fn typehash() -> u64
Source§fn typeid() -> TypeId
fn typeid() -> TypeId
Source§fn port() -> u64
fn port() -> u64
Source§impl ReshapeShapeExt for Shape
impl ReshapeShapeExt for Shape
Source§fn reshape(&self, limit: Limit) -> ReshapedShape
fn reshape(&self, limit: Limit) -> ReshapedShape
Source§impl Serialize for Shape
impl Serialize for Shape
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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§
§impl<T> AnySync for T
impl<T> AnySync for T
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> Checkpointable for Twhere
T: RemoteMessage + Clone,
impl<T> Checkpointable for Twhere
T: RemoteMessage + Clone,
Source§type State = T
type State = T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<A, M> Handler<IndexedErasedUnbound<M>> for A
impl<A, M> Handler<IndexedErasedUnbound<M>> for A
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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