Skip to main content

statspai-hdfe

Rust kernels for StatsPAI: high-dimensional fixed-effect (HDFE) demeaning, the native Poisson IRLS behind sp.fast.fepois, and the cluster-robust sandwich meat.

pip install "statspai[rust]"     # or: pip install statspai-hdfe

StatsPAI never requires this package. Without it the same functions run on NumPy / Numba and agree with the Rust path to within the residualisation tolerance. Check which one is in use:

import statspai as sp
sp.fast.backend_info()      # {'available': True, 'version': '0.8.0', 'threads': 8, ...}
sp.fast.set_num_threads(4)  # or set STATSPAI_NUM_THREADS before starting Python

STATSPAI_SKIP_RUST=1 makes StatsPAI ignore an installed extension.

What uses it

StatsPAI entry point Kernel
sp.fast.feols, sp.fast.demean, sp.fast.within, sp.fast.event_study demean_2d
sp.fast.feols(weights=), sp.ppmlhdfe (two or more FEs) demean_2d_weighted
sp.fast.fepois fepois_irls, separation_mask
sp.iv(absorb=), sp.didregress, sp.iv.iv_diag, weak-IV diagnostics demean_2d
sp.regress(cluster=) (one-way) cluster_meat
singleton pruning in sp.fast singleton_mask

sp.hdfe_ols / sp.Absorber, sp.panel and the pyfixest-backed sp.feols do not use it.

Algorithm

The fixed-effect projection is solved in the space of FE coefficients, as fixest does (Bergé 2018; paper.bib key berge2018efficient):

  • Two FEs. One Gauss-Seidel sweep needs only the group sums of the column and the sparse cross-tabulation of the two FEs, so it costs O(nnz) instead of O(n); on panels where a unit meets few levels of the other FE (worker x firm, firm x year) that is a small fraction of the rows. The iteration runs on the coefficients of the smaller FE and is accelerated with Irons-Tuck at every step.
  • Three or more FEs. The two FEs with the most levels form a block solved by the two-FE routine (warm-started) inside an outer Gauss-Seidel over the others, accelerated with Irons-Tuck. The inner tolerance starts loose and follows the outer change down.
  • Stopping rule. Stop when the bound on the change of the residual between two sweeps is at most tol_abs + tol_rel * max|x|, the rule of the NumPy reference in statspai.fast.demean.
  • IRLS. The FE structure is built once per fepois call; each iteration re-weights it and restarts every column from its FE coefficients of the previous iteration.

Columns are processed in parallel. The cluster meat sums fixed blocks of clusters in parallel and adds the block sums in order, so its result is the same at any thread count; the demeaning is per column and therefore also independent of the thread count.

Safety

Every entry point validates lengths, contiguity and code ranges before running and raises ValueError on bad input. The crate is built with panic = "unwind", so an unexpected panic surfaces as a Python exception instead of aborting the interpreter. The kernels run on their own thread pool (never Rayon's global one), which is rebuilt in a forked child.

Build from source

pip install maturin
cd rust/statspai_hdfe
maturin develop --release       # into the active environment
maturin build --release         # a wheel in target/wheels
PYO3_PYTHON=python cargo test --release

Wheels are abi3: one per platform serves every CPython >= 3.10. The rust-hdfe GitHub workflow tests the crate on Linux, macOS and Windows, builds wheels on demand, and publishes on an hdfe-v* tag.

Kernel API

statspai_hdfe.API_VERSION names the interface level; StatsPAI ignores an extension older than the level it was written against (statspai._rust_backend.MIN_API_VERSION) and warns once.

Level Crate Change
1 0.1 – 0.7 data-space alternating projections; inputs not validated
2 0.8 coefficient-space solver; validated inputs; fepois_irls reports singular / fe_converged; thread-pool control; reproducible cluster_meat

License

MIT.

Metadata

Release files for statspai-hdfe 0.8.0

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

Source distribution (sdist)

Source distribution for statspai-hdfe 0.8.0
File Size Uploaded Provenance
statspai_hdfe-0.8.0.tar.gz 40.0 kB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for statspai-hdfe 0.8.0
File
statspai_hdfe-0.8.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
statspai_hdfe-0.8.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
statspai_hdfe-0.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
statspai_hdfe-0.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
statspai_hdfe-0.8.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
statspai_hdfe-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 2.4 MB

Release files / statspai_hdfe-0.8.0.tar.gz

Download URL statspai_hdfe-0.8.0.tar.gz
Size 40.0 kB
Tags Source
SHA-256 checksum
How to use checksums
fb1a90ed8d1d12a418519072596f9b7554ec0c66d5ce65930e4c1c0be652e8b3
BLAKE2b-256 checksum
How to use checksums
667674dfbb8d4e73e8c1a91a6baf4db234f7a35be9af8ded257cc6e6b99d86db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / statspai_hdfe-0.8.0-cp310-abi3-win_amd64.whl

Download URL statspai_hdfe-0.8.0-cp310-abi3-win_amd64.whl
Size 282.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
decaae7cd1ad32779c0930be2f6ea7e421c64b14c4f6cadc43e9f3b1ad6d260a
BLAKE2b-256 checksum
How to use checksums
ba6481c856f07731deab8c4792092a93deea433136337c0687c129476ade28dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / statspai_hdfe-0.8.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL statspai_hdfe-0.8.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 603.1 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
d1c4d061cfa7a394ba9b61d8e377d168d36395d8253f000d642962660fab717b
BLAKE2b-256 checksum
How to use checksums
6bdb8890fac7fc51750d07742be75bbb4e9e300ada3e3ff6ab367bac684aa7f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / statspai_hdfe-0.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL statspai_hdfe-0.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 392.4 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
876bea25650f7d8da70b497bec521069346da16bc5fdaf82c003780b43af30ac
BLAKE2b-256 checksum
How to use checksums
571e78c2e933941cf8c117f8d149789d79b3256396333c64abac93c41362e0eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / statspai_hdfe-0.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL statspai_hdfe-0.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 388.7 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
ac033a75f06610b62f924b2af34e0d900af197382b6c2cc1b2bd685b068fb9b1
BLAKE2b-256 checksum
How to use checksums
d14dde865957964e7bd398afd5d46c0d96a016b1e480543b37a9520f4eb74b25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / statspai_hdfe-0.8.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL statspai_hdfe-0.8.0-cp310-abi3-macosx_11_0_arm64.whl
Size 355.5 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
818eb50bf024006e4f3493ad39bc5023fbcba0fc748e262b2e58a56cda7940d7
BLAKE2b-256 checksum
How to use checksums
a9dbdd9fe7f96d08f3206a0aed1bac08b21cc40bf5e48934d544b6f24152bf85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / statspai_hdfe-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL statspai_hdfe-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 367.7 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
9611d72077264c27770620b35b80befaa1506e1e82762f4f7a0ee4ba49180904
BLAKE2b-256 checksum
How to use checksums
8e99ef37de3754f2105cfe371e9fbe4538afc865a0b23e946d1a8c97f1951877
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Security for statspai-hdfe 0.8.0

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.

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