DataInterpolationsND.jl is a library for interpolating arbitrarily high dimensional array data. The domain of this interpolation is a (hyper)rectangle. Support is included for efficient evaluation at multiple points in the domain through KernelAbstractions.jl.
For one dimensional interpolation see also DataInterpolations.jl.
DataInterpolationsND.jl is similar in functionality to Interpolations.jl, a well established interpolation package that is currently much more feature rich than DataInterpolationsND.jl. We hope to justify the existence of DataInterpolationsND.jl through its use of the KernelAbstractions and its planned integration with the SciML ecosystem.
An NDInterpolation
is defined by a tuple of interpolation dimensions and the data u
to interpolate.
using DataInterpolationsND
t1 = cumsum(rand(5))
t2 = cumsum(rand(7))
interpolation_dimensions = (
LinearInterpolationDimension(t1),
LinearInterpolationDimension(t2)
)
# The outputs will be vectors of length 2
u = rand(5, 7, 2)
interp = NDInterpolation(u, interpolation_dimensions)
Evaluation of this vector valued interpolation can be done in place or out of place.
interp(0.5, 0.5)
out = zeros(2)
interp(out, 0.5, 0.5)
If we provide t_eval
for the interpolation dimensions, we can evaluate at these points either 'zipped' (where all t_eval
must be of the same length) or as a grid defined by the Cartesian product of the t_eval
.
interpolation_dimensions = (
LinearInterpolationDimension(t1; t_eval = range(first(t1), last(t1); length = 100)),
LinearInterpolationDimension(t2; t_eval = range(first(t2), last(t2); length = 100))
)
interp = NDInterpolation(u, interpolation_dimensions)
# Out of place zipped evaluation
eval_unstructured(interp) # Yields Matrix of size (100, 2)
# In place grid evaluation
out = zeros(100, 100, 2)
eval_grid!(out, interp)
This is particularly efficient for evaluating the interpolation for the same t_eval
multiple times with different values for u
, because the indices (and basis functions if applicable) for the t_eval
are cached during the interpolation dimension construction.
The interpolation types are given by the corresponding interpolation dimension type.
LinearInterpolationDimension(t)
: Linear interpolation in the sense of bilinear, trilinear interpolation etc.ConstantInterpolationDimension(t)
: An interpolation with a constant value in each interval betweent
points. The Boolean optionleft
(defaulttrue
) can be used to indicate which side of the interval in which the input lies determines the output value.BSplineInterpolationDimension(t, degree)
: Interpolation using BSpline basis functions. The input valuest
are interpreted as knots, and optionally knot multiplicities can be supplied. Per dimension a degree can be specified. Note that for anNDInterpolation
of this type, the size ofu
for a certain dimension is equal tosum(multiplicities) - degree - 1
. This interpolation dimension type can also be used to define NURBS, by passingcache = NURBSWeights(weights)
to theNDInterpolation
constructor.