Skip to content

Quick Reference

Data Format

Data must be an AbstractVector of point vectors, not a Matrix:

julia
using StaticArrays

# CORRECT: Vector of static vectors
points = [SVector{2}(rand(2)) for _ in 1:100]

# Converting from matrix
matrix = rand(100, 2)
points = [SVector{2}(row) for row in eachrow(matrix)]

# 3D points
points_3d = [SVector{3}(rand(3)) for _ in 1:100]

Basis Functions

TypeConstructorFormulaShape Parameter
Polyharmonic SplinePHS(n)None (scale-free)
Inverse MultiquadricIMQ(ε)Optional (default: 1)
GaussianGaussian(ε)Optional (default: 1)

PHS Orders

OrderConstructorSmoothnessUse Case
1PHS(1)C⁰Rough data
3PHS(3)General purpose (default)
5PHS(5)C⁴Smooth functions
7PHS(7)C⁶Very smooth functions

Polynomial Augmentation

julia
# Default: quadratic (poly_deg=2)
basis = PHS(3)

# Custom polynomial degree
basis = PHS(3; poly_deg=0)   # Constant only
basis = PHS(3; poly_deg=1)   # Linear
basis = PHS(3; poly_deg=3)   # Cubic
basis = PHS(3; poly_deg=-1)  # No polynomial (not recommended)

Operators

Creating Operators

julia
using RadialBasisFunctions, StaticArrays

points = [SVector{2}(rand(2)) for _ in 1:100]

# Differential operators
lap = laplacian(points)           # ∇²f (scalar output)
grad = gradient(points)           # ∇f (vector output)
∂x = partial(points, 1, 1)        # ∂f/∂x (1st order, dim 1)
∂²y = partial(points, 2, 2)       # ∂²f/∂y² (2nd order, dim 2)
∂v = directional(points, v)       # ∇f·v

# Interpolation operators
rg = regrid(source, target)       # Local interpolation

Applying Operators

julia
values = sin.(getindex.(points, 1))

# Apply to data
lap_values = lap(values)          # Vector of scalars
grad_values = grad(values)        # Matrix (N × dim)

Common Options

julia
# Custom basis
lap = laplacian(points; basis=PHS(5; poly_deg=3))

# Custom stencil size
lap = laplacian(points; k=30)

# Different evaluation points
lap = laplacian(points; eval_points=other_points)

# Precomputed neighbors
adjl = find_neighbors(points, k)
lap = laplacian(points; adjl=adjl)

Global Interpolation

julia
# Create interpolator (uses all points)
interp = Interpolator(points, values)

# Evaluate at single point
result = interp(SVector(0.5, 0.5))

# Evaluate at multiple points
results = interp(new_points)

Hermite Boundary Conditions

For PDE problems with boundary conditions:

julia
# Prepare boundary data
is_boundary = [is_on_boundary(p) for p in points]
bc = [Dirichlet() for _ in points]  # or Neumann(), Robin(α, β)
normals = [compute_normal(p) for p in points]

# Create operator with Hermite interpolation
lap = laplacian(
    points;
    hermite=(is_boundary=is_boundary, bc=bc, normals=normals)
)

Boundary Condition Types

TypeConstructorMeaning
DirichletDirichlet()Fixed value
NeumannNeumann()Fixed normal derivative
RobinRobin(α, β) 

GPU Evaluation

Weight computation currently runs on CPU. Once built, operators can be moved to GPU for fast evaluation:

julia
using CUDA, Adapt

# Build operator on CPU
lap = laplacian(points)

# Move to GPU for evaluation
lap_gpu = cu(lap)
values_gpu = cu(values)
result_gpu = lap_gpu(values_gpu)

Full GPU weight computation is planned — see #88.

Common Errors and Fixes

ErrorCauseFix
MethodError: no method matchingMatrix dataUse Vector{SVector}
n must be 1, 3, 5, or 7Invalid PHS orderUse odd integer ≤ 7
Shape parameter should be > 0Negative εUse positive ε (0.1-10.0)
SingularExceptionDuplicate points or bad stencilRemove duplicates, adjust k

Performance Tips

  1. Reuse adjacency lists for multiple operators on same points

  2. Use StaticArrays (SVector) for best performance

  3. Batch operations - create operator once, apply many times

  4. GPU for large problems — build operators on CPU, then cu(operator) for GPU evaluation