lutInterp
Generate C lookup-table interpolation code from Python callables — using integer-only arithmetic (no floating point at runtime) suitable for embedded targets (32-bit MCUs).
Complex math functions sometimes consume too much runtime on MCUs, need extra libraries and extra engineering. It's much simpler to do the math in python and produce a lookup table which can be interpolated, all with fix point arithmetic.
Installation
pip install lutinterp
What it does
Given a Python function, CInterpolator produces:
- A C coefficient array (
int8_t,int16_t, orint32_t) scaled to maximally fill the chosen integer type - A C function that approximates the original using only integer arithmetic and bit-shifts — no division, no floating point
The x-axis is parameterized with power-of-2 exponents so that table lookup is a single right-shift instruction.
Usage
import numpy as np
from lutinterp import CInterpolator
# Approximate sqrt over [0, 4096] with a linear LUT
lut = CInterpolator(
np.sqrt,
typ="linear",
coefResExp=16, # store coefficients as int16_t
xSupportPointsExp=4, # 2^4 = 16 segments
xRangeExp=12, # input range [0, 2^12] = [0, 4096]
xRangeSign="pos",
)
print(lut) # prints C code to stdout
lut.print_to_file("sqrt_lut.c") # or save to a file
Cubic spline
lut = CInterpolator(
np.sqrt,
typ="cubic",
coefResExp=16,
xSupportPointsExp=3,
xRangeExp=12,
xRangeSign="pos",
)
Visualise error
lut.plot_error() # relative error vs exact function
lut.plot_func() # overlay: linear / cubic / pchip / exact
Key parameters
| Parameter | Description |
|---|---|
typ |
'linear' or 'cubic' |
coefResExp |
Bit-width of coefficients (8, 16, or 32) |
xSupportPointsExp |
log2 of the number of LUT segments |
xRangeExp |
log2 of the input range |
xRangeSign |
'pos' → [0, 2^n], 'neg' → [2^n, 0], 'center' → [-2^n, +2^n] |
License
MIT — see LICENSE.
Metadata
Release files for lutinterp 0.1.1
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 |
|---|---|---|---|---|
| lutinterp-0.1.1.tar.gz | 6.8 kB | Without provenance | Details for lutinterp-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lutinterp-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for lutinterp-0.1.1-py3-none-any.whl |
Total release size: 14.3 kB
Release files / lutinterp-0.1.1.tar.gz
| Download URL | lutinterp-0.1.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69a9b8e90ee01b5c93c54e479702268a3a0630510ef7f101cf177676ad6da79b
|
|
BLAKE2b-256 checksum How to use checksums |
424710161ca993866d68230befdf3189e85aabc520b26792ebfbdee0bfe8641b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.4 {"installer":{"name":"uv","version":"0.11.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / lutinterp-0.1.1-py3-none-any.whl
| Download URL | lutinterp-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f63b8c43e83007ab413dddff971cd208791bf36b4cec9343115616c606bd41b6
|
|
BLAKE2b-256 checksum How to use checksums |
3be3c04f8631aa3bd891661d492a94d7cf29d466a7d9f23a8816773263fe594f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.4 {"installer":{"name":"uv","version":"0.11.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for lutinterp 0.1.1
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.