[][src]Struct wheel_resample::Resampler

pub struct Resampler<'a, R: Rng, W: Float> { /* fields omitted */ }

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)));

Methods

impl<'a, R: Rng, W: Float> Resampler<'a, R, W>[src]

pub fn new(rng: &'a mut R, weights: &'a [W]) -> Self[src]

Create Resampler instance from random generator and weights

Trait Implementations

impl<'a, R: Rng, W: SampleUniform + Float> IntoIterator for Resampler<'a, R, W>[src]

type Item = usize

The type of the elements being iterated over.

type IntoIter = ResampleIterator<'a, R, W>

Which kind of iterator are we turning this into?

Auto Trait Implementations

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> where
    R: Send,
    W: Sync

impl<'a, R, W> Sync for Resampler<'a, R, W> where
    R: Sync,
    W: Sync

impl<'a, R, W> Unpin for Resampler<'a, R, W>

impl<'a, R, W> !UnwindSafe for Resampler<'a, R, W>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,