sparsax.factor_solve¶
-
sparsax.factor_solve(Ai, Aj, Ax, rhs, want_logdet=
False, n=None)[source]¶ Factor
Aonce, then run several solve chains from that one factor.This is the “factor once, do everything” primitive:
A(the COO matrix) is factored a single time and every requested solve — plus an optionallogdet— is served from that factor. Underjax.vmapit lowers to one batched FFI call that factors once per batch element regardless of how many chains are requested, which is the key win for Gibbs sweeps that otherwise pay for the same factorization several times (mean, sample, and density all need it).Each entry of
rhsis(b, modes)wheremodesis a singleMODE_*code or a sequence of them applied left to right — a chain. For a chain[m0, m1, ...]the result is... m1(m0(b)). Examples:posterior mean
A^{-1} b:(b, MODE_A)a draw’s factor part
P' L^{-T} z:(z, [MODE_LT, MODE_PT])
- Parameters:¶
- Ai¶
COO of the SPD matrix
A, as insolve().- Aj¶
COO of the SPD matrix
A, as insolve().- Ax¶
COO of the SPD matrix
A, as insolve().- rhs¶
list of
(b, modes). Eachbis[n]or[n, n_rhs].- want_logdet=
False¶ if
True, also returnlog|A|from the same factor.- n=
None¶ matrix dimension. Inferred from
rhs[0]when omitted; required ifrhsis empty (logdet only).
- Returns:¶
A list
xsof solutions, one perrhsentry, each matching itsb’s shape. Ifwant_logdetis set, returns(xs, logdet).