Skip to content

linear: implement P0 PLU decomposition with unified result type#3

Open
Ezrnest wants to merge 2 commits intomasterfrom
codex/explore-further-work-on-linear-algebra-a8120r
Open

linear: implement P0 PLU decomposition with unified result type#3
Ezrnest wants to merge 2 commits intomasterfrom
codex/explore-further-work-on-linear-algebra-a8120r

Conversation

@Ezrnest
Copy link
Copy Markdown
Owner

@Ezrnest Ezrnest commented Feb 20, 2026

Motivation

  • Implement the P0 work item to provide a robust PLU/LUP decomposition entry for exact (non-floating) linear algebra.
  • Introduce a unified decomposition result type so consumers can access P, L, U, pivot indices and rank in a single object.
  • Provide a field-context API for decompPLU to complement existing decompLU and enable pivoting when leading elements are zero.

Description

  • Add PLUDecompositionResult<T> containing P, L, U, and pivots with a computed rank property in src/main/kotlin/.../Matrix.kt.
  • Add the extension API Matrix<T>.decompPLU() which delegates to MatrixImpl.decompPLU(this, model) in Matrix.kt.
  • Implement MatrixImpl.decompPLU(m: Matrix<T>, mc: Field<T>) performing row pivot selection, row swaps on U and P, updating L accordingly, and returning PLUDecompositionResult in src/main/kotlin/.../MatrixImpl.kt.
  • Add unit tests decompPLUOfSquareMatrix and decompPLUHandlesZeroLeadingPivotByRowSwap in src/test/kotlin/linear/MatrixTest.kt to validate P*A == L*U, pivot/rank consistency and row-swap behavior.

Testing

  • Attempted to run targeted tests linear.MatrixTest.decompPLUOfSquareMatrix and linear.MatrixTest.decompPLUHandlesZeroLeadingPivotByRowSwap via the Gradle wrapper, but the wrapper download failed due to a network connection refusal so the tests could not be executed in this environment.
  • Project changes include the new tests and compile-time code; CI or a local run with working network should execute the added tests (decompPLUOfSquareMatrix, decompPLUHandlesZeroLeadingPivotByRowSwap) to verify correctness.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant