Type Reference
Abstract Types
Interpolant Hierarchy
FastInterpolations.AbstractInterpolant — Type
AbstractInterpolant{Tg<:AbstractFloat, Tv}Abstract supertype for all interpolant objects.
Type Parameters
Tg: Grid/coordinate type (Float32 or Float64) - used for x-coordinates, spacing, searchTv: Value type - used for y-values, coefficients, return values. Can beTg(real-valued),Complex{Tg}(complex-valued), or other Number types.
Design Invariant
- Grid operations (search, spacing) always use Tg
- Value operations (kernel, coefficients) use Tv
- Evaluation returns type based on promotetype(Tv, querytype)
Subtypes
AbstractSeriesInterpolant{Tg, Tv}: Multi-series interpolantsLinearInterpolant{Tg, Tv}: Piecewise linear interpolationConstantInterpolant{Tg, Tv}: Piecewise constant (step) interpolationQuadraticInterpolant{Tg, Tv}: C1 piecewise quadratic splineCubicInterpolant{Tg, Tv}: C2 natural/clamped/periodic cubic spline
Note
This is a pure type hierarchy - no methods are defined on AbstractInterpolant itself. All functionality is implemented in concrete subtypes.
FastInterpolations.AbstractSeriesInterpolant — Type
AbstractSeriesInterpolant{Tg<:AbstractFloat, Tv}Abstract supertype for multi-series interpolant objects. Series interpolants handle multiple y-series sharing the same x-grid.
Type Parameters
Tg: Grid/coordinate type (Float32 or Float64)Tv: Value type - can be real or complex
Subtypes
LinearSeriesInterpolant{Tg, Tv}: Multiple linear interpolants sharing x-gridConstantSeriesInterpolant{Tg, Tv}: Multiple constant interpolants sharing x-gridQuadraticSeriesInterpolant{Tg, Tv}: Multiple quadratic interpolants sharing x-gridCubicSeriesInterpolant{Tg, Tv}: Multiple cubic splines sharing x-grid
Key Features
- Anchor optimization: compute interval once, evaluate all series
- Matrix storage: unified storage for optimal SIMD vectorization
- Zero-allocation batch evaluation with pre-built anchors
Usage
x = collect(range(0.0, 1.0, 101))
y1, y2, y3 = sin.(2π .* x), cos.(2π .* x), exp.(-x)
sitp = cubic_interp(x, [y1, y2, y3]) # Creates CubicSeriesInterpolant
vals = sitp(0.5) # Returns Vector of 3 values
sitp(output, 0.5) # In-place evaluationNote
This is a pure type hierarchy - no methods are defined on AbstractSeriesInterpolant itself. All functionality is implemented in concrete subtypes.
FastInterpolations.AbstractInterpolantND — Type
AbstractInterpolantND{Tg<:AbstractFloat, Tv, N}Abstract supertype for N-dimensional interpolant objects.
Type Parameters
Tg: Grid/coordinate type (Float32 or Float64)Tv: Value type - can be real, complex, or other Number typesN: Number of dimensions
API Differences from 1D Interpolants
- Evaluation:
itp(x::NTuple{N})oritp(x::AbstractVector)instead ofitp(x::Real) - Derivatives: Use
derivkeyword (e.g.,itp(x; deriv=(1,0))) orderiv_view(itp, (1,0)) - Vector Calculus: Supports
gradient,hessian,laplacian
Subtypes
CubicInterpolantND{Tg, Tv, N}: N-dimensional cubic Hermite interpolation
Example
x, y = range(0, 1, 50), range(0, 1, 50)
data = [sin(xi) * cos(yj) for xi in x, yj in y]
itp = cubic_interp((x, y), data) # Returns CubicInterpolantND{..., 2}
itp((0.5, 0.5)) # Evaluate
itp((0.5, 0.5); deriv=(1, 0)) # ∂f/∂x
gradient(itp, (0.5, 0.5)) # (∂f/∂x, ∂f/∂y)ND Cubic Types
FastInterpolations.AbstractCoeffStrategy — Type
AbstractCoeffStrategyAbstract supertype for coefficient computation strategies in ND interpolation.
Implemented Strategies
PreCompute: Precompute all partial derivatives at construction (O(1) query)OnTheFly: Compute coefficients lazily at query time (O(n) query)
FastInterpolations.PreCompute — Type
PreCompute <: AbstractCoeffStrategyPrecompute all partial derivatives at construction time.
For N-dimensional interpolation, stores 2^N partial derivatives per grid point:
- 2D: 4 partials (f, ∂f/∂x, ∂f/∂y, ∂²f/∂x∂y)
- 3D: 8 partials (f, ∂f/∂x, ∂f/∂y, ∂f/∂z, ∂²f/∂x∂y, ∂²f/∂x∂z, ∂²f/∂y∂z, ∂³f/∂x∂y∂z)
Trade-offs
- Memory: O(2^N × n^N) - higher than OnTheFly
- Construction: O(N × n^N) - expensive (N passes of 1D spline solving)
- Query: O(1) - ultra-fast (just polynomial evaluation)
Best for
- Static data with many queries
- Real-time applications requiring fast evaluation
- Scenarios where construction cost can be amortized
FastInterpolations.OnTheFly — Type
OnTheFly <: AbstractCoeffStrategyCompute coefficients lazily at query time using tensor-product (separable) approach.
Stores only the original data; computes 1D spline solutions per-axis at each query.
Trade-offs
- Memory: O(n^N) - minimal (only original data)
- Construction: O(1) - instant (just store data reference)
- Query: O(n) per axis - slower (must solve 1D systems)
Best for
- Few queries on large datasets
- Memory-constrained environments
- Data that changes frequently
FastInterpolations.CubicInterpolantND — Type
CubicInterpolantND{Tg, Tv, N, NP1, G, S, B, E, P}Generic N-dimensional cubic Hermite interpolant with precomputed partial derivatives.
Stores function values AND all partial derivatives at grid nodes, enabling ultra-fast O(1) evaluation via tensor-product Hermite polynomials.
Type Parameters
Tg: Grid/coordinate type (Float32 or Float64)Tv: Value type (can be Tg, Complex{Tg}, or other Number)N: Number of dimensionsNP1: N + 1 (partials array dimensionality)G: Tuple type for grids,NTuple{N, <:AbstractVector{Tg}}S: Tuple type for spacings,NTuple{N, <:AbstractGridSpacing{Tg}}B: Tuple type for boundary conditions,NTuple{N, <:AbstractBC}E: Tuple type for extrapolation modes,NTuple{N, <:ExtrapVal}P: Tuple type for search policies,NTuple{N, <:AbstractSearchPolicy}
Fields
grids: N-tuple of grid vectors for each dimensionspacings: N-tuple of grid spacing info (for O(1) h lookup)nodal_derivs: NodalDerivativesND containing partial derivatives at grid nodesbcs: N-tuple of boundary conditions used for constructionextraps: N-tuple of extrapolation modessearches: N-tuple of search policies
Performance
- Construction: O(2^N × n^N) - computes all partial derivatives
- Query: O(1) - tensor-product Hermite polynomial evaluation
- Memory: 2^N × n^N values
Thread-Safety
Immutable after construction; safe for concurrent read access.
Example
x = range(0.0, 2π, 50)
y = range(0.0, π, 30)
z = range(0.0, 1.0, 20)
data = [sin(xi) * cos(yj) * zk for xi in x, yj in y, zk in z]
itp = cubic_interp((x, y, z), data) # Returns CubicInterpolantND{..., 3, 4, ...}
itp((1.0, 0.5, 0.3)) # Evaluate at (1.0, 0.5, 0.3)Type Accessors
FastInterpolations.grid_type — Function
grid_type(::AbstractInterpolant{Tg, Tv}) -> Type{Tg}Get the grid/coordinate type of an interpolant.
FastInterpolations.value_type — Function
value_type(::AbstractInterpolant{Tg, Tv}) -> Type{Tv}Get the value type of an interpolant.
FastInterpolations.eval_type — Function
eval_type(::AbstractInterpolant{Tg, Tv}, ::Type{Tq}) -> TypeCompute the output type when evaluating an interpolant with query type Tq. This is promote_type(Tv, Tq), accounting for value type (real or complex) and query type (standard float or ForwardDiff.Dual).
Examples
itp = linear_interp([0.0, 1.0], [1.0, 2.0])
eval_type(itp, Float64) # Float64
itp_c = linear_interp([0.0, 1.0], [1.0+0im, 2.0+0im])
eval_type(itp_c, Float64) # ComplexF64Evaluation Operations
FastInterpolations.AbstractEvalOp — Type
AbstractEvalOpAbstract type for evaluation operations (value, derivatives). Used for compile-time dispatch to select appropriate kernel.
Subtypes:
EvalValue: Evaluate function value f(x)EvalDeriv1: Evaluate first derivative f'(x)EvalDeriv2: Evaluate second derivative f''(x)EvalDeriv3: Evaluate third derivative f'''(x)
FastInterpolations.EvalValue — Type
EvalValue <: AbstractEvalOpSingleton type indicating evaluation of function value f(x).
FastInterpolations.EvalDeriv1 — Type
EvalDeriv1 <: AbstractEvalOpSingleton type indicating evaluation of first derivative f'(x).
FastInterpolations.EvalDeriv2 — Type
EvalDeriv2 <: AbstractEvalOpSingleton type indicating evaluation of second derivative f''(x).
FastInterpolations.EvalDeriv3 — Type
EvalDeriv3 <: AbstractEvalOpSingleton type indicating evaluation of third derivative f'''(x).
Note
For cubic splines, S'''(x) is constant within each interval. Linear/quadratic/constant interpolants always return zero.
Mathematical Background
The cubic spline third derivative is: S'''(x) = (zR - zL) / h
where zL and zR are the second derivative values (moments) at the interval endpoints, and h is the interval width.
Vector Calculus (ND)
FastInterpolations.gradient — Function
gradient(itp::AbstractInterpolantND, query)Compute the gradient (vector of partial derivatives) at query.
Returns an NTuple{N} of partial derivatives (∂f/∂x₁, ∂f/∂x₂, ..., ∂f/∂xₙ).
Performance
~9x faster than ForwardDiff.gradient by using analytical derivatives. Uses locate-once optimization: interval search performed only once per query point.
Examples
itp = cubic_interp((x, y), data)
gradient(itp, (0.5, 0.5)) # → (∂f/∂x, ∂f/∂y)
gradient(itp, [0.5, 0.5]) # Vector input also supportedFastInterpolations.gradient! — Function
gradient!(G, itp::AbstractInterpolantND, query)Compute the gradient in-place, writing partial derivatives into G.
Zero-allocation version of gradient for use in optimization loops.
Examples
itp = cubic_interp((x, y), data)
G = zeros(2)
gradient!(G, itp, (0.5, 0.5)) # G .= (∂f/∂x, ∂f/∂y)
gradient!(G, itp, [0.5, 0.5]) # G .= (∂f/∂x, ∂f/∂y)
# Optim.jl compatible:
grad!(G, x) = gradient!(G, itp, x)
result = optimize(f, grad!, x0, LBFGS())FastInterpolations.hessian — Function
hessian(itp::AbstractInterpolantND, query)Compute the Hessian matrix (matrix of second partial derivatives) at query.
Returns an N×N matrix where H[i,j] = ∂²f/∂xᵢ∂xⱼ.
Performance
~9x faster than ForwardDiff.hessian by using analytical derivatives. Exploits symmetry: computes only N(N+1)/2 unique elements. Uses locate-once optimization: interval search performed only once per query point.
Examples
itp = cubic_interp((x, y), data)
H = hessian(itp, (0.5, 0.5))
# H = [∂²f/∂x² ∂²f/∂x∂y]
# [∂²f/∂x∂y ∂²f/∂y² ]FastInterpolations.hessian! — Function
hessian!(H, itp::AbstractInterpolantND, query)Compute the Hessian matrix in-place, writing second partial derivatives into H.
Zero-allocation version of hessian for use in optimization loops. Exploits symmetry: computes only N(N+1)/2 unique elements.
Examples
itp = cubic_interp((x, y), data)
H = zeros(2, 2)
hessian!(H, itp, (0.5, 0.5))
# Optim.jl compatible:
hess!(H, x) = hessian!(H, itp, x)
result = optimize(f, grad!, hess!, x0, NewtonTrustRegion())FastInterpolations.laplacian — Function
laplacian(itp::AbstractInterpolantND, query)Compute the Laplacian (sum of second partial derivatives) at query.
Returns a scalar: ∇²f = ∂²f/∂x₁² + ∂²f/∂x₂² + ... + ∂²f/∂xₙ²
Performance
Faster than computing full Hessian when only the trace is needed. Uses locate-once optimization: interval search performed only once per query point.
Examples
itp = cubic_interp((x, y), data)
∇²f = laplacian(itp, (0.5, 0.5)) # ∂²f/∂x² + ∂²f/∂y²
# Equivalent to (but faster than):
# tr(hessian(itp, (0.5, 0.5)))Applications
- Heat equation: ∂T/∂t = α∇²T
- Wave equation: ∂²u/∂t² = c²∇²u
- Poisson equation: ∇²φ = ρ
Boundary Conditions
Cubic Splines (BCPair)
FastInterpolations.AbstractBC — Type
AbstractBCAbstract base type for all boundary condition specifications. Type-free design: no type parameter on the abstract type. Concrete subtypes with values (Deriv1, Deriv2, Deriv3) carry their own Tv parameter.
Subtypes
NaturalBC: Natural BC (zero curvature at both ends) - singletonClampedBC: Clamped BC (zero slope at both ends) - singletonPeriodicBC: Periodic boundary condition - singletonPointBC: Single-point derivative conditions (abstract)BCPair{L,R}: Pair of left/right boundary conditionsLeft{B}: Endpoint wrapper for BC at left (x[1]) - used by quadratic splinesRight{B}: Endpoint wrapper for BC at right (x[end]) - used by quadratic splines
FastInterpolations.PointBC — Type
PointBC <: AbstractBCAbstract type for single-point boundary conditions. Represents a derivative condition at one endpoint. Type-free design: concrete subtypes carry their own Tv parameter.
Subtypes
Deriv1{Tv}: First derivative (slope) BCDeriv2{Tv}: Second derivative (curvature) BCDeriv3{Tv}: Third derivative BCPolyFit{D}: Polynomial fit (lazy, no Tv until materialization)
FastInterpolations.Deriv1 — Type
Deriv1{Tv} <: PointBCFirst derivative (slope) boundary condition: S'(endpoint) = val
The type parameter Tv is the value type, supporting both Real and Complex.
Example
Deriv1(0.5) # Slope of 0.5 at endpoint (Float64)
Deriv1(0) # Zero slope (horizontal tangent)
Deriv1(1.0+2.0im) # Complex slope (ComplexF64)FastInterpolations.Deriv2 — Type
Deriv2{Tv} <: PointBCSecond derivative (curvature) boundary condition: S''(endpoint) = val
The type parameter Tv is the value type, supporting both Real and Complex.
Example
Deriv2(0) # Natural BC (zero curvature)
Deriv2(1.5) # Specified curvature at endpoint
Deriv2(0.0+0.0im) # Complex curvatureFastInterpolations.Deriv3 — Type
Deriv3{Tv} <: PointBCThird derivative boundary condition: S'''(endpoint) = val
For cubic splines, the third derivative is constant within each interval: S'''(x) = (z[i+1] - z[i]) / h[i]. This BC specifies the third derivative value at the first (or last) interval.
The type parameter Tv is the value type, supporting both Real and Complex.
Example
Deriv3(0) # Zero third derivative at endpoint
Deriv3(1.0) # Specified third derivative
Deriv3(0.0+0.0im) # Complex third derivativeFastInterpolations.BCPair — Type
BCPair{L<:PointBC, R<:PointBC} <: AbstractBCContainer for left and right boundary conditions with type parameters for zero-overhead dispatch. The BC types are encoded in the type parameters, enabling compile-time specialization.
Type-free design: no Tv parameter on BCPair itself. The value type is determined by the concrete L and R types (e.g., BCPair{Deriv1{Float64}, Deriv2{Float64}}).
Type Parameters
L: Left boundary condition type (Deriv1{Tv}, Deriv2{Tv}, PolyFit{D}, etc.)R: Right boundary condition type (Deriv1{Tv}, Deriv2{Tv}, PolyFit{D}, etc.)
Example
bc = BCPair(Deriv1(0.5), Deriv2(0)) # Left: slope=0.5, Right: natural
bc = BCPair(Deriv1(1.0+0.0im), Deriv2(0.0im)) # Complex BC
bc = BCPair(CubicFit(), Deriv2(0.0)) # Mixed: lazy left, concrete rightFastInterpolations.NaturalBC — Type
NaturalBC <: AbstractBCNatural boundary condition: S''(endpoints) = 0 (zero curvature at both ends). Equivalent to BCPair(Deriv2(0), Deriv2(0)).
This is a singleton type (structure-only). Normalized to BCPair with Deriv2(zero(Tv)) at both ends based on the value type during interpolant construction.
Example
itp = cubic_interp(x, y; bc=NaturalBC()) # Default
itp = cubic_interp(x, y) # Same as aboveFastInterpolations.ClampedBC — Type
ClampedBC <: AbstractBCClamped boundary condition: S'(endpoints) = 0 (zero slope at both ends). Equivalent to BCPair(Deriv1(0), Deriv1(0)).
This is a singleton type (structure-only). Normalized to BCPair with Deriv1(zero(Tv)) at both ends based on the value type during interpolant construction.
Example
itp = cubic_interp(x, y; bc=ClampedBC())FastInterpolations.PeriodicBC — Type
PeriodicBC <: AbstractBCPeriodic boundary condition: S(x0) = S(xn), S'(x0) = S'(xn), S''(x0) = S''(xn)
This is a singleton type (structure-only, no value parameter). Internally, periodic BC uses Sherman-Morrison solver with PeriodicData{T} for the cache.
Example
cache = CubicSplineCache(x; bc=PeriodicBC())PolyFit: Polynomial Fitting BCs
FastInterpolations.PolyFit — Type
PolyFit{D} <: PointBCGeneric polynomial fitting boundary condition (lazy).
Fits a degree-D polynomial through (D+1) points at the endpoint and evaluates its derivative. This automatically estimates the first derivative from data without requiring user-specified values.
This is a lazy type with no value parameter. The actual derivative value is computed during materialize_bc() based on the data's value type (Tv).
Type Parameters
D::Int: Polynomial degree (1=linear, 2=quadratic, 3=cubic, ...)
Relationships
Points needed = D + 1
Accuracy = O(h^D) for smooth functionsAliases (Recommended for common cases)
LinearFit=PolyFit{1}→ 2 points, O(h)QuadraticFit=PolyFit{2}→ 3 points, O(h²)CubicFit=PolyFit{3}→ 4 points, O(h³)
Mathematical Background
All polynomial fitting methods are mathematically equivalent to finite difference formulas of the same order. For example, CubicFit (4-point) gives identical coefficients to 4-point one-sided finite difference:
- Left:
f'(x₁) ≈ (-11f₁ + 18f₂ - 9f₃ + 2f₄) / (6h) - Right:
f'(xₙ) ≈ (-2fₙ₋₃ + 9fₙ₋₂ - 18fₙ₋₁ + 11fₙ) / (6h)
Key Property
Polynomial Reproduction: PolyFit{D} exactly reproduces polynomials up to degree D.
Example
# Recommended: use named aliases
itp = cubic_interp(x, y; bc=CubicFit())
itp = quadratic_interp(x, y; bc=Left(QuadraticFit()))
# Generic form (equivalent)
itp = cubic_interp(x, y; bc=PolyFit{3}())See also: LinearFit, QuadraticFit, CubicFit, Deriv1
FastInterpolations.LinearFit — Type
LinearFit = PolyFit{1}2-point linear fit boundary condition. Estimates derivative using forward/backward difference: f'(x) ≈ (f₂ - f₁) / h.
Accuracy: O(h) - first order. Points needed: 2
Example
itp = cubic_interp(x, y; bc=LinearFit())FastInterpolations.QuadraticFit — Type
QuadraticFit = PolyFit{2}3-point quadratic fit boundary condition. Fits a parabola through 3 points and evaluates its derivative at the endpoint.
Accuracy: O(h²) - second order. Points needed: 3
For uniform grids: f'(x₁) ≈ (-3f₁ + 4f₂ - f₃) / (2h)
Key Property
Polynomial Reproduction: Exactly reproduces quadratic polynomials.
Example
# Default BC for quadratic splines
itp = quadratic_interp(x, y; bc=Left(QuadraticFit()))FastInterpolations.CubicFit — Type
CubicFit = PolyFit{3}4-point cubic fit boundary condition. Fits a cubic polynomial through 4 points and evaluates its derivative at the endpoint.
Accuracy: O(h³) - third order. Points needed: 4
For uniform grids:
- Left:
f'(x₁) ≈ (-11f₁ + 18f₂ - 9f₃ + 2f₄) / (6h) - Right:
f'(xₙ) ≈ (-2fₙ₋₃ + 9fₙ₋₂ - 18fₙ₋₁ + 11fₙ) / (6h)
Key Property
Polynomial Reproduction: Exactly reproduces cubic polynomials.
Example
# Recommended BC for cubic splines when derivative is unknown
itp = cubic_interp(x, y; bc=CubicFit())
# Mixed with other BCs
itp = cubic_interp(x, y; bc=BCPair(CubicFit(), Deriv2(0)))FastInterpolations.ParabolaFit — Function
ParabolaFitDeprecated alias for QuadraticFit.
Endpoint Wrappers (Quadratic Splines)
FastInterpolations.Left — Type
Left{B<:PointBC} <: AbstractBCWrapper indicating BC is applied at left endpoint (x[1]). Used for quadratic splines where only one endpoint BC is specified.
The type parameter B is the inner PointBC type, which carries the value type Tv for concrete types (Deriv1{Tv}, etc.) or just the degree D for lazy types (PolyFit{D}).
Example
bc = Left(Deriv1(0.5)) # slope = 0.5 at left endpoint
bc = Left(Deriv2(0.0)) # curvature = 0 at left endpoint
bc = Left(Deriv1(1.0+2.0im)) # Complex slope
bc = Left(QuadraticFit()) # Lazy polynomial fitFastInterpolations.Right — Type
Right{B<:PointBC} <: AbstractBCWrapper indicating BC is applied at right endpoint (x[end]). Used for quadratic splines where only one endpoint BC is specified.
The type parameter B is the inner PointBC type, which carries the value type Tv for concrete types (Deriv1{Tv}, etc.) or just the degree D for lazy types (PolyFit{D}).
Example
bc = Right(Deriv1(2.0)) # slope = 2.0 at right endpoint
bc = Right(Deriv2(0.0)) # curvature = 0 at right endpoint
bc = Right(Deriv1(1.0+2.0im)) # Complex slope
bc = Right(QuadraticFit()) # Lazy polynomial fitSearch Policies
Search policies control how the interpolant finds the correct interval for a query point. Different policies offer trade-offs between simplicity, performance for sequential queries, and thread safety.
FastInterpolations.AbstractSearchPolicy — Type
AbstractSearchPolicyAbstract supertype for user-facing search policy selection. Concrete subtypes encode the search algorithm choice.
See also: Binary, HintedBinary, LinearBinary
FastInterpolations.Binary — Type
Binary <: AbstractSearchPolicyBinary search algorithm. O(log n) per query for vectors, O(1) for ranges. Stateless and thread-safe. This is the default search policy.
Hint Behavior
When a hint argument is provided with Binary(), the search automatically upgrades to HintedBinary behavior to utilize the hint. Without a hint, pure binary search is used.
Example
val = linear_interp(x, y, 0.5; search=Binary()) # pure binary search
val = linear_interp(x, y, 0.5) # same (default)
# With hint: auto-upgrades to HintedBinary behavior
hint = Ref(1)
val = itp(0.5; search=Binary(), hint=hint) # uses hinted binary internallySee also: HintedBinary, LinearBinary
FastInterpolations.HintedBinary — Type
HintedBinary <: AbstractSearchPolicyHinted binary search: O(1) if query hits cached interval, O(log n) fallback. Useful when queries repeatedly access the same interval region.
Example
itp = linear_interp(x, y)
vals = itp(query_points; search=HintedBinary())FastInterpolations.Linear — Type
Linear <: AbstractSearchPolicyPure linear search for strictly monotonic query sequences. Maximum speed with no binary fallback and minimal bounds checking.
Safety Contract (User Responsibility)
Preconditions that MUST be satisfied:
- Queries must be monotonically ordered (all increasing OR all decreasing)
- All queries must satisfy
x[1] <= xi <= x[end](within interpolation domain)
If violated: Undefined behavior (infinite loop or out-of-bounds access)
Performance Characteristics
- Best case: O(1) per query (consecutive intervals)
- Amortized: O(1) for properly monotonic sequences
- Worst case: O(n) if sequence is not monotonic
When to Use
- ODE integration with strictly monotonic time stepping
- Streaming data evaluation with guaranteed ordering
- Performance-critical loops where ALL inputs are controlled
When NOT to Use
- Random access patterns (use
Binary) - Queries that might exceed domain bounds (use
LinearBinary) - Untrusted input data (use
LinearBinary)
Example
# ODE-style monotonic evaluation
hint = Ref(1)
for t in t_values # strictly increasing
y = itp(t; search=Linear(), hint=hint)
endSee also: LinearBinary, Binary, HintedBinary
FastInterpolations.LinearBinary — Type
LinearBinary{MAX} <: AbstractSearchPolicyBounded linear search within a window of MAX positions from hint, then binary fallback. Optimal for sorted/monotonic query sequences where consecutive queries tend to fall in adjacent or nearby intervals.
Type Parameter
MAX::Int: Size of the linear search window before falling back to binary search. This is a compile-time constant encoded in the type parameter.
Performance Characteristics
- Best case: O(1) when query is within
MAXpositions of the hint - Worst case: O(log n) binary search fallback
- Ideal for: Sorted queries, time-series data, streaming evaluations
Construction
Use the factory function (recommended) to construct with a curated set of values:
LinearBinary() # default MAX=8
LinearBinary(linear_window=4) # custom MAX=4Or construct the parametric type directly (advanced):
LinearBinary{8}() # explicit type parameterExample
sorted_queries = sort(rand(1000))
vals = linear_interp(x, y, sorted_queries; search=LinearBinary(linear_window=8))See also: Binary, HintedBinary
Series Interpolant Types
SeriesInterpolant stores multiple y-series in a unified matrix with point-contiguous layout for optimal SIMD performance on scalar queries (10-120× faster than composition-based approaches).
Constant Interpolation
FastInterpolations.ConstantSeriesInterpolant — Type
ConstantSeriesInterpolant{Tg, Tv, P, X}Multi-series constant (step) interpolant with unified matrix storage and SIMD optimization. Shares a single x-grid across N y-series for efficient batch evaluation.
Type Parameters
Tg: Grid type (Float32 or Float64)Tv: Value type (Tg for real, Complex{Tg} for complex)P: Search policy typeX: Grid container type (Vector or Range)
Fields
x::X: Shared x-grid (Vector or Range)y::Matrix{Tv}: Function values (npoints × nseries) series-contiguous_transpose::LazyTranspose{Tv}: Lazy point-contiguous layout for scalar SIMDextrap::ExtrapVal: Extrapolation modeside::SideVal: Side selection (:nearest, :left, :right)
Memory Layout
Primary storage is series-contiguous (npoints × nseries):
y[i, k]= value of series k at grid point iy[:, k]is contiguous → optimal for vector queries
Lazy transpose (nseries × npoints) for scalar queries:
y_point[:, i]is contiguous → optimal for SIMD scalar queries
Usage
x = collect(range(0.0, 1.0, 101))
y1, y2, y3 = sin.(2π .* x), cos.(2π .* x), exp.(-x)
sitp = constant_interp(x, [y1, y2, y3])
# Scalar evaluation
vals = sitp(0.5) # Returns Vector{Float64} of length 3
sitp(output, 0.5) # In-place
# Vector evaluation
vals = sitp([0.1, 0.5, 0.9]) # Returns Vector of Vectors
sitp([out1, out2, out3], xq) # In-place (zero allocation)
# Complex values are also supported
y_complex = [exp.(2im * π * x), (1.0+2.0im) .* x]
sitp_complex = constant_interp(x, y_complex)Implementation Note: mutable struct with const fields
This type uses mutable struct with all const fields (Julia 1.8+) instead of plain struct for performance reasons. See CubicSeriesInterpolant for details.
Linear Interpolation
FastInterpolations.LinearSeriesInterpolant — Type
LinearSeriesInterpolant{Tg, Tv, P, X}Multi-series linear interpolant with unified matrix storage and SIMD optimization. Shares a single x-grid across N y-series for efficient batch evaluation.
Type Parameters
Tg: Grid type (Float32 or Float64)Tv: Value type (Tg for real, Complex{Tg} for complex)P: Search policy typeX: Grid container type (Vector or Range)
Fields
x::X: Shared x-grid (Vector or Range)y::Matrix{Tv}: Function values (npoints × nseries) series-contiguous_transpose::LazyTranspose{Tv}: Lazy point-contiguous layout for scalar SIMDextrap::ExtrapVal: Extrapolation mode
Memory Layout
Primary storage is series-contiguous (npoints × nseries):
y[i, k]= value of series k at grid point iy[:, k]is contiguous → optimal for vector queries
Lazy transpose (nseries × npoints) for scalar queries:
y_point[:, i]is contiguous → optimal for SIMD scalar queries
Usage
x = collect(range(0.0, 1.0, 101))
y1, y2, y3 = sin.(2π .* x), cos.(2π .* x), exp.(-x)
sitp = linear_interp(x, [y1, y2, y3])
# Scalar evaluation
vals = sitp(0.5) # Returns Vector{Float64} of length 3
sitp(output, 0.5) # In-place
# Vector evaluation
vals = sitp([0.1, 0.5, 0.9]) # Returns Vector of Vectors
sitp([out1, out2, out3], xq) # In-place (zero allocation)
# Complex values are also supported
y_complex = [exp.(2im * π * x), (1.0+2.0im) .* x]
sitp_complex = linear_interp(x, y_complex)Performance
- Vector queries use series-contiguous layout directly
- Scalar queries trigger lazy transpose on first call
Implementation Note: mutable struct with const fields
This type uses mutable struct with all const fields (Julia 1.8+) instead of plain struct for performance reasons. See CubicSeriesInterpolant for details.
Quadratic Interpolation
FastInterpolations.QuadraticSeriesInterpolant — Type
QuadraticSeriesInterpolant{Tg, Tv, P, X}Multi-series quadratic spline interpolant with unified matrix storage and SIMD optimization. Shares a single x-grid across N y-series for efficient batch evaluation.
Type Parameters
Tg: Grid type (Float32 or Float64)Tv: Value type (Tg for real, Complex{Tg} for complex)P: Search policy typeX: Grid container type (Vector or Range)
Fields
x::X: Grid points (sorted, Vector or Range)y::Matrix{Tv}: Function values (npoints × nseries) series-contiguousa::Matrix{Tv}: Quadratic coefficients (npoints × nseries) series-contiguousd::Matrix{Tv}: Slope coefficients (npoints × nseries) series-contiguoush::Vector{Tg}: Grid spacing (shared across all series, always real)_transpose::LazyTransposeTriple{Tv}: Lazy point-contiguous layout for SIMDextrap::ExtrapVal: Extrapolation mode
Memory Layout
Primary storage is series-contiguous (npoints × nseries):
y[i, k]= value of series k at grid point iy[:, k]is contiguous → optimal for vector queries
Lazy transpose (nseries × npoints) for scalar queries:
y_point[:, i]is contiguous → optimal for SIMD scalar queries
Usage
x = collect(range(0.0, 1.0, 101))
y1, y2, y3 = sin.(2π .* x), cos.(2π .* x), exp.(-x)
sitp = quadratic_interp(x, [y1, y2, y3])
# Scalar evaluation
vals = sitp(0.5) # Returns Vector{Float64} of length 3
sitp(output, 0.5) # In-place
# Vector evaluation
vals = sitp([0.1, 0.5, 0.9]) # Returns Vector of Vectors
sitp([out1, out2, out3], xq) # In-place (zero allocation)
# Derivatives
d1 = sitp(0.5; deriv=1) # First derivatives
d2 = sitp(0.5; deriv=2) # Second derivatives
# Complex values are also supported
y_complex = [exp.(2im * π * x), (1.0+2.0im) .* x]
sitp_complex = quadratic_interp(x, y_complex)Performance
- Vector queries use series-contiguous layout directly
- Scalar queries trigger lazy transpose on first call
- All series share same h[] array (O(1) memory overhead)
Implementation Note: mutable struct with const fields
This type uses mutable struct with all const fields (Julia 1.8+) instead of plain struct for performance reasons. See CubicSeriesInterpolant for details.
Cubic Interpolation
FastInterpolations.CubicSeriesInterpolant — Type
CubicSeriesInterpolant{Tg, Tv, C, B}Multi-series cubic spline interpolant with unified matrix storage and SIMD optimization. Shares a single x-grid across N y-series for efficient batch evaluation.
Type Parameters
Tg: Grid coordinate type (Float32 or Float64) - always realTv: Value type (real or Complex{Tg})C: Cache type (CubicSplineCache{Tg})B: Boundary condition config type (BCPair or PeriodicData)
Fields
cache::C: Shared CubicSplineCache with LU factorizationbc_for_solve::B: BC configuration for solving systemsy::Matrix{Tv}: Function values (npoints × nseries) series-contiguousz::Matrix{Tv}: Second derivatives (npoints × nseries) series-contiguous_point_snapshot: Atomic field for lazy point-contiguous layoutextrap::ExtrapVal: Extrapolation mode
Memory Layout
Primary storage is series-contiguous (npoints × nseries):
y[i, k]= value of series k at grid point iy[:, k]is contiguous → optimal for vector queries
Lazy transpose (nseries × npoints) for scalar queries:
y_point[:, i]is contiguous → optimal for SIMD scalar queries
Usage
x = collect(range(0.0, 1.0, 101))
y1, y2, y3 = sin.(2π .* x), cos.(2π .* x), exp.(-x)
sitp = cubic_interp(x, [y1, y2, y3])
# Scalar evaluation
vals = sitp(0.5) # Returns Vector{Float64} of length 3
sitp(output, 0.5) # In-place
# Vector evaluation
vals = sitp([0.1, 0.5, 0.9]) # Returns Vector of Vectors
sitp([out1, out2, out3], xq) # In-place (zero allocation)
# Complex values
y_complex = exp.(2im .* π .* x)
sitp_c = cubic_interp(x, [y_complex]) # CubicSeriesInterpolant{Float64, ComplexF64, ...}Performance
- Vector queries use series-contiguous layout directly
- Scalar queries trigger lazy transpose on first call
- All series share same cache (O(1) memory overhead)
Implementation Note: mutable struct with const fields
This type uses mutable struct with all const fields (Julia 1.8+) instead of plain struct for performance reasons. The const annotation ensures fields cannot be reassigned while allowing heap allocation. This pattern provides:
- Stable memory addresses for the compiler to optimize field access
- Better inlining of field accesses compared to plain immutable structs
- Compatibility with mutable inner types (LazyTransposePair with @atomic)
Benchmarks show ~15% regression when using plain struct instead.
FastInterpolations.precompute_transpose! — Function
precompute_transpose!(lt::LazyTranspose, src::Matrix) -> LazyTransposePre-compute transpose before hot loops. Returns the holder for chaining.
precompute_transpose!(ltp::LazyTransposePair, y::Matrix, z::Matrix) -> LazyTransposePairPre-compute transpose pair before hot loops. Returns the holder for chaining.
precompute_transpose!(ltt::LazyTransposeTriple, y::Matrix, a::Matrix, d::Matrix) -> LazyTransposeTriplePre-compute transpose triple before hot loops. Returns the holder for chaining.
precompute_transpose!(sitp::LinearSeriesInterpolant) -> sitpPre-allocate point-contiguous matrix for scalar queries. Call before hot loops to avoid first-call latency.
precompute_transpose!(sitp::ConstantSeriesInterpolant) -> sitpPre-allocate point-contiguous matrix for scalar queries. Call before hot loops to avoid first-call latency.
precompute_transpose!(sitp::CubicSeriesInterpolant) -> sitpPre-allocate point-contiguous matrices for scalar queries. Call before hot loops to avoid first-call latency.
Index
FastInterpolations.AbstractBCFastInterpolations.AbstractCoeffStrategyFastInterpolations.AbstractDerivativeViewFastInterpolations.AbstractEvalOpFastInterpolations.AbstractInterpolantFastInterpolations.AbstractInterpolantNDFastInterpolations.AbstractSearchPolicyFastInterpolations.AbstractSeriesInterpolantFastInterpolations.BCPairFastInterpolations.BinaryFastInterpolations.ClampedBCFastInterpolations.ConstantInterpolantFastInterpolations.ConstantInterpolantNDFastInterpolations.ConstantSeriesInterpolantFastInterpolations.CubicFitFastInterpolations.CubicInterpolantFastInterpolations.CubicInterpolantNDFastInterpolations.CubicSeriesInterpolantFastInterpolations.CubicSplineCacheFastInterpolations.Deriv1FastInterpolations.Deriv2FastInterpolations.Deriv3FastInterpolations.DerivativeViewFastInterpolations.EvalDeriv1FastInterpolations.EvalDeriv2FastInterpolations.EvalDeriv3FastInterpolations.EvalValueFastInterpolations.HintedBinaryFastInterpolations.LeftFastInterpolations.LinearFastInterpolations.LinearBinaryFastInterpolations.LinearFitFastInterpolations.LinearInterpolantFastInterpolations.LinearInterpolantNDFastInterpolations.LinearSeriesInterpolantFastInterpolations.MinCurvFitFastInterpolations.NaturalBCFastInterpolations.OnTheFlyFastInterpolations.PeriodicBCFastInterpolations.PointBCFastInterpolations.PolyFitFastInterpolations.PreComputeFastInterpolations.QuadraticFitFastInterpolations.QuadraticInterpolantFastInterpolations.QuadraticInterpolantNDFastInterpolations.QuadraticSeriesInterpolantFastInterpolations.RightFastInterpolations.ParabolaFitFastInterpolations.clear_cubic_cache!FastInterpolations.constant_interpFastInterpolations.constant_interp!FastInterpolations.cubic_interpFastInterpolations.cubic_interp!FastInterpolations.deriv1FastInterpolations.deriv2FastInterpolations.deriv3FastInterpolations.deriv_viewFastInterpolations.eval_typeFastInterpolations.get_cubic_cache_sizeFastInterpolations.gradientFastInterpolations.gradient!FastInterpolations.grid_typeFastInterpolations.hessianFastInterpolations.hessian!FastInterpolations.laplacianFastInterpolations.linear_interpFastInterpolations.linear_interp!FastInterpolations.precompute_transpose!FastInterpolations.quadratic_interpFastInterpolations.quadratic_interp!FastInterpolations.set_cubic_cache_size!FastInterpolations.value_type