Fix sparse LU/QR/Cholesky fill-reduction permutations#236
Open
micycle1 wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solves #207.
Problem
Sparse fill-reduction orderings were broken for any non-identity permutation.
LU and Cholesky could return plausible but incorrect results. Sparse QR could crash. This went unnoticed because the only orderings covered by tests were
NONEandIDENTITY.FillReducing.RANDOMexisted but was not used in the test suite.There were six issues across LU and QR:
ApplyFillReductionPermutation_DSCCP*A*Q.P.Q."No row permutation matrix"otherwise.LuUpLooking_DSCC.performLU()getArrayP()) as the column ordering during factorization.LinearSolverLu_DSCC.solve()b.xin the wrong direction: it usedpermuteinstead ofpermuteInv.LinearSolverLu_DSCC.solveSparse()QrLeftLookingDecomposition_DSCC.decompose()ArrayIndexOutOfBoundsExceptionfor nontrivial column permutations.LinearSolverQrLeftLooking_DSCC.solve()andsolveSparse()xusing the row permutation in the forward direction.While fixing these, there was one more issue:
LinearSolverCholesky_DSCC.solveSparse()pinvtoTriangularSolver_DSCC.solve().Cause
Each solver handled fill-reduction permutations differently:
pinvapproach.ApplyFillReductionPermutation_DSCCwas intended to provide a common implementation, but it only handled matrix permutation. Each solver separately handledbandx, which led to inconsistent conventions and direction mistakes.Fix
The common convention is now:
The decomposition operates on
P*A*Q, wherePandQcome from the fill-reduction ordering. For symmetric orderings such as SYMRCM or AMD,Q = Pᵀ.ApplyFillReductionPermutation_DSCCIt now applies both row and column permutations.
Permutation handling is now centralized in this class:
rowPermInv(numericRowPinv, work)undoColumnPermutation(double[] ...)undoColumnPermutation(DMatrixSparseCSC ...)All LU, QR, and Cholesky solve paths now follow the same pattern:
The solver-specific parts are now limited to the decomposition pivot array and the triangular solve implementation.
LU
LuUpLooking_DSCCnow processes columnkdirectly, since the input matrix has already been fully permuted.computeDeterminant()now includes the sign of both fill permutations.QR
API
LU and QR now expose
getApplyFillReduction(), matching the existing Cholesky setup.Tests
Added
FillReducing.RANDOMto the permutation test cases for LU, QR, and Cholesky.Also added or updated tests for:
Pfr * A * Qfr, rather than directly againstA.RANDOM.For wide matrices, QR may now return
falseunder a fill-reduction ordering if the resulting structure requires column pivoting. Previously this case crashed.Verification
org.ejml.sparsedsparse suite: 358/358 passingCompatibility
There are no public signature changes for the solve APIs.
NONEis unchanged; the fill-reduction object is null and all new logic is skipped.IDENTITYgives the same numerical results.One consequence is that LU and QR factors now reconstruct the fill-reduced matrix:
rather than
Adirectly.Callers reconstructing
Afrom LU or QR factors need the fill-reduction permutation as well as the decomposition's numeric pivot data. It is available throughgetApplyFillReduction().Follow-up
This should unblock SYMRCM and similar orderings. A symmetric ordering can return its ordering through both
prowandpcol, and it will now work consistently with Cholesky, LU, and QR.