within
Solves linear fixed-effects models y = D x + e where D is a sparse categorical design matrix. The normal equations G x = D^T W y (with G = D^T W D) are solved via preconditioned CG or right-preconditioned GMRES with additive or multiplicative Schwarz preconditioners backed by approximate Cholesky local solvers. Designed for econometric panel data with millions of observations and multiple high-dimensional fixed effects.
Install
cargo add within
Quick example
use Array2;
use ;
// Two factors: 100 levels each, 10 000 observations
let n_obs = 10_000usize;
let mut categories = zeros;
for i in 0..n_obs
let y: = .map.collect;
// Solve with the default solver: CG + additive Schwarz + implicit operator
let result = solve
.expect;
assert!;
println!;
// GMRES with multiplicative Schwarz
let params = SolverParams ;
let precond = Multiplicative;
let result = solve
.expect;
assert!;
println!;
Feature flags
| Feature | Default | Effect |
|---|---|---|
ndarray |
yes | Enables from_array constructors on observation stores for interop with ndarray::ArrayView2. |
Architecture
The crate is organized in four layers:
-
observation— Per-observation factor levels and weights viaFactorMajorStoreand theObservationStoretrait. -
domain— Domain decomposition.WeightedDesignwraps a store with factor metadata;build_local_domainsconstructs factor-pair subdomains with partition-of-unity weights for the Schwarz preconditioner. -
operator— Linear algebra primitives.Gramian(explicit CSR) andGramianOperator(implicit D^T W D) for the normal equations; Schwarz preconditioner builders that wire approximate Cholesky local solvers into the genericschwarz-precondframework. -
orchestrate— End-to-end solve entry points (solve,solve_batch) with typed configuration (SolverParams,KrylovMethod,Preconditioner,OperatorRepr).
License
MIT
References
- Correia, Sergio. "A feasible estimator for linear models with multi-way fixed effects." Preprint at http://scorreia.com/research/hdfe.pdf (2016).
- Gao, Y., Kyng, R. & Spielman, D. A. (2025). AC(k): Robust Solution of Laplacian Equations by Randomized Approximate Cholesky Factorization. SIAM Journal on Scientific Computing.
- Toselli & Widlund (2005). Domain Decomposition Methods — Algorithms and Theory. Springer.
- Xu, J. (1992). Iterative Methods by Space Decomposition and Subspace Correction. SIAM Review, 34(4), 581--613.