Struct Shape

Source
pub struct Shape { /* private fields */ }
Expand description

A shape is a Slice with labeled dimensions and a selection API.

Implementations§

Source§

impl Shape

Source

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.

Source

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.

Source

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.

Source

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().

Source

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

Source

pub fn labels(&self) -> &[String]

The per-dimension labels of this shape.

Source

pub fn slice(&self) -> &Slice

The slice describing the shape.

Source

pub fn coordinates( &self, rank: usize, ) -> Result<Vec<(String, usize)>, ShapeError>

Return a set of labeled coordinates for the given rank.

Source

pub fn dim(&self, label: &str) -> Result<usize, ShapeError>

Source

pub fn unity() -> Shape

Return the 0-dimensional single element shape

Source

pub fn extent(&self) -> Extent

The extent corresponding to this shape.

Trait Implementations§

Source§

impl Clone for Shape

Source§

fn clone(&self) -> Shape

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 Shape

Source§

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

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

impl<'de> Deserialize<'de> for Shape

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Shape

Source§

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

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

impl Hash for Shape

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Shape

Source§

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

Source§

fn reshape(&self, limit: Limit) -> ReshapedShape

Produces a reshaped version of the shape with expanded dimensions under the given size limit.
Source§

impl Serialize for Shape

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,