sparsax.factor_solve

sparsax.factor_solve(Ai, Aj, Ax, rhs, want_logdet=False, n=None)[source]

Factor A once, 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 optional logdet — is served from that factor. Under jax.vmap it 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 rhs is (b, modes) where modes is a single MODE_* 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 in solve().

Aj

COO of the SPD matrix A, as in solve().

Ax

COO of the SPD matrix A, as in solve().

rhs

list of (b, modes). Each b is [n] or [n, n_rhs].

want_logdet=False

if True, also return log|A| from the same factor.

n=None

matrix dimension. Inferred from rhs[0] when omitted; required if rhs is empty (logdet only).

Returns:

A list xs of solutions, one per rhs entry, each matching its b’s shape. If want_logdet is set, returns (xs, logdet).

Note

This primitive has no autodiff rule. Use solve() / logdet(), which define VJPs, when you need gradients.