pyakima

Numba-compatible Akima spline interpolation.

pyakima is a fast, JIT-compatible Akima spline implementation written in pure Python.

Akima splines are a type of cubic spline that can guarantee continuous differentiability and local behavior while minimizing overshoot on both regular and irregular interpolation grids.

pyakima ships a small object-oriented Python API for ordinary use and Numba-friendly helper functions for building and evaluating splines inside fully jitted code.

The implementation is fully typed (py.typed) and keeps the public surface small: AkimaSpline is an object-oriented interface which simplifies calls for non-jitted Python callers; it has only a constructor and a __call__ method. For jitted workloads,

  1. The spline interpolation itself is represented as a set of coefficients stored in a SplineCoeffs object, computed once via make_akima_coeffs.

  2. The spline is called from cubic_call, which selects the appropriate coefficients and evaluates the polynomial with spline_single_knot_eval.

Static comparison of the pyakima non-rounded, akima, and makima corner models interpolating a step in the control points, showing how much each rounds the corner. Static comparison of the pyakima non-rounded, akima, and makima corner models interpolating a step in the control points, showing how much each rounds the corner.

See the Examples page for animated comparisons against SciPy on both uniform and irregular grids.

Installation

pip install pyakima

pyakima requires Python 3.10 or newer, NumPy, and Numba. The optional demo dependencies are available with:

pip install "pyakima[demos]"

Note that pygsl_lite from the demos dependencies may not always succeed on a pip install; any demo that uses it recovers gracefully if it cannot be imported. pyakima.demos.speed_demo can recover if none of the demos dependencies are present. pyakima.demos.step_demo runs if only matplotlib is present.

Quick Start

import numpy as np

from pyakima import AkimaSpline

x = np.linspace(0.0, 10.0, 16)
y = np.sin(x)

spline = AkimaSpline(x, y, corner_model="makima", ext=3)

print(spline(2.5))
print(spline(np.linspace(-1.0, 11.0, 1000)))

AkimaSpline is the ergonomic Python interface. The class stores a compiled coefficient bundle and dispatches scalar or vector evaluations to the fast helper functions.

Indices