[][src]Trait psyche_utils::grid::GridSampler

pub trait GridSampler<T, W> {
    fn sample(self, grid: &Grid<T>) -> Option<(T, W)>;
}

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

Required methods

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));
Loading content...

Implementors

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

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

Loading content...