Trait GridSampler

Source
pub trait GridSampler<T, W> {
    // Required method
    fn sample(self, grid: &Grid<T>) -> Option<(T, W)>;
}
Expand description

Trait used to sample pair of single value and weight from grid.

Required Methods§

Source

fn sample(self, grid: &Grid<T>) -> Option<(T, W)>

Sample value and weight from given grid.

§Arguments
  • grid - Grid that we sample from.
§Return

Pair of single value and weight as result of grid sampling.

§Example
use psyche_utils::grid::{Grid, GridSampler};

struct MySampler;

impl GridSampler<f32, usize> for MySampler {
    fn sample(self, grid: &Grid<f32>) -> Option<(f32, usize)> {
        let value = grid.fields().iter().cloned().sum();
        let weight = grid.fields().len();
        Some((value, weight))
    }
}

let grid = Grid::new(2, 2, 1.0);
let sampler = MySampler {};
assert_eq!(grid.sample(sampler).unwrap(), (4.0, 4));

Implementors§

Source§

impl<T> GridSampler<T, f64> for GridSamplerDistance
where T: GridSampleZeroValue<T> + Add<Output = T> + Clone + Mul<Scalar, Output = T>,

Source§

impl<T> GridSampler<T, usize> for GridSamplerCluster
where T: GridSampleZeroValue<T> + Add<Output = T> + Clone,