This release is a pre-release and may not be stable for production use.
Toeplitz-LS
Reference implementation of the multiharmonic least-squares periodogram
(AoVMH(W) / FastChi²) algorithm described in Rutkowski & Poleski (2026) using a blocked NuFFT and a fast Toeplitz solver.
Works as a drop-in default backend for astropy.timeseries.LombScargle, releases the GIL across its ctypes C/Vulkan calls even on standard (non-free-threaded) Python builds, and ships built-in GPU acceleration via Vulkan offload.
Installation
The package requires Python >= 3.8 and NumPy >= 1.17.3; the optional tlsdd
extra requires mpmath >= 1.0. Prebuilt wheels include runtime microarchitecture
dispatch, so installing from PyPI is the recommended path:
pip install Toeplitz-LS
# or with mpmath for the double-double wrappers:
pip install "Toeplitz-LS[tlsdd]"
To build from source instead:
git clone https://github.com/kkrutkowski/Toeplitz-LS.git --depth=1
cd ./Toeplitz-LS
make native # or 'make generic' for a portable baseline
cd ./toeplitz-ls
pip3 install . # use 'pip3 install ".[tlsdd]"' for the mpmath wrappers
make native may be slightly faster thanks to custom-generated scaling
constants and host tuning, though because release wheels ship multiple
microarchitecture builds via runtime dispatch, that difference is generally
insignificant.
Supported platforms
Linux, Windows, and macOS are supported on x86-64 and ARM64.
Runtime dispatch
Release builds bundle more than one native library. At import,
toeplitz_ls probes the CPU and loads the widest variant it can execute,
falling back to the baseline library; the choice is made once, so a
periodogram call pays nothing for it. TOEPLITZ_LS_DISPATCH forces a specific
variant, and TOEPLITZ_LS_DISPATCH=list prints the available variants.
Usage
Drop-in astropy.timeseries.LombScargle interface
Importing toeplitz_ls lazily hooks astropy.timeseries.LombScargle (with zero import overhead when Astropy is unused), registers "tls" (FP64), "tlsf" (FP32), and "tlsh" (FP16 compute, FP64 output), and sets "tls" as the default "auto" backend on regular frequency grids (falling back to Astropy for irregular grids or fit_mean=False):
import toeplitz_ls
from astropy.timeseries import LombScargle
# Uses "tls" automatically for regular frequency grids (single- or multi-harmonic)
frequency, power = LombScargle(t, y, dy, nterms=3).autopower()
# Or choose single/half precision or solver options explicitly:
frequency, power = LombScargle(t, y, dy, nterms=3).autopower(
method="tlsf",
method_kwds={"backend": "pswf43", "solver": "levinson"},
)
Astropy normalizations ("standard", "model", "log", "psd"), "anova", "nll", weighted errors (dy), and astropy.units.Quantity inputs/outputs are all supported; degenerate Toeplitz bins report 0.0 instead of NaN.
Native toeplitz_ls API
The package exposes two periodogram families. The FastChi2/AoVMH modules
(tlsf, tls, tlsdd) use the Toeplitz least-squares solve. The IHS modules
(ihsf, ihs, ihsdd) use the incoherent harmonic sum: one NuFFT per
harmonic, no linear solve, and only the raw, nll, or default
statistic. Each
family has single-, double-, and double-double-precision variants. The single-
and double-precision variants accept and return NumPy arrays. The double-double
variants rely on compensated arithmetic and operate on a 106-bit mantissa; they
use mpmath's mpf type to bridge the gap between the library's internal
representation and Python's native numeric types. The get_peaks helper turns
a periodogram into a sorted, interpolated peak list for printing or saving.
Normalizations
For the FastChi2 modules (tlsf, tls, tlsdd), power() and autopower()
accept normalization=:
| value | output | notes |
|---|---|---|
"standard" (default) |
coefficient of determination R^2 |
|
"anova" |
ANOVA / F statistic |
A. Schwarzenberg-Czerny's ANOVA convention |
"nll" |
natural negative log false-alarm probability | -ln(FAP) |
For nterms = d harmonics:
"standard"is the coefficient of determinationR^2of the full model. Values at or above 1 are numerical artefacts of an ill-conditioned solve and are reported as NaN."anova"is the ANOVAFstatistic in A. Schwarzenberg-Czerny's convention."nll"is the natural-log negative false-alarm probability,-ln(FAP), computed from the direct Pochhammer/incomplete-beta statistic with its finite-sample correction.Neff = (sum w)^2 / sum(w^2)withw = 1/dy^2.
The cond array returned when autonan=False is the Toeplitz condition upper
bound (2*nterms + 1) * P, where P is the Cybenko reflection-coefficient
product.
Spreading algorithms
For the PSWF backends ("pswf43", "pswf21"), power() and autopower()
accept spreading=:
| value | behavior |
|---|---|
"auto" (default) |
selects "minmax" or "piecewise" from the calibrated cost model for the problem size and CPU vector width |
"minmax" |
precomputes per-point minmax-polynomial PSWF0 weights once before block execution |
"piecewise" |
evaluates vectorized piecewise polynomials on the fly during spreading, avoiding weight-table precomputation and memory traffic (single and double precision only) |
Vectorization modes
Both the FastChi2 (tlsf, tls, tlsdd) and IHS (ihsf, ihs, ihsdd)
modules accept vectorize= on power() and autopower():
| value | behavior |
|---|---|
"auto" (default) |
selects "depth" or "breadth" (and spreading mode) from the calibrated cost model |
"depth" |
vectorizes across FFT bins within each frequency block (single and double precision only; raises ValueError on tlsdd/ihsdd) |
"breadth" |
vectorizes across consecutive frequency blocks in parallel across all backends ("pswf43", "pswf21", "lra"), including double-double via VECDD |
IHS periodogram
The ihsf, ihs, and ihsdd modules expose the same power() and
autopower() call shape, but no solver, no autonan, and no condition
array:
from toeplitz_ls import ihs
frequency, power = ihs.autopower(t, y, dy=None, nterms=3, normalization="nll")
IHS is a simplified formulation of a similar periodogram. It assumes that the
harmonic frequencies are independent (a regression from the standard
least-squares periodogram) but not orthogonal. It evaluates d NuFFTs instead
of 3d and replaces the O(d^2) normal-equation solve with an O(d) power
accumulation, so it is at least 3x less computationally expensive. In practice
it is usually slightly less accurate than FastChi2.
The three statistics are:
"raw": a direct display statistic built from the normalized per-harmonic Rayleigh powers. It is not a calibrated false-alarm probability, and fornterms > 1it is not a boundedR^2; it may exceed 1."nll": the negative log false-alarm probability. Each harmonic's Rayleigh power is passed through Wilkie's (1983) finite-sample correction, and the harmonic sum is then passed through the Erlang correction.Neff = (sum |wy|)^2 / sum(wy^2), wherewy = w * (y - ymean). Use this statistic when a reliable significance estimate is needed."default"(the default): the same initial formula and Erlang correction as"nll", but without the finite-sample Wilkie correction. This still produces NLL estimates, just less accurately.
IHS is not suitable when nterms^4 > Neff, where Neff is the raw-weight
effective sample size from the FastChi2/TLS path; the Python wrappers emit a
RuntimeWarning in that case. Use the FastChi2 modules or reduce nterms.
Free-threaded (GIL-free) Python support
Every C and Vulkan entrypoint is called through ctypes, which releases the GIL
even on regular (non-GIL-free) CPython builds. Independent power()/autopower()
calls therefore run concurrently in a ThreadPoolExecutor with real multi-core
speedups on standard Python as well as free-threaded builds (PEP 703, optional
since Python 3.13).
mpmath is not thread-safe by default. When using tlsdd in a multithreaded
context, each worker should keep its own mp context via mpmath.workprec()
rather than mutating the global mp.prec.
NaN handling
When the system matrix at a given frequency is numerically unstable, the solver
returns NaN rather than raising an exception. Use np.nanargmax() and
np.nanmax() in place of their standard counterparts to safely recover the
peak frequency and power without short-circuiting on degenerate bins.
For manual filtering, call power() or autopower() with autonan=False to
receive rough conditionality estimates alongside the periodogram. These
estimates are solver-specific: LDLT reports a diagonal-ratio estimate, while
the three Toeplitz solvers (levinson, zohar, and bareiss) return a
reflection-coefficient-based upper bound (2*nterms + 1) * P. The Toeplitz
estimates are generally much higher (and more reliable) for the same
frequencies, so threshold values should be chosen with the solver family in
mind.
Example usage of tls and tlsf
import numpy as np
import matplotlib.pyplot as plt
from toeplitz_ls import tls
rng = np.random.default_rng(seed=123)
N = 1000
t = np.sort(rng.uniform(0, 1000, size=N))
y = np.sin(50 * t) + 0.5 * np.sin(150 * t) + 1 + rng.poisson(size=N)
# Compute the generalized Scargle periodogram.
freq, r2 = tls.autopower(
t, y, dy=None,
fmax=12, # default value
nterms=1, # generalized Scargle periodogram
oversampling=5, # frequency density, relative to a dense, uniform FFT
backend="pswf43", # or "pswf21", "lra"
spreading="auto", # or "minmax", "piecewise"
vectorize="auto", # or "depth", "breadth"
normalization="standard", # or "anova", "nll"
)
best_idx = np.nanargmax(r2)
best_freq = freq[best_idx]
best_power = r2[best_idx]
print(f"Peak frequency: {best_freq:.6g} (R^2 = {best_power:.6g})")
plt.figure(figsize=(12, 5))
plt.plot(freq, r2, label="degree = 1", color="red")
plt.axvline(best_freq, linestyle="--", color="black", alpha=0.7)
plt.xlabel("Frequency")
plt.ylabel("Coefficient of determination")
plt.legend()
plt.tight_layout()
plt.show()
GPU offload (Vulkan)
Release wheels bundle built-in Vulkan compute offload under toeplitz_ls.offload.vulkan,
supporting NVIDIA, AMD, Intel, and Apple (MoltenVK) GPUs with no external CUDA/ROCm
SDK required (source builds from sdist also compile it automatically when glslc
and spirv-tools are installed). Each wrapper mirrors the CPU API with device
as its first argument: list_devices(), FastChi2 modules (tlsh FP16, tlsf FP32,
tlsdf Dekker double-float for GPUs without native FP64, and tls FP64), and IHS
modules (ihsh, ihsf, ihsdf, ihs).
Example usage with Vulkan tlsdf on an OGLE-BLAP light curve
from pathlib import Path
from tempfile import TemporaryDirectory
from urllib.request import urlretrieve
import numpy as np
from toeplitz_ls import get_peaks
from toeplitz_ls.offload.vulkan import list_devices, tlsdf
url = "https://www.astrouw.edu.pl/ogle/ogle4/OCVS/BLAP/phot/phot_ogle4/I/OGLE-BLAP-035.dat"
with TemporaryDirectory() as tmpdir:
data_path = Path(tmpdir) / "OGLE-BLAP-035.dat"
urlretrieve(url, str(data_path))
t, y, _dy = np.loadtxt(data_path, unpack=True)
t = t - t.min()
dev_id = list_devices()[0].id
# BLAPs require high-frequency search. Run Dekker double-float on the first Vulkan GPU.
freq, power, cond = tlsdf.autopower(
dev_id,
t, y, dy=None,
fmax=100,
nterms=3,
oversampling=5,
normalization="anova",
autonan=False,
)
peaks = get_peaks(freq, power, cond, threshold=10)
peaks.print(10)
Development
The C and Python halves share one style: .clang-format and ruff.toml use the
same 160-column budget and 4-space indentation, so make format leaves both in
a state make format-check accepts.
make format # clang-format (src, include, tests) + ruff format/check (package, dispatch)
make format-check # the same, without writing
make generic # portable build for this machine's architecture
make native # build for this machine
make -C tests check
Build artifacts (objects, staged wheel payloads, .toolchains/) live under
.build/. Nothing is committed to it.
Citation
If you use this code in your research, please cite:
@misc{rutkowski2026faster,
author = {Rutkowski, Kacper and Poleski, Rados{\l}aw},
title = {Faster $\chi^2$ periodogram: Accelerating linear algebra with fast Toeplitz solvers},
year = {2026},
eprint = {2611.20300},
archivePrefix = {arXiv},
primaryClass = {astro-ph.IM},
doi = {10.48550/arXiv.2611.20300},
url = {https://arxiv.org/abs/2611.20300}
}
Performance
The algorithm relies on blocked NuFFT sweeps with depth- and breadth-wise
vectorized transforms, deferred permutations, and block-sized work arrays. The
IHS path is an experimental approximation, expected to be at least 3x cheaper,
but appropriate only when the 4th power of degree does not exceed the
effective number of measurements. The benchmark harness is present in tests/.
Metadata
Release files for toeplitz-ls 1.1.0rc1
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 |
|---|---|---|---|---|
| toeplitz_ls-1.1.0rc1.tar.gz | 318.3 kB | Without provenance | Details for toeplitz_ls-1.1.0rc1.tar.gz |
Built distributions (wheels)
Total release size: 40.7 MB
Release files / toeplitz_ls-1.1.0rc1.tar.gz
| Download URL | toeplitz_ls-1.1.0rc1.tar.gz |
|---|---|
| Size | 318.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc898fa5abbd2e8413aa57530aa32f30d02cb783b048c403f7f5c08748f16ce0
|
|
BLAKE2b-256 checksum How to use checksums |
b4c474488928512f8724e52ffcf18c0b9405e8a51bfefa9b89969009fe4d58bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / toeplitz_ls-1.1.0rc1-py3-none-win_arm64.whl
| Download URL | toeplitz_ls-1.1.0rc1-py3-none-win_arm64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | Python 3 Windows ARM64 |
|
SHA-256 checksum How to use checksums |
0092a60c5231a0862816284649004f1389f58c54fe8df488dbab1a6038276d75
|
|
BLAKE2b-256 checksum How to use checksums |
e37de8ee2b075d0a7cfb7c461985196ef0006864d04a369ea9f9f5a99ef2a98f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / toeplitz_ls-1.1.0rc1-py3-none-win_amd64.whl
| Download URL | toeplitz_ls-1.1.0rc1-py3-none-win_amd64.whl |
|---|---|
| Size | 5.6 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
095f49493a7d2bca65428de49f0025d740515c742cdeae21cd482d960a441b4c
|
|
BLAKE2b-256 checksum How to use checksums |
26f587ff3a44e1dbfd1e212683c273ec2f3f4bfef3eb47e565cd833a9f4e9e7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / toeplitz_ls-1.1.0rc1-py3-none-musllinux_1_2_x86_64.whl
| Download URL | toeplitz_ls-1.1.0rc1-py3-none-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | Linux musl 1.2+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
ae03c43a38d89eac69885dec0817448166a9805965492c9a94814b518efeb52e
|
|
BLAKE2b-256 checksum How to use checksums |
a55b2ca0ce7833709db812250bcb5335989ef0b800a05cd9363f55cd9bacce39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / toeplitz_ls-1.1.0rc1-py3-none-musllinux_1_2_aarch64.whl
| Download URL | toeplitz_ls-1.1.0rc1-py3-none-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | Linux musl 1.2+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
463f509f7b6996dbc131b9f9712fea01edb40bb505d694f81fe05fd6d5398981
|
|
BLAKE2b-256 checksum How to use checksums |
753bf2932d1b1efca35f6fe6ad79297d9845c114d4f5289da105c74fb578a27d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / toeplitz_ls-1.1.0rc1-py3-none-manylinux_2_17_x86_64.whl
| Download URL | toeplitz_ls-1.1.0rc1-py3-none-manylinux_2_17_x86_64.whl |
|---|---|
| Size | 5.4 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
0412c90c7ea53d8790cd5a6a56fa4899fec17539f33bcb337a77dddf4f34a1d9
|
|
BLAKE2b-256 checksum How to use checksums |
95e84cc26a272aab758460757ed009e52bd09c3f93b49117655abd1e29a21ab4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / toeplitz_ls-1.1.0rc1-py3-none-manylinux_2_17_aarch64.whl
| Download URL | toeplitz_ls-1.1.0rc1-py3-none-manylinux_2_17_aarch64.whl |
|---|---|
| Size | 4.3 MB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
7626d346a97931ec721ac3002b49dfd65af37345ad60bba00d7711ea5cb72f5b
|
|
BLAKE2b-256 checksum How to use checksums |
0847984f0e031d901b12c99f369e0e1cfdff122ae7c54e3bb83744bf5ea718a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / toeplitz_ls-1.1.0rc1-py3-none-macosx_11_0_x86_64.whl
| Download URL | toeplitz_ls-1.1.0rc1-py3-none-macosx_11_0_x86_64.whl |
|---|---|
| Size | 6.6 MB |
| Tags | Python 3 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
dcbae52b5c4405fdb14fb9fc47ff1f6014a943cdf50f00f4f856deb1d634602f
|
|
BLAKE2b-256 checksum How to use checksums |
992ad924a4eb91949166a44f38fb8dc74d73eaf243c5edda23a97af65579e23d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / toeplitz_ls-1.1.0rc1-py3-none-macosx_11_0_arm64.whl
| Download URL | toeplitz_ls-1.1.0rc1-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.6 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
56fb3713087d1940ca94476c3071614fe11651563cb39ffb44e92cfd97807e0e
|
|
BLAKE2b-256 checksum How to use checksums |
e48bfd3fe298f7ee64e5e3037fd05408784c94c45bef8d73ec060e4032575a09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for toeplitz-ls 1.1.0rc1
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.