Struct Region

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

Region describes a region of a possibly-larger space of ranks, organized into a hyperrect.

Internally, region consist of a set of labels and a Slice, as it allows for a compact but useful representation of the ranks. However, this representation may change in the future.

Implementations§

Source§

impl Region

Source

pub fn new(labels: Vec<String>, slice: Slice) -> Self

Constructor to build arbitrary regions (incl. non-contiguous / offset).

Source

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

The labels of the dimensions of this region.

Source

pub fn slice(&self) -> &Slice

The slice representing this region. Note: this representation may change.

Source

pub fn into_inner(self) -> (Vec<String>, Slice)

Convert this region into its constituent labels and slice.

Source

pub fn extent(&self) -> Extent

Returns the extent of the region.

Source

pub fn is_subset(&self, other: &Region) -> bool

Returns true if this region is a subset of other, i.e., if other contains at least all of the ranks in this region.

Source

pub fn remap(&self, target: &Region) -> Option<impl Iterator<Item = usize> + '_>

Remap the target to ranks in this region. The returned iterator iterates over each rank in target, providing the corresponding rank in self. This is useful when mapping between different subspaces.

let ext = extent!(replica = 8, gpu = 4);
let replica1 = ext.range("replica", 1).unwrap();
assert_eq!(replica1.extent(), extent!(replica = 1, gpu = 4));
let replica1_gpu12 = replica1.range("gpu", 1..3).unwrap();
assert_eq!(replica1_gpu12.extent(), extent!(replica = 1, gpu = 2));
// The first rank in `replica1_gpu12` is the second rank in `replica1`.
assert_eq!(
    replica1.remap(&replica1_gpu12).unwrap().collect::<Vec<_>>(),
    vec![1, 2],
);
Source

pub fn num_ranks(&self) -> usize

Returns the total number of ranks in the region.

Source

pub fn base_rank_of_point(&self, p: Point) -> Result<usize, RegionError>

Convert a rank in this region’s extent into its corresponding rank in the base space defined by the region’s Slice.

Source

pub fn point_of_base_rank(&self, rank: usize) -> Result<Point, RegionError>

Convert a rank in the base space into the corresponding Point in this region’s extent (if the base rank lies within the region’s Slice).

Trait Implementations§

Source§

impl Clone for Region

Source§

fn clone(&self) -> Region

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 Region

Source§

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

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

impl<'de> Deserialize<'de> for Region

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 Region

Formats a Region in a compact rectangular syntax:

[offset+]label=size/stride[,label=size/stride,...]

§Grammar

Region   := [ Offset "+" ] Pair ( "," Pair )*
Offset   := [0-9]+
Pair     := Label "=" Size "/" Stride
Label    := SafeIdent | Quoted
SafeIdent:= [A-Za-z0-9_]+
Quoted   := "\"" ( [^"\\] | "\\" . )* "\""   // Rust string literal style
Size     := [0-9]+
Stride   := [0-9]+

§Quoting rules

  • Labels that are not SafeIdent are rendered using Rust string-literal syntax (via format!("{:?}", label)).
  • “Safe” means ASCII alphanumeric or underscore ([A-Za-z0-9_]+). Everything else is quoted.
  • The optional Offset+ prefix appears only when the slice offset is nonzero.

§Examples

x=2/1,y=3/2
8+"dim/0"=4/1,"dim,1"=5/4

§Notes

This format is both human-readable and machine-parsable. The corresponding FromStr implementation accepts exactly this grammar, including quoted labels. The quoting rule makes round-trip unambiguous.

Source§

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

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

impl From<&Region> for Shape

Source§

fn from(region: &Region) -> Self

Converts to this type from the input type.
Source§

impl From<&Shape> for Region

Source§

fn from(s: &Shape) -> Self

Converts to this type from the input type.
Source§

impl From<Extent> for Region

Source§

fn from(extent: Extent) -> Self

Converts to this type from the input type.
Source§

impl From<Shape> for Region

Source§

fn from(s: Shape) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Region

Parses a Region from the textual form emitted by Display.

The accepted syntax and quoting rules are exactly those documented on Display: comma-separated label=size/stride pairs with an optional offset+ prefix, and labels that are either safe identifiers or Rust string literals.

Returns a RegionParseError on malformed input.

§Examples

use ndslice::view::Region;

let r: Region = "x=2/1,y=3/2".parse().unwrap();
assert_eq!(r.labels(), &["x", "y"]);

let q: Region = "8+\"dim/0\"=4/1".parse().unwrap();
assert_eq!(q.labels(), &["dim/0"]);
Source§

type Err = RegionParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for Region

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 Region

Source§

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

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 View for Region

A Region is also a View.

Source§

type Item = usize

The type of item is the rank in the underlying space.

Source§

type View = Region

The type of sub-view is also a Region.

Source§

fn region(&self) -> Region

The ranks contained in this view.
Source§

fn subset(&self, region: Region) -> Result<Region, ViewError>

Subsets this view with the provided ranks. This is mainly used by combinators on Views themselves. The set of ranks passed in must be a subset of the ranks of the base view.
Source§

fn get(&self, rank: usize) -> Option<Self::Item>

Retrieve the item corresponding to the given rank in the Region of this view. An implementation MUST return a value for all ranks defined in this view.
Source§

impl Eq for Region

Source§

impl StructuralPartialEq for Region

Auto Trait Implementations§

§

impl Freeze for Region

§

impl RefUnwindSafe for Region

§

impl Send for Region

§

impl Sync for Region

§

impl Unpin for Region

§

impl UnwindSafe for Region

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> ViewExt for T
where T: View,

Source§

fn range<R>(&self, dim: &str, range: R) -> Result<<T as View>::View, ViewError>
where R: Into<Range>,

Construct a view comprising the range of points along the provided dimension. Read more
Source§

fn group_by( &self, dim: &str, ) -> Result<impl Iterator<Item = <T as View>::View>, ViewError>

Group by view on dim. The returned iterator enumerates all groups as views in the extent of dim to the last dimension of the view. Read more
Source§

fn extent(&self) -> Extent

The extent of this view. Every point in this space is defined.
Source§

fn iter(&self) -> impl Iterator<Item = (Point, <T as View>::Item)>

Iterate over all points in this region.
Source§

fn values(&self) -> impl Iterator<Item = <T as View>::Item>

Iterate over the values in the region.
Source§

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