InterpN
Writeup | Repo | Python Docs | Rust Docs
N-dimensional interpolation/extrapolation methods, no-std and no-alloc compatible, prioritizing correctness, performance, and compatibility with memory-constrained environments.
Available as a rust crate and python library.
Features
| Feature → ↓ Interpolant Method |
Regular Grid |
Rectilinear Grid |
Json Serialization |
Thread Parallelism |
|---|---|---|---|---|
| Nearest-Neighbor | ✅ | ✅ | ✅ | ✅ |
| Linear | ✅ | ✅ | ✅ | ✅ |
| Cubic Hermite | ✅ | ✅ | ✅ | ✅ |
| Cubic B-spline | ✅ | ✅ | ✅ | ✅ |
The methods provided here, while more limited in scope than scipy's,
- are significantly faster under most conditions
- use almost no RAM (and perform no heap allocations at all)
- produce significantly improved floating-point error (by several orders of magnitude)
- are json-serializable using Pydantic
- can also be used easily in web and embedded applications via the Rust library
- are permissively licensed
For larger jobs such as image processing, the non-allocating evaluation pattern results in a nearly-linear thread speedup, limited only by thread spawning overhead and memory bandwidth.
See here for more info about quality-of-fit, throughput, and memory usage.
Installation
pip install interpn
Profile-Guided Optimization
To build the extension with profile-guided optimization, do sh ./scripts/distr_pgo.sh
after installing this extra compiler dependency:
rustup component add llvm-tools-preview
An LLVM install matching the version used by rustc is also required for doing PGO;
see the ./scripts/distr_pgo.sh or CI workflows for the exact version.
Rust Examples
Regular Grid
use interpn::{multilinear, multicubic};
// Define a grid
let x = [1.0_f64, 2.0, 3.0, 4.0];
let y = [0.0_f64, 1.0, 2.0, 3.0];
// Grid input for rectilinear method
let grids = &[&x[..], &y[..]];
// Grid input for regular grid method
let dims = [x.len(), y.len()];
let starts = [x[0], y[0]];
let steps = [x[1] - x[0], y[1] - y[0]];
// Values at grid points
let z = [2.0; 16];
// Observation points to interpolate/extrapolate
let xobs = [0.0_f64, 5.0];
let yobs = [-1.0, 3.0];
let obs = [&xobs[..], &yobs[..]];
// Storage for output
let mut out = [0.0; 2];
// Do interpolation
multilinear::regular::interpn(&dims, &starts, &steps, &z, &obs, &mut out);
multicubic::regular::interpn(&dims, &starts, &steps, &z, false, &obs, &mut out);
Rectilinear Grid
use interpn::{multilinear, multicubic};
// Define a grid
let x = [1.0_f64, 2.0, 3.0, 4.0];
let y = [0.0_f64, 1.0, 2.0, 3.0];
// Grid input for rectilinear method
let grids = &[&x[..], &y[..]];
// Values at grid points
let z = [2.0; 16];
// Points to interpolate/extrapolate
let xobs = [0.0_f64, 5.0];
let yobs = [-1.0, 3.0];
let obs = [&xobs[..], &yobs[..]];
// Storage for output
let mut out = [0.0; 2];
// Do interpolation
multilinear::rectilinear::interpn(grids, &z, &obs, &mut out).unwrap();
multicubic::rectilinear::interpn(grids, &z, false, &obs, &mut out).unwrap();
Python Examples
Available Methods
import interpn
import numpy as np
# Build grid
x = np.linspace(0.0, 10.0, 5)
y = np.linspace(20.0, 30.0, 4)
grids = [x, y]
xgrid, ygrid = np.meshgrid(x, y, indexing="ij")
zgrid = (xgrid + 2.0 * ygrid) # Values at grid points
# Grid inputs for true regular grid
dims = [x.size, y.size]
starts = np.array([x[0], y[0]])
steps = np.array([x[1] - x[0], y[1] - y[0]])
# Initialize different interpolators
# Call like `linear_regular.eval([xs, ys])`
linear_regular = interpn.MultilinearRegular.new(dims, starts, steps, zgrid)
cubic_regular = interpn.MulticubicRegular.new(dims, starts, steps, zgrid)
linear_rectilinear = interpn.MultilinearRectilinear.new(grids, zgrid)
cubic_rectilinear = interpn.MulticubicRectilinear.new(grids, zgrid)
Multilinear Interpolation
import interpn
import numpy as np
# Build grid
x = np.linspace(0.0, 10.0, 5)
y = np.linspace(20.0, 30.0, 4)
xgrid, ygrid = np.meshgrid(x, y, indexing="ij")
zgrid = (xgrid + 2.0 * ygrid) # Values at grid points
# Grid inputs for true regular grid
dims = [x.size, y.size]
starts = np.array([x[0], y[0]])
steps = np.array([x[1] - x[0], y[1] - y[0]])
# Observation points pointed back at the grid
obs = [xgrid.flatten(), ygrid.flatten()]
# Initialize
interpolator = interpn.MultilinearRegular.new(dims, starts, steps, zgrid.flatten())
# Interpolate
out = interpolator.eval(obs)
# Check result
assert np.allclose(out, zgrid.flatten(), rtol=1e-13)
# Serialize and deserialize
roundtrip_interpolator = interpn.MultilinearRegular.model_validate_json(
interpolator.model_dump_json()
)
out2 = roundtrip_interpolator.eval(obs)
# Check result from roundtrip serialized/deserialized interpolator
assert np.all(out == out2)
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Metadata
Release files for interpn 0.11.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| interpn-0.11.2.tar.gz | 2.0 MB | Without provenance | Details for interpn-0.11.2.tar.gz |
Built distributions (wheels)
Total release size: 18.4 MB
Release files / interpn-0.11.2.tar.gz
| Download URL | interpn-0.11.2.tar.gz |
|---|---|
| Size | 2.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e69afe45f674e35c33f535fd63b42dbb74a46bb4ef9bd39e9d86be74ead414ea
|
|
BLAKE2b-256 checksum How to use checksums |
6d513f2f80f1dd80d43f0aa83ea00b8c747e5d9a076189c8111aa50d16772591
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-win_amd64.whl
| Download URL | interpn-0.11.2-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
81864516d4163876c692f344a6f30474af6f3e1aa3c9d1b9c28dc402b6087b0c
|
|
BLAKE2b-256 checksum How to use checksums |
386706a86d38ddff0d2f477f22259ad331f2ac92a9d66056af01e7305bc77dcf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-win32.whl
| Download URL | interpn-0.11.2-cp310-abi3-win32.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
a854b51008b30450a37c720beaf13163beeaf06266a9b37994034e1d63a7143a
|
|
BLAKE2b-256 checksum How to use checksums |
6f83fcf4da0c9967e04d419dd19ceb2a6788eef2e83b3144e7cb58391df276b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | interpn-0.11.2-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e52d28ba877f0d655bb65fcd1842edfc148f8e1ff4e13bab4474b12fdb51589e
|
|
BLAKE2b-256 checksum How to use checksums |
126bda47f11ca0fcaeb2689b300df79068dfe59eb96035c7756572098b0e57bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-musllinux_1_2_i686.whl
| Download URL | interpn-0.11.2-cp310-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
1899e651d8b3f2e868054573e133cdde0c26dada6c897af2b00da455a4e075cd
|
|
BLAKE2b-256 checksum How to use checksums |
7aa24339c75a68f2979bfcfaf1c30d5389a221c2250999c86cf49d8263a692c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-musllinux_1_2_armv7l.whl
| Download URL | interpn-0.11.2-cp310-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
d4cf1a37c9372ebddc79ad8690edd9e63a07ecea6b9406c358b51ece65084784
|
|
BLAKE2b-256 checksum How to use checksums |
0e7f6238328ff719ca9781ccba793fb168b4d9117bb40e37177aa0208d066996
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | interpn-0.11.2-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
8cc1a67d088a732e69586af048fc82ea99576025a6474034189e7b320e7d4241
|
|
BLAKE2b-256 checksum How to use checksums |
9c9e4aa8fd5d1a8e3271cfb14daa242c306dfa52282e45c6b1ff220cdc7349bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | interpn-0.11.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
5210d31dcb9b868fa030239a2ec1e66c58b622860f01b62889176629d8582d2f
|
|
BLAKE2b-256 checksum How to use checksums |
0befeb44039eaf064418c23a979c67978089765a4e824cfb43a4897075e7c235
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | interpn-0.11.2-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
06a175b0680bbcec4b9e606a2354c4a4ee1c2117a05a8a71667d0af5416dcbe3
|
|
BLAKE2b-256 checksum How to use checksums |
4bbc7bb88f09fdd2220855f4282d331feb59a7638ea99f7b82a4d715316f454c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | interpn-0.11.2-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
0e40d7f2bfc184670f1b93733a719d6e1ba01f000427edc0614f0ca649bc5671
|
|
BLAKE2b-256 checksum How to use checksums |
65d2df7fe7606fdc85cd1613ee6ebab379b55873483075a4812acde1fdb36aa3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | interpn-0.11.2-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
04787a1032d2dc4f2c5a351b2f32529203013cd1db0f2f39ff5439496ac02c8f
|
|
BLAKE2b-256 checksum How to use checksums |
d8142cdd820501155061d6b68694a078d18bb110212d34b6ea92c9f49972dbf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | interpn-0.11.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
9568fe99e852012bde1af25cba33b59af16d37707bf849183a268899212663dc
|
|
BLAKE2b-256 checksum How to use checksums |
d211e30227ac05c0282b19ec9e9f41b679f853801a5b63113c59074305aec5e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | interpn-0.11.2-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
33bc41740752f6d41916198c92c37325a1fc52342e391d951dec13074164f7f1
|
|
BLAKE2b-256 checksum How to use checksums |
71f877031c48be55be7faf3ed7f07748c7123c5a0e63530011359c93db086145
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / interpn-0.11.2-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | interpn-0.11.2-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
fbc883b911140570f63763d449c801ca250b188e82cd74f99c435de6481e9289
|
|
BLAKE2b-256 checksum How to use checksums |
83949b710054559c1c7e96007960929923396622b91ffcc36e68978a44156087
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Security for interpn 0.11.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.