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>
impl<const K: usize> InverseCdf<K>
Sourcepub fn build(a: f64, b: f64, density: impl FnMut(f64) -> f64) -> Self
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.