pub fn interpn<T: Float + Send + Sync>(
grids: &[&[T]],
vals: &[T],
obs: &[&[T]],
out: &mut [T],
method: GridInterpMethod,
assume_grid_kind: Option<GridKind>,
linearize_extrapolation: bool,
check_bounds_with_atol: Option<T>,
max_threads: Option<usize>,
) -> Result<(), &'static str>Expand description
Evaluate multidimensional interpolation on a regular grid in up to 8 dimensions. Assumes C-style ordering of vals (z(x0, y0), z(x0, y1), …, z(x0, yn), z(x1, y0), …).
For lower dimensions, a fast flattened method is used. For higher dimensions, where that flattening
becomes impractical due to compile times and instruction size, evaluation defers to a run-time
loop.
The linear method uses the flattening for 1-6 dimensions, while
flattened cubic methods are available up to 3 dimensions by default and up to 4 dimensions
with the deep_unroll feature enabled.
This is a convenience function; best performance will be achieved by using the exact right number for the N parameter, as this will slightly reduce compute and storage overhead, and the underlying method can be extended to more than this function’s limit of 8 dimensions. The limit of 8 dimensions was chosen for no more specific reason than to reduce unit test times.
While this method initializes the interpolator struct on every call, the overhead of doing this is minimal even when using it to evaluate one observation point at a time.
Like most grid search algorithms (including in the standard library), the uniqueness and monotonicity of the grid is the responsibility of the user, because checking it is often much more expensive than the algorithm that we will perform on it. Behavior with ill-posed grids is undefined.
§Args:
grids:Nslices of each axis’ grid coordinates. Must be unique and monotonically increasing.vals: FlattenedN-dimensional array of data values at each grid point in C-style order. Must be the same length as the cartesian product of the grids, (n_x * n_y * …).obs:Nslices of Observation points where the interpolant should be evaluated. Must be of equal length.out: Pre-allocated output buffer to place the resulting values. Must be the same length as each of theobsslices.method: Choice of interpolant function.assume_grid_kind: Whether to assume the grid is regular (evenly-spaced), rectilinear (un-evenly spaced), or make no assumption. If an assumption is provided, this bypasses a check of each grid, which can be a major speedup in some cases.linearize_extrapolation: Whether cubic methods should extrapolate linearly instead of the default quadratic extrapolation. Linearization is recommended to prevent the interpolant from diverging to extremes outside the grid.check_bounds_with_atol: If provided, return an error if any observation points are outside the grid by an amount exceeding the provided tolerance.max_threads: If provided, limit number of threads used to at most this number. Otherwise, use a heuristic to choose the number that will provide the best throughput.