statspai-hdfe
Rust kernels for StatsPAI:
high-dimensional fixed-effect (HDFE) demeaning, the native IRLS (Poisson,
logit, probit) behind sp.fepois / sp.feglm / sp.fast.fepois, and the
cluster-robust sandwich meat.
pip install statspai-hdfe # StatsPAI releases after 1.39.6 install it themselves
StatsPAI releases after 1.39.6 depend on this package on every platform with a wheel (Linux x86_64 / aarch64, macOS, Windows x64). 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.9.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.fepois, sp.fast.fepois |
fepois_irls, separation_mask |
sp.feglm(family="logit" / "probit") |
feglm_irls (API 3) |
sp.feols (plain formulas, backend="auto") |
demean_2d |
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.panel and the calls sp.feols hands to pyfixest (IV, i(),
csw(), other variances) 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 ofO(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 instatspai.fast.demean. - IRLS. The FE structure is built once per
fepoiscall; each iteration re-weights it and restarts every column from its FE coefficients of the previous iteration.
Columns are processed in parallel, and from crate 0.9 so is every pass
over the rows within a column (group sums, residuals, the IRLS working
response, cross products, deviance): the rows are split into chunks fixed
by the problem size, each chunk is reduced in row order, and the chunk
results are added in chunk order (src/par.rs). A fit is therefore
bit-identical at any thread count. The cluster meat sums fixed blocks of
clusters the same way.
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,
and builds wheels on demand; releases are uploaded from those wheels with
twine.
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 |
| 3 | 0.9 | feglm_irls(..., family) for Poisson / logit / probit; row-parallel passes, bit-identical at any thread count; API 2 entry points unchanged |
License
MIT.
Metadata
Release files for statspai-hdfe 0.9.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 | |
|---|---|---|---|---|
| statspai_hdfe-0.9.1.tar.gz | 45.6 kB | Without provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| statspai_hdfe-0.9.1-cp310-abi3-win_arm64.whl | CPython 3.10 | abi3 | Windows ARM64 | Details |
| statspai_hdfe-0.9.1-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| statspai_hdfe-0.9.1-cp310-abi3-musllinux_1_2_x86_64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ x86-64 | Details |
| statspai_hdfe-0.9.1-cp310-abi3-musllinux_1_2_aarch64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ ARM64 | Details |
| statspai_hdfe-0.9.1-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.9.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| statspai_hdfe-0.9.1-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| statspai_hdfe-0.9.1-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 3.7 MB
Release files / statspai_hdfe-0.9.1.tar.gz
| Download URL | statspai_hdfe-0.9.1.tar.gz |
|---|---|
| Size | 45.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d695bfb31c7656ce1918c4c8be05443e17c7e24134572bb0f63eba6631969b3
|
|
BLAKE2b-256 checksum How to use checksums |
9f1eee76e6722523ae435a16e696ea064f5dc063048d3c0777cb90c3e193e393
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / statspai_hdfe-0.9.1-cp310-abi3-win_arm64.whl
| Download URL | statspai_hdfe-0.9.1-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 320.9 kB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e93bd08b6d64fa366f1bd17c1fdc1aee192186dfabd68e9e7c6540e2920352af
|
|
BLAKE2b-256 checksum How to use checksums |
efade9f25ff9952bbe1feeff2a6884ce06821faf485dd3e9833143bae8126622
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / statspai_hdfe-0.9.1-cp310-abi3-win_amd64.whl
| Download URL | statspai_hdfe-0.9.1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 341.7 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
aae31308fe12e274c50f7f0f360e87ab127a41841bb45bd4da02351c7be75e4b
|
|
BLAKE2b-256 checksum How to use checksums |
5df91d06ab9214ed806f59720d59224fc74b51bb9e9089e293dda9a7fefaf48f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / statspai_hdfe-0.9.1-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | statspai_hdfe-0.9.1-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 655.2 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
bf54a46e6efe221ed3363d9b166295e28c3783d7714f2f3b5ab3fd1dbdeb7eb8
|
|
BLAKE2b-256 checksum How to use checksums |
8373f2452c382b338788c074098f7c12bcc3f91629a55a82a1476567c3f2b6b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / statspai_hdfe-0.9.1-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | statspai_hdfe-0.9.1-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 613.1 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
c5fac0f0fa9d021a70af3245d8b342c745bd309c44e5a2cc88e4c8b24d486b3f
|
|
BLAKE2b-256 checksum How to use checksums |
2890eb139fb80b955c9da8545da519fdf4eb841eddc3196a480f7413ce66ffe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / statspai_hdfe-0.9.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | statspai_hdfe-0.9.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 444.7 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
92f8d5ac6edb46238a67e37d2c86ddfe2b3d8e9b789f227ae0afe71ba873bb63
|
|
BLAKE2b-256 checksum How to use checksums |
5862c51906d0ab2251d37341db81f1a294862e332f7c3bc990765b106061a873
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / statspai_hdfe-0.9.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | statspai_hdfe-0.9.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 435.3 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
d2925ede844f1acc604aeef91b196f3ba8e2e8c65cb72f3719a6e5ac47882dab
|
|
BLAKE2b-256 checksum How to use checksums |
8941adef9abc0961a0d57bbdf2a68fbe24eb2200a51f10c195c84a3051601980
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / statspai_hdfe-0.9.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | statspai_hdfe-0.9.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 402.9 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1bdbd878b64c232f9dc7f0373b4c3ad2ebff914f6802b4c6402fa1cb1ec059d3
|
|
BLAKE2b-256 checksum How to use checksums |
1e7413fed8e0f79742c8e702a039a384a27feaa075126a1cd27d5854c844e200
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Release files / statspai_hdfe-0.9.1-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | statspai_hdfe-0.9.1-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 418.5 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
882383d3a3765a22173124dc9e9dc92371d330e92e3810d292cc7f729485e89b
|
|
BLAKE2b-256 checksum How to use checksums |
b62709ac3a8efa67c84b0928b0df1a6d350325cb92e42f4fb420fe593905f11c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.20
|
Security for statspai-hdfe 0.9.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.