pub struct AliasTable { /* private fields */ }Expand description
Walker/Vose alias table over a discrete PDF.
Build once with AliasTable::new, then draw with
AliasTable::sample using two uniform random numbers in [0, 1).
Implementations§
Source§impl AliasTable
impl AliasTable
Sourcepub fn new(pdf: &[f64]) -> Result<Self, Error>
pub fn new(pdf: &[f64]) -> Result<Self, Error>
Build an alias table from a non-negative PDF.
The PDF is normalized internally so the standalone API is safe with unnormalized input (the underlying construction assumes a unit sum).
Sourcepub fn sample(&self, r1: f64, r2: f64) -> usize
pub fn sample(&self, r1: f64, r2: f64) -> usize
Draw one index using two uniforms in [0, 1).
Mirrors sample_pdf(rand1, rand2): pick column n * rand1, return it
when rand2 < prob[column], else the column’s alias.
r1 is saturated to [0, n) before indexing: negative values map to
column 0 and values >= 1.0 map to column n - 1. This is
intentional defensive behavior; callers should still pass uniforms in
[0, 1).
Trait Implementations§
Source§impl Clone for AliasTable
impl Clone for AliasTable
Source§fn clone(&self) -> AliasTable
fn clone(&self) -> AliasTable
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AliasTable
impl Debug for AliasTable
Source§impl PartialEq for AliasTable
impl PartialEq for AliasTable
impl StructuralPartialEq for AliasTable
Auto Trait Implementations§
impl Freeze for AliasTable
impl RefUnwindSafe for AliasTable
impl Send for AliasTable
impl Sync for AliasTable
impl Unpin for AliasTable
impl UnsafeUnpin for AliasTable
impl UnwindSafe for AliasTable
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