perf: use Matrix.gram() for XtX#28
Merged
Merged
Conversation
XtX = Xt.mmul(X) is the symmetric Gram matrix XᵀX. ml-matrix 6.13.0 adds Matrix.gram() which computes only the upper triangle and skips zero entries, so it is ~2x faster on dense inputs and far faster on sparse ones. On the 98.7%-sparse spectral test fixture the full fcnnls run drops from ~29.7 ms to ~3.2 ms per iteration (~9x), with bit-identical results. Also bump ml-matrix to ^6.13.0 (required for gram()) and rework the benchmark into a reproducible warmup + best-of-N harness. Assisted-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1b86891 to
8e2a244
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #28 +/- ##
=======================================
Coverage 93.38% 93.38%
=======================================
Files 18 18
Lines 272 272
Branches 54 54
=======================================
Hits 254 254
Misses 15 15
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Replace
XtX = Xt.mmul(X)withX.gram()(new in ml-matrix 6.13.0) and bumpml-matrixto^6.13.0. Bit-identical results;gram()skips zero entries, so on the 98.7%-sparse spectral fixture the XtX product (which dominated runtime) drops ~9×.