Crate interp

Source
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]);

Warning: x is expected to be strictly increasing, but this is not explicitly enforced. However, if x is non-increasing, interpolation results are meaningless.

Enums§

InterpMode
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 and y slices at point xp, using the interpolation method provided by mode.
interp_array
Linearly interpolate the data points given by the x and y slices at each of the points in the xp slice, using the interpolation method provided by mode.
interp_slice
Linearly interpolate the data points given by the x and y slices at each of the points in the xp slice, using the interpolation method provided by mode.