pub struct Resampler<'a, R: Rng, W: Float> { /* private fields */ }Expand description
The Resampler can be turned into an Iterator to contineously pull sample indices
§Example
use wheel_resample::Resampler;
let mut rng = rand::thread_rng();
let weights = [0.1, 0.2, 0.3, 0.8];
let resampler = Resampler::new(&mut rng, &weights);
let population = vec![1, 2, 3, 4];
let samples = resampler.into_iter().take(4).map(|i| population[i].clone()).collect::<Vec<u32>>();
// Make sure we got four samples
assert_eq!(samples.len(), 4);
// Make sure all samples come from the population
assert!(samples.iter().all(|s| population.contains(s)));Implementations§
Trait Implementations§
Source§impl<'a, R: Rng, W: SampleUniform + Float> IntoIterator for Resampler<'a, R, W>
impl<'a, R: Rng, W: SampleUniform + Float> IntoIterator for Resampler<'a, R, W>
Auto Trait Implementations§
impl<'a, R, W> Freeze for Resampler<'a, R, W>
impl<'a, R, W> RefUnwindSafe for Resampler<'a, R, W>where
R: RefUnwindSafe,
W: RefUnwindSafe,
impl<'a, R, W> Send for Resampler<'a, R, W>
impl<'a, R, W> Sync for Resampler<'a, R, W>
impl<'a, R, W> Unpin for Resampler<'a, R, W>
impl<'a, R, W> !UnwindSafe for Resampler<'a, R, W>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more