Add Refactorize() for numeric refactorization reusing the symbolic analysis#55
Conversation
…ization SparseLU / SparseCholesky / SparseLDL (Double and Complex) gain a public Refactorize(matrix[, tol]) that re-runs only the numeric factorization, reusing the cached symbolic analysis (fill-reducing ordering, elimination tree). Intended for Newton iterations and time-stepping loops where the matrix values change but the sparsity pattern does not: it skips the ordering/symbolic phase and keeps only the (dominant) numeric work. - LU: a different pattern still factorizes correctly (column ordering is a permutation), only the fill may be sub-optimal. - Cholesky / LDL: the elimination tree is reused, so the pattern must match. - Dimension guard throws ArgumentException on a size mismatch. Adds TestRefactorize for all six factorizations (refactorize B = 2*A on the same pattern reproduces a correct solve; dimension guard throws). All 40 factorization tests pass.
|
Thanks a lot! Now that there are if (L is null)
{
L = CompressedColumnStorage<double>.Create(n, n, lnz);
U = CompressedColumnStorage<double>.Create(n, n, unz);
}
else
{
// lnz and unz do not change on re-factorization
L.Clear();
U.Clear();
}Same for Cholesky and LDL'. Would you like to do another PR which implements this? |
|
Done — added the allocate-once / I folded it into this PR rather than opening a separate one because the reuse path is only reachable (and testable) via One note on I am delighted to contribute to CSparse.NET ! Please feel free to share any other improvements you may need. |
|
I merged this, probably while you were working on the changes. Could you * Probably easier to just sync your fork, create a new working branch and bring the latest changes from |
Very welcome! |
Good catch. I think the resize should be avoided when using the factorization inside an iterative solver. You could wrap the resize operation inside a CSparse.NET/CSparse/Storage/CompressedColumnStorage.cs Lines 16 to 23 in 8898899 |
Reuse factor buffers across re-factorizations (follow-up to #55)
Motivation
In Newton iterations and time-stepping loops the system matrix changes its values every iteration but keeps the same sparsity pattern. The only public entry point today is the static
Create(), which re-runs the fill-reducing ordering + symbolic analysis every time, even though the pattern is constant.Separating symbolic-once / numeric-many is a standard feature of sparse direct solvers (UMFPACK, PARDISO, MUMPS, CHOLMOD all expose it). The internals here already split the two phases (
SymbolicAnalysis→S, then the private numericFactorize); this PR just exposes the numeric refactorization.What
Adds a public
Refactorize(matrix[, tol])to the square direct factorizations, for bothDoubleandComplex:SparseLU.Refactorize(A, tol = 1.0)SparseCholesky.Refactorize(A)SparseLDL.Refactorize(A)It re-runs only the numeric
Factorize, reusing the cachedSymbolicFactorization. A dimension guard throwsArgumentExceptionon a size mismatch. Behaviour w.r.t. the pattern:Create(documented in the XML doc).Usage
Tests
TestRefactorizeadded for all six factorizations: factorizeA, refactorizeB = 2·A(same pattern), solve and check the residual; plus a dimension-guard throw. All 40 factorization tests pass.Notes
ISparseFactorization<T>if you'd prefer it uniform across all factorizations (would also need a story forSparseQR, whose symbolic/numeric split is structured differently).RefactorizevsFactorize/Numeric) or the scope to your preference.Thanks for CSparse.NET!