Skip to content

fix: use plain workspaces for structured matrix inputs - #225

Open
KennyMcSimpson wants to merge 1 commit into
mljs:mainfrom
KennyMcSimpson:fix/structured-matrix-working-copies
Open

KennyMcSimpson wants to merge 1 commit into
mljs:mainfrom
KennyMcSimpson:fix/structured-matrix-working-copies

Conversation

@KennyMcSimpson

Copy link
Copy Markdown

SymmetricMatrix and DistanceMatrix keep their class when cloned. Algorithms that use those clones as workspaces consequently mirror writes into the opposite triangle; DistanceMatrix also resets each diagonal write to zero. For the matrix in #222, determinant() returns 757.1567106010962 instead of 442.75, and a nonsingular distance matrix can incorrectly fail inversion as singular.

Use plain Matrix copies for LU/QR decomposition workspaces, QR/Cholesky right-hand sides, echelon reduction, and the two-block NIPALS residuals. The public structured clone() behavior stays intact. Regressions check factor reconstruction, determinants, inverse/solve identities, right-hand sides, row reduction, residual reconstruction, and unchanged inputs.

Fixes #222.

Validation on Windows with Node.js 24.11.0:

  • New tests on the unchanged source: 22 failures, 2 passing controls. Patched full suite: 328 tests pass; ESLint and Prettier pass.
  • Independent NumPy 2.4.6 and reconstruction checks over 50 matrices: 1,400 checks, 552 failures on the original build and zero after the fix, including ordinary-matrix and public-clone controls.
  • Package build, clean installation of the npm archive, the same 1,400 installed-package checks, and 39 CommonJS/ESM/UMD checks pass.

The existing one-block NIPALS path (Y omitted) mutates its input and retains its separate structured-residual limitation; this change only addresses the two-block path identified in #222. It does not change the clone() declaration or other algorithms.

Prepared with AI assistance (OpenAI Codex).

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.08%. Comparing base (da8f1f6) to head (2253c78).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #225      +/-   ##
==========================================
+ Coverage   68.88%   70.08%   +1.20%     
==========================================
  Files          49       49              
  Lines        5904     5904              
  Branches     1060     1093      +33     
==========================================
+ Hits         4067     4138      +71     
+ Misses       1824     1753      -71     
  Partials       13       13              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decompositions give wrong results for a SymmetricMatrix or a DistanceMatrix

1 participant