Extrapolation (ND)

Extrapolation in ND works per-axis, using the same modes as 1D extrapolation.


Modes

ModeBehavior
:noneDomainError (default)
:constantClamp to boundary value
:extensionExtend boundary polynomial
:wrapWrap coordinates periodically

Visualization

All examples use a Franke-lite test function — two Gaussian peaks arranged diagonally on $[0, 1]^2$:

using FastInterpolations

f(x, y) = 0.75exp(-((4x-1)^2 + (4y-1)^2)) + 0.75exp(-((4x-3)^2 + (4y-3)^2)/2)

xs = [0.0, 0.1, 0.4, 0.5, 0.82, 1.0]
ys = [0.0, 0.1, 0.2, 0.5, 0.8, 0.9, 1.0]

data = [f(xi, yj) for xi in xs, yj in ys]

kw = (size=(480, 400), xlims=(-0.3,1.3), ylims=(-0.3,1.3))

extrap=:none (Default)

Domain-only view — queries outside $[0, 1]^2$ throw DomainError:

itp = cubic_interp((xs, ys), data; bc=CubicFit(), extrap=:none)
plot(itp; kw...)
Example block output

extrap=:constant

Boundary values are held constant — flat color bands extend from each edge:

itp = cubic_interp((xs, ys), data; bc=CubicFit(), extrap=:constant)
plot(itp; kw...)
Example block output

extrap=:extension

Boundary polynomials extend beyond the domain — the cubic pieces continue their natural curvature:

itp = cubic_interp((xs, ys), data; bc=CubicFit(), extrap=:extension)
plot(itp; kw...)
Example block output

extrap=:wrap

Coordinates wrap periodically. Since the data is not periodic, a visible seam appears at the boundaries:

itp = cubic_interp((xs, ys), data; bc=CubicFit(), extrap=:wrap)
plot(itp; kw...)
Example block output
Wrap vs Periodic — coordinate repetition is not periodic interpolation

:wrap alone simply maps coordinates back into the domain via modular arithmetic. The interpolant itself is unaware of periodicity, so a C⁰ seam (jump in derivatives) is expected at the boundary.

For true periodic interpolation, use PeriodicBC() with cubic splines. PeriodicBC() enforces C² continuity at the wrap boundary — matching function value, first derivative, and second derivative across the period — producing a seamless, smooth result.

When bc=PeriodicBC() is set on an axis, extrap=:wrap is automatically applied for that axis.


Per-Axis Combinations

Different extrapolation modes can be assigned independently to each axis via a tuple:

itp = cubic_interp((x, y), data; extrap=(:constant, :extension))

Constant × None

Constant extrapolation on x₁, strict domain on x₂ — the heatmap extends only horizontally:

itp = cubic_interp((xs, ys), data; bc=CubicFit(), extrap=(:constant, :none))
plot(itp; kw...)
Example block output

Constant x Wrap

Constant extrapolation on x₁, wrap periodically on x₂:

itp = cubic_interp((xs, ys), data; bc=CubicFit(), extrap=(:constant, :wrap))
plot(itp; kw...)
Example block output

See Also