Expand description
An implementation of 1-dimensional linear interpolation in Rust, similar to MATLAB’s interp1
or NumPy’s numpy.interp
.
§Example
use interp::{interp, interp_array, interp_slice, InterpMode};
let x = vec![0.0, 0.2, 0.5, 0.8, 1.0];
let y = vec![0.0, 1.0, 3.0, 3.5, 4.0];
// Interpolate at a single point
assert_eq!(interp(&x, &y, 0.35, &InterpMode::default()), 2.0);
// Interpolate a slice - alloces a new results Vec<T>
let xp = vec![0.1, 0.65, 0.9];
assert_eq!(interp_slice(&x, &y, &xp, &InterpMode::default()), vec![0.5, 3.25, 3.75]);
// Interpolate an array
let xp = [0.1, 0.65, 0.9];
assert_eq!(interp_array(&x, &y, &xp, &InterpMode::default()), [0.5, 3.25, 3.75]);
Enums§
- Interp
Mode - Interpolation method that sets the behaviour of the interpolation functions for points outside the range of sample points.
Functions§
- interp
- Linearly interpolate the data points given by the
x
andy
slices at pointxp
, using the interpolation method provided bymode
. - interp_
array - Linearly interpolate the data points given by the
x
andy
slices at each of the points in thexp
slice, using the interpolation method provided bymode
. - interp_
slice - Linearly interpolate the data points given by the
x
andy
slices at each of the points in thexp
slice, using the interpolation method provided bymode
.