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
impl Region
Sourcepub fn new(labels: Vec<String>, slice: Slice) -> Self
pub fn new(labels: Vec<String>, slice: Slice) -> Self
Constructor to build arbitrary regions (incl. non-contiguous / offset).
Sourcepub fn slice(&self) -> &Slice
pub fn slice(&self) -> &Slice
The slice representing this region. Note: this representation may change.
Sourcepub fn into_inner(self) -> (Vec<String>, Slice)
pub fn into_inner(self) -> (Vec<String>, Slice)
Convert this region into its constituent labels and slice.
Sourcepub fn is_subset(&self, other: &Region) -> bool
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.
Sourcepub fn remap(&self, target: &Region) -> Option<impl Iterator<Item = usize> + '_>
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],
);
Sourcepub fn base_rank_of_point(&self, p: Point) -> Result<usize, RegionError>
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
.
Sourcepub fn point_of_base_rank(&self, rank: usize) -> Result<Point, RegionError>
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<'de> Deserialize<'de> for Region
impl<'de> Deserialize<'de> for Region
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 Display for Region
Formats a Region
in a compact rectangular syntax:
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 (viaformat!("{:?}", 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§impl FromStr for Region
Parses a Region
from the textual form emitted by
Display
.
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§impl View for Region
A Region
is also a View.
impl View for Region
A Region
is also a View.
impl Eq for Region
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> 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 moreSource§impl<T> ViewExt for Twhere
T: View,
impl<T> ViewExt for Twhere
T: View,
Source§fn range<R>(&self, dim: &str, range: R) -> Result<<T as View>::View, ViewError>
fn range<R>(&self, dim: &str, range: R) -> Result<<T as View>::View, ViewError>
Source§fn group_by(
&self,
dim: &str,
) -> Result<impl Iterator<Item = <T as View>::View>, ViewError>
fn group_by( &self, dim: &str, ) -> Result<impl Iterator<Item = <T as View>::View>, ViewError>
dim
. The returned iterator enumerates all groups
as views in the extent of dim
to the last dimension of the view. Read more