Skip to main content

correlation

Tools for computing time correlation functions of real-valued trajectories, with FFT, PyTorch, conditional, and incremental HDF5 workflows.

Installation

Install correlation-fft from PyPI.

pip install correlation-fft

The Rust extension always builds with both CPU and CUDA support. Build a wheel for your target platform and Python version with Maturin:

maturin build --release
pip install target/wheels/correlation_fft-*.whl

The Rust extension loads the NVIDIA driver when it tries to use CUDA. CPU-only machines can use the same wheel. The Rust CUDA path uses the embedded PTX and requires a compatible NVIDIA driver. The separate PyTorch CUDA path requires a CUDA-enabled PyTorch installation.

Features and usage

Correlation functions

correlation(a, b=None, trunc=None) computes an autocorrelation when b is omitted, or a cross-correlation when b is supplied. It supports one- and two-dimensional NumPy arrays and uses mkl_fft.

import numpy as np
from correlation import correlation

x = np.random.randn(10000)
acf = correlation(x)                 # autocorrelation
cross = correlation(x, np.roll(x, 1), trunc=1000)

correlation_torch provides the same operation through PyTorch and accepts a device such as "cpu" or "cuda". Install PyTorch separately with pip install torch to use it.

from correlation import correlation_torch

acf_gpu = correlation_torch(x, device="cuda")

Benchmark

The benchmark for the correlation of a 100 million-entry real array on an 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz CPU yields:

python benchmark_correlation.py --size 100000000 --repeats 20
Implementation Median time (s) Peak RAM usage (GiB)
package (mkl_fft) 3.203 4.47
numpy.fft 9.813 8.94
scipy.fft 8.263 8.94

Conditional correlation

ConditionalCorrelation is a Rust-backed accumulator. Choose a trajectory range and number of bins, then add trajectory arrays and retrieve the result:

from correlation import ConditionalCorrelation

cc = ConditionalCorrelation(100, 8, (-2.0, 2.0), cond_start=True)
cc.add_data(x, x, condition)
result = cc.get_result()

The default device is "cpu". device="auto" selects CUDA when the driver can load the kernel and cond_start=True, cond_end=False. Otherwise it selects CPU. Explicit device="cuda" (or "gpu") raises an error if the driver, kernel, or conditioning mode is unavailable. The device property reports the selected backend.

add_data accepts float32 and float64 NumPy arrays on both backends. The CPU computes in double precision. The CUDA kernel converts inputs to single precision. Use device="cpu" to keep double precision.

ConditionalCorrelationFFT accumulates conditional correlations using FFTs. Construct it with from_range(nbins, traj_range, trunc) or from_dx(dx, nbins, start, trunc), add trajectories with add_data(...), then call get_result(). Without PyTorch, add_data_cuda(...) issues a warning and uses add_data(...) on the CPU.

Incremental HDF5 correlation

IterativeCorrelation and its VVCorr (velocity autocorrelation function) and XdUCorr (position gradient-of-pmf correlation function) variants support correlation calculations over chunked HDF5 datasets, limiting memory use for large inputs. See their class docstrings for the dataset and observable arguments.

Metadata

Release files for correlation-fft 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for correlation-fft 0.1.6
File Size Uploaded Provenance Actions
correlation_fft-0.1.6.tar.gz 59.6 kB Without provenance Details for correlation_fft-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for correlation-fft 0.1.6
File Interpreter ABI Platform Actions
correlation_fft-0.1.6-cp310-abi3-manylinux_2_34_x86_64.whl CPython 3.10 abi3 Linux glibc 2.34+ x86-64 Details for correlation_fft-0.1.6-cp310-abi3-manylinux_2_34_x86_64.whl

Total release size: 888.4 kB

Release files / correlation_fft-0.1.6.tar.gz

Download URL correlation_fft-0.1.6.tar.gz
Size 59.6 kB
Tags Source
SHA-256 checksum
How to use checksums
192a5d62f13460ead0b5bd5eac93a3bc127adf4533d5c59842bd88043cc02e4a
BLAKE2b-256 checksum
How to use checksums
37cee24acf0a06ce921a41f0b7e3fc8b2ebe47597244071bff2ae0154ee276e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / correlation_fft-0.1.6-cp310-abi3-manylinux_2_34_x86_64.whl

Download URL correlation_fft-0.1.6-cp310-abi3-manylinux_2_34_x86_64.whl
Size 828.8 kB
Tags CPython 3.10 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
2f50c85878af42c42b2a2608de666bdc7756781c2d1dbc94619726d78161be7c
BLAKE2b-256 checksum
How to use checksums
653881cbc6a7f2304f1549cabaf0361cbe916c09d48e5b82c9652cc488da1e66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for correlation-fft 0.1.6

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page