Expand description
The ninterp crate provides
multivariate interpolation
over rectilinear grids of any dimensionality.
There are hard-coded interpolators for lower dimensionalities (up to N = 3) for better runtime performance. All interpolators work with both owned and borrowed arrays (array views) of various types.
A variety of interpolation strategies are implemented and exposed in the prelude module.
Custom interpolation strategies can be defined in downstream crates.
cargo add ninterp§Cargo Features
§Examples
See examples in new method documentation:
Also see the examples directory for advanced examples:
-
dynamic_strategy.rsStrategy dynamic dispatch
By default, construction of interpolators uses static dispatch, meaning strategy concrete types are determined at compilation. This gives increased performance at the cost of runtime flexibility. To allow swapping strategies at runtime, use dynamic dispatch by providing a boxed trait object
Box<dyn Strategy1D>/etc. to thenewmethod. -
dynamic_interpolator.rsInterpolator dynamic dispatch using
Box<dyn Interpolator> -
custom_strategy.rsDefining custom strategies
-
uom.rsUsing transmutable (transparent) types, such as
uom::si::Quantity
§Overview
A prelude module has been defined:
use ninterp::prelude::*;This exposes all strategies and a variety of interpolators:
There is also a constant-value ‘interpolator’:
Interp0D.
This is useful when working with a Box<dyn Interpolator>
Instantiation is done by calling an interpolator’s new method.
For dimensionalities N ≥ 1, this executes a validation step, preventing runtime panics.
After editing interpolator data,
call the InterpData’s validate method
or Interpolator::validate
to rerun these checks.
To change the extrapolation setting, call set_extrapolate.
To change the interpolation strategy,
supply a Box<dyn Strategy1D>/etc. upon instantiation,
and call set_strategy.
§Strategies
An interpolation strategy (e.g. Linear, Nearest, LeftNearest, RightNearest) must be specified.
Not all interpolation strategies are implemented for every dimensionality.
Linear and Nearest are implemented for all dimensionalities.
Custom strategies can be defined. See examples/custom_strategy.rs for an example.
§Extrapolation
An Extrapolate setting must be provided in the new method.
This controls what happens when a point is beyond the range of supplied coordinates.
The following settings are applicable for all interpolators:
Extrapolate::Enable is valid for Linear for all dimensionalities.
If you are unsure which variant to choose, Extrapolate::Error is likely what you want.
§Interpolation
Interpolation is executed by calling Interpolator::interpolate.
The length of the interpolant point slice must be equal to the interpolator dimensionality.
The interpolator dimensionality can be retrieved by calling Interpolator::ndim.
Re-exports§
pub use ndarray;
Modules§
- data
- error
- Crate error types
- interpolator
- n
- N-dimensional interpolation
- one
- 1-dimensional interpolation
- prelude
- The
preludemodule exposes a variety of types: - strategy
- Pre-defined interpolation strategies and traits for custom strategies
- three
- 3-dimensional interpolation
- two
- 2-dimensional interpolation
- zero
- 0-dimensional interpolation
Enums§
- Extrapolate
- Extrapolation strategy
Traits§
- Interpolator
- An interpolator of data type
T