pub trait ViewExt: Viewable {
// Required methods
fn range<R: Into<Range>>(
&self,
dim: &str,
range: R,
) -> Result<View, ViewError>;
fn group_by(
&self,
dim: &str,
) -> Result<impl Iterator<Item = View>, ViewError>;
}
Expand description
Extension methods for view construction.
Required Methods§
Sourcefn range<R: Into<Range>>(&self, dim: &str, range: R) -> Result<View, ViewError>
fn range<R: Into<Range>>(&self, dim: &str, range: R) -> Result<View, ViewError>
Construct a view comprising the range of points along the provided dimension.
§Examples
use ndslice::Range;
use ndslice::ViewExt;
use ndslice::extent;
let ext = extent!(zone = 4, host = 2, gpu = 8);
// Subselect zone index 0.
assert_eq!(ext.range("zone", 0).unwrap().iter().count(), 16);
// Even GPUs within zone 0
assert_eq!(
ext.range("zone", 0)
.unwrap()
.range("gpu", Range(0, None, 2))
.unwrap()
.iter()
.count(),
8
);
Sourcefn group_by(&self, dim: &str) -> Result<impl Iterator<Item = View>, ViewError>
fn group_by(&self, dim: &str) -> Result<impl Iterator<Item = 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.
§Examples
use ndslice::ViewExt;
use ndslice::extent;
let ext = extent!(zone = 4, host = 2, gpu = 8);
// We generate one view for each zone.
assert_eq!(ext.group_by("host").unwrap().count(), 4);
let mut parts = ext.group_by("host").unwrap();
let zone0 = parts.next().unwrap();
let mut zone0_points = zone0.iter();
assert_eq!(zone0.extent(), extent!(host = 2, gpu = 8));
assert_eq!(
zone0_points.next().unwrap(),
(extent!(host = 2, gpu = 8).point(vec![0, 0]).unwrap(), 0)
);
assert_eq!(
zone0_points.next().unwrap(),
(extent!(host = 2, gpu = 8).point(vec![0, 1]).unwrap(), 1)
);
let zone1 = parts.next().unwrap();
assert_eq!(zone1.extent(), extent!(host = 2, gpu = 8));
assert_eq!(
zone1.iter().next().unwrap(),
(extent!(host = 2, gpu = 8).point(vec![0, 0]).unwrap(), 16)
);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.