pub struct InterpolationTable<F: Fn(f64) -> f64> { /* private fields */ }Expand description
Fast lookup table for arbitrary floating point functions. This can be used to e.g., provide fast lookups of distribution values. Input values are sampled with a given precision and results are stored in a vector. During lookup, infimum and supremum of a given value are calculated and the result is interpolated.
Implementations§
Source§impl<F: Fn(f64) -> f64> InterpolationTable<F>
impl<F: Fn(f64) -> f64> InterpolationTable<F>
Sourcepub fn new(min_x: f64, max_x: f64, frac_digits: i32, func: F) -> Self
pub fn new(min_x: f64, max_x: f64, frac_digits: i32, func: F) -> Self
Create a new InterpolationTable.
§Arguments
min_x- minimum sample valuemax_x- maximum sample valuefrac_digits- number of fraction digits to store in samplefunc- Function to emulate.
If given value is outside of min_x and max_x, the lookup falls back to applying the
function itself.
The table size grows with the number of fraction digits.
Space Complexity: O(m * 10^n), where m = max_x - min_x and n = frac_digits
Sourcepub fn get(&self, x: f64) -> f64
pub fn get(&self, x: f64) -> f64
Lookup given value in table, and interpolate the result between the sampled values if
necessary. This provides an approximation that is better the more fraction digits are
used to generate this table.
Time Complexity for lookup: O(1) if min_x <= x < max_x and O(func(x)) otherwise.
Trait Implementations§
Source§impl<F: Clone + Fn(f64) -> f64> Clone for InterpolationTable<F>
impl<F: Clone + Fn(f64) -> f64> Clone for InterpolationTable<F>
Source§fn clone(&self) -> InterpolationTable<F>
fn clone(&self) -> InterpolationTable<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F: Default + Fn(f64) -> f64> Default for InterpolationTable<F>
impl<F: Default + Fn(f64) -> f64> Default for InterpolationTable<F>
Source§fn default() -> InterpolationTable<F>
fn default() -> InterpolationTable<F>
Source§impl<'de, F> Deserialize<'de> for InterpolationTable<F>
impl<'de, F> Deserialize<'de> for InterpolationTable<F>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<F: PartialOrd + Fn(f64) -> f64> PartialOrd for InterpolationTable<F>
impl<F: PartialOrd + Fn(f64) -> f64> PartialOrd for InterpolationTable<F>
Source§impl<F> Serialize for InterpolationTable<F>
impl<F> Serialize for InterpolationTable<F>
impl<F: Fn(f64) -> f64> StructuralPartialEq for InterpolationTable<F>
Auto Trait Implementations§
impl<F> Freeze for InterpolationTable<F>where
F: Freeze,
impl<F> RefUnwindSafe for InterpolationTable<F>where
F: RefUnwindSafe,
impl<F> Send for InterpolationTable<F>where
F: Send,
impl<F> Sync for InterpolationTable<F>where
F: Sync,
impl<F> Unpin for InterpolationTable<F>where
F: Unpin,
impl<F> UnwindSafe for InterpolationTable<F>where
F: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.