Skip to main content

Module utils

Module utils 

Source

Structs§

PcgSolveInfo

Functions§

block_penalty_rank_and_pinv
Rank and Moore–Penrose pseudoinverse of a symmetric PSD penalty matrix via its eigendecomposition, keeping eigenpairs whose eigenvalue exceeds a relative tolerance. Returns (rank, pinv).
enforce_symmetry
Enforce exact symmetry on a square matrix by averaging off-diagonal pairs. Canonical in-place symmetrizer for a dense square ndarray matrix.
gaussian_weighted_ridge
Weighted ridge (penalized least-squares) solve for a multi-output Gaussian response. Forms the weighted normal equations XᵀWX (+ λ·penalty) β = XᵀWY (row weights W = diag(weights)), factorizes the symmetric system via the Cholesky-with-fallback path, solves for the coefficients (p, d), and returns (coefficients, fitted = Xβ). Single source of truth shared by the gaussian_weighted_ridge FFI shim and any core consumer.
gaussian_weighted_ridge_batch
Batched gaussian_weighted_ridge: solve one independent weighted-ridge fit per leading-axis slice of the padded (K, N_max, p) design / (K, N_max, d) response, honoring optional per-batch active row_counts. Runs the per-batch solves in parallel and scatters results back into dense (K, p, d) coefficients and (K, N_max, d) fitted arrays (padding rows left zero).
invert_spd_with_ridge
Invert a symmetric positive-definite matrix, escalating a relative diagonal ridge until the Cholesky factorization succeeds (robust SPD inverse).
solve_dense_block_system
Solve a symmetric dense block system H x = rhs (single right-hand side) via the Cholesky-with-fallback factorization, returning the solution vector. context labels errors.
solve_spd_pcg
solve_spd_pcg_with_info
solve_spd_pcg_with_info_into
Write-into variant of solve_spd_pcg_with_info that takes an apply closure of the form Fn(&Array1<f64>, &mut Array1<f64>) so the matvec can write into a caller-owned buffer. This eliminates the per-iteration Array1::<f64> allocation for the matvec result that the legacy closure-returning variant forces. See commit 83369abb for the analogous penalty-vector elimination.
solve_symmetric_vector_with_floor
Solve a symmetric (possibly indefinite/ill-conditioned) linear system via eigendecomposition with a spectral floor: eigenvalues below the floor are clamped (preserving sign) before inversion, stabilizing the solve.