NearestRegular

Struct NearestRegular 

Source
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>

Source

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
Source

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
Source

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>
where T: Send + Sync,

§

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>

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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.