Struct bio::data_structures::interpolation_table::InterpolationTable
source · [−]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
sourceimpl<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.
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.