pub fn interp_array<T, const N: usize>(
x: &[T],
y: &[T],
xp: &[T; N],
mode: &InterpMode<T>,
) -> [T; N]Expand description
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.
Returns a [T; N] containing the equivalent y coordinates to each of the x coordinates given
by xp.
This is equivalent to running interp iteratively for each value in xp, but more efficient
as intermediate calculations are not repeated.
If the lengths of x and y differ, only the number of elements in the shorter slice are
considered; excess elements are ignored.
If the length of either x or y is 0, 0 is returned for each xp. If the length of either
is 1, y[0] is returned. If both are 2 elements or longer the interpolations are performed as
expected.
ยงExample
use interp::interp_array;
use interp::InterpMode;
let x = [0.0, 1.0, 2.0, 3.0];
let y = [1.0, 3.0, 4.0, 2.0];
let xp = [0.5, 2.5, 4.0];
assert_eq!(interp_array(&x, &y, &xp, &InterpMode::Extrapolate), [2.0, 3.0, 0.0]);Warning: x is expected to be strictly increasing, but this is not explicitly enforced.
However, if x is non-increasing, interpolation results are meaningless.