linear: implement P0 PLU decomposition with unified result type#3
linear: implement P0 PLU decomposition with unified result type#3
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3001d129eb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| val pivots = mutableListOf<Int>() | ||
|
|
||
| for (k in 0 until n) { | ||
| val pivotRow = (k until n).firstOrNull { !mc.isZero(upper[it, k]) } ?: continue |
There was a problem hiding this comment.
Preserve PLU invariants when a pivot column is all zero
In decompPLU, the early continue when column k has no non-zero candidate skips initialization of lower[k,k] and abandons pivot tracking for that step. On rank-deficient inputs with a zero leading column but non-zero entries later in the row (for example [[0,1],[0,0]]), this yields P=I and U=A but leaves row k of L zeroed, so P*A != L*U, and pivots/rank underreport the matrix rank. This should handle zero-pivot columns without breaking the decomposition identity.
Useful? React with 👍 / 👎.
Motivation
P,L,U, pivot indices and rank in a single object.decompPLUto complement existingdecompLUand enable pivoting when leading elements are zero.Description
PLUDecompositionResult<T>containingP,L,U, andpivotswith a computedrankproperty insrc/main/kotlin/.../Matrix.kt.Matrix<T>.decompPLU()which delegates toMatrixImpl.decompPLU(this, model)inMatrix.kt.MatrixImpl.decompPLU(m: Matrix<T>, mc: Field<T>)performing row pivot selection, row swaps onUandP, updatingLaccordingly, and returningPLUDecompositionResultinsrc/main/kotlin/.../MatrixImpl.kt.decompPLUOfSquareMatrixanddecompPLUHandlesZeroLeadingPivotByRowSwapinsrc/test/kotlin/linear/MatrixTest.ktto validateP*A == L*U, pivot/rank consistency and row-swap behavior.Testing
linear.MatrixTest.decompPLUOfSquareMatrixandlinear.MatrixTest.decompPLUHandlesZeroLeadingPivotByRowSwapvia the Gradle wrapper, but the wrapper download failed due to a network connection refusal so the tests could not be executed in this environment.decompPLUOfSquareMatrix,decompPLUHandlesZeroLeadingPivotByRowSwap) to verify correctness.Codex Task