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§
Sourcefn sample(self, grid: &Grid<T>) -> Option<(T, W)>
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));