Skip to main content

InverseCdf

Struct InverseCdf 

Source
pub struct InverseCdf<const K: usize> { /* private fields */ }
Expand description

Inverse-transform sampling from a tabulated 1-D density (CORE-R58): radial profiles of orbitals, spectral line shapes, speed distributions.

build integrates the density over K equal bins (midpoint rule) and stores K quantiles F⁻¹(j / (K − 1)) of the resulting piecewise-linear CDF in an inline array, so it never allocates; sample interpolates them in O(1). Quantiles skip zero-density bins, though interpolation between two quantiles can cross a zero-density gap narrower than one quantile step.

Implementations§

Source§

impl<const K: usize> InverseCdf<K>

Source

pub fn build(a: f64, b: f64, density: impl FnMut(f64) -> f64) -> Self

Tabulate density (non-negative; negative or non-finite values count as 0) on [a, b] (CORE-R58). Non-finite bounds are taken as 0 and reversed bounds are swapped. A density that is zero or non-finite everywhere, a constant one, and K < 2 all give the exact uniform sampler.

Source

pub fn sample(&self, u: f64) -> f64

The sample for a uniform variate u ∈ [0, 1] (clamped, NaN ⇒ 0): monotone non-decreasing in u, always in [a, b], and exactly a + u·(b − a) for a uniform density (CORE-R58).

Trait Implementations§

Source§

impl<const K: usize> Clone for InverseCdf<K>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const K: usize> Debug for InverseCdf<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const K: usize> Forget for InverseCdf<K>

§

impl<const K: usize> Freeze for InverseCdf<K>
where [f64; K]: Freeze,

§

impl<const K: usize> Move for InverseCdf<K>

§

impl<const K: usize> RefUnwindSafe for InverseCdf<K>
where [f64; K]: RefUnwindSafe,

§

impl<const K: usize> Send for InverseCdf<K>
where [f64; K]: Send,

§

impl<const K: usize> Sync for InverseCdf<K>
where [f64; K]: Sync,

§

impl<const K: usize> Unpin for InverseCdf<K>
where [f64; K]: Unpin,

§

impl<const K: usize> UnsafeUnpin for InverseCdf<K>
where [f64; K]: UnsafeUnpin,

§

impl<const K: usize> UnwindSafe for InverseCdf<K>
where [f64; K]: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V