Trait ViewExt

Source
pub trait ViewExt: View {
    // Required methods
    fn range<R: Into<Range>>(
        &self,
        dim: &str,
        range: R,
    ) -> Result<Self::View, ViewError>;
    fn group_by(
        &self,
        dim: &str,
    ) -> Result<impl Iterator<Item = Self::View>, ViewError>;
    fn extent(&self) -> Extent;
    fn iter<'a>(&'a self) -> impl Iterator<Item = (Point, Self::Item)> + 'a;
    fn values<'a>(&'a self) -> impl Iterator<Item = Self::Item> + 'a;
}
Expand description

Extension methods for view construction.

Required Methods§

Source

fn range<R: Into<Range>>( &self, dim: &str, range: R, ) -> Result<Self::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
);
Source

fn group_by( &self, dim: &str, ) -> Result<impl Iterator<Item = Self::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)
);
Source

fn extent(&self) -> Extent

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

Source

fn iter<'a>(&'a self) -> impl Iterator<Item = (Point, Self::Item)> + 'a

Iterate over all points in this region.

Source

fn values<'a>(&'a self) -> impl Iterator<Item = Self::Item> + 'a

Iterate over the values in the region.

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.

Implementors§

Source§

impl<T: View> ViewExt for T