pub struct NearestRegular<'a, T: Float, const N: usize> { /* private fields */ }Expand description
An arbitrary-dimensional multilinear interpolator / extrapolator on a regular grid.
Assumes C-style ordering of vals (z(x0, y0), z(x0, y1), …, z(x0, yn), z(x1, y0), …).
Operation Complexity
- O(2^N) for interpolation and extrapolation in all regions.
Memory Complexity
- Peak stack usage is O(N), which is minimally O(N).
- While evaluation is recursive, the recursion has constant max depth of N, which provides a guarantee on peak memory usage.
Timing
- Timing determinism is guaranteed to the extent that floating-point calculation timing is consistent. That said, floating-point calculations can take a different number of clock-cycles depending on numerical values.
Implementations§
Source§impl<'a, T: Float, const N: usize> NearestRegular<'a, T, N>
impl<'a, T: Float, const N: usize> NearestRegular<'a, T, N>
Sourcepub fn new(
dims: [usize; N],
starts: [T; N],
steps: [T; N],
vals: &'a [T],
) -> Result<Self, &'static str>
pub fn new( dims: [usize; N], starts: [T; N], steps: [T; N], vals: &'a [T], ) -> Result<Self, &'static str>
Build a new interpolator, using O(N) calculations and storage.
This method does not handle degenerate dimensions; all grids must have at least 2 entries.
Assumes C-style ordering of vals (z(x0, y0), z(x0, y1), …, z(x0, yn), z(x1, y0), …).
§Errors
- If any input dimensions do not match
- If any dimensions have size < 2
- If any step sizes have zero or negative magnitude
Sourcepub fn interp(&self, x: &[&[T]; N], out: &mut [T]) -> Result<(), &'static str>
pub fn interp(&self, x: &[&[T]; N], out: &mut [T]) -> Result<(), &'static str>
Interpolate on a contiguous list of observation points.
Assumes C-style ordering of vals (z(x0, y0), z(x0, y1), …, z(x0, yn), z(x1, y0), …).
§Errors
- If the dimensionality of the point does not match the data
- If the dimensionality of point or data does not match the grid
Sourcepub fn interp_one(&self, x: [T; N]) -> Result<T, &'static str>
pub fn interp_one(&self, x: [T; N]) -> Result<T, &'static str>
Interpolate the value at a point, using fixed-size intermediate storage of O(N) and no allocation.
Assumes C-style ordering of vals (z(x0, y0), z(x0, y1), …, z(x0, yn), z(x1, y0), …).
§Errors
- If the dimensionality of the point does not match the data
- If the dimensionality of either one exceeds the fixed maximum
- If the index along any dimension exceeds the maximum representable
integer value within the value type
T
Auto Trait Implementations§
impl<'a, T, const N: usize> Freeze for NearestRegular<'a, T, N>where
T: Freeze,
impl<'a, T, const N: usize> RefUnwindSafe for NearestRegular<'a, T, N>where
T: RefUnwindSafe,
impl<'a, T, const N: usize> Send for NearestRegular<'a, T, N>
impl<'a, T, const N: usize> Sync for NearestRegular<'a, T, N>where
T: Sync,
impl<'a, T, const N: usize> Unpin for NearestRegular<'a, T, N>where
T: Unpin,
impl<'a, T, const N: usize> UnwindSafe for NearestRegular<'a, T, N>where
T: UnwindSafe + RefUnwindSafe,
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> 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 more