Multiply Symmetric/Hermitian sparse matrices by sparse matrices and vectors in O(nnz) - #869
Open
ViralBShah wants to merge 2 commits into
Open
ViralBShah wants to merge 2 commits into
ViralBShah wants to merge 2 commits into
Conversation
…n O(nnz) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… O(nnz) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Symmetric/Hermitian sparse matrices by sparse matrices in O(nnz)Symmetric/Hermitian sparse matrices by sparse matrices and vectors in O(nnz)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #869 +/- ##
=======================================
Coverage 93.01% 93.01%
=======================================
Files 12 12
Lines 9076 9080 +4
=======================================
+ Hits 8442 8446 +4
Misses 634 634 ☔ 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.
*has sparse methods for plain, column-view, triangular and adjoint/transpose sparse factors, but none forSymmetric/Hermitianof a sparse matrix, so a product of one with any other sparse factor went to LinearAlgebra's generic*and an elementwise sweep into a sparse destination. This adds four methods (three for a sparse matrix on the other side, one for a sparse vector) that materialize the symmetric factor withsparse(O(nnz), like thecopythe adjoint methods already make, and like+/-with these wrappers) and use the existing sparse product. The result type is unchanged, aSparseMatrixCSC. This touches dispatch;detect_ambiguitiesagainst LinearAlgebra and Base reports none and the Aqua job passes.Nightly, n = 3000, 5 nonzeros per column:
Symmetric(A) * BA * Symmetric(B)Symmetric(A) * Symmetric(B)Symmetric(A) * Hermitian(B)Hermitian(Ac) * Hermitian(Ac, :L)(complex)Symmetric(A) * x,xaSparseVectorwith 1% storedA * B(reference)At n = 300, where main finishes quickly enough to sweep:
A' * Symmetric(B)210 → 0.085 ms,UpperTriangular(A) * Symmetric(B)120 → 0.042 ms,Symmetric(A) * UpperTriangular(B)100 → 0.039 ms.Tests:
Symmetric,HermitianandSymmetricof a column view against plain, adjoint, transpose, triangular, column-view and symmetric/Hermitian sparse factors on both sides, real and complex, plus aSparseVectorand a sparse column view on the right, checking the result type and the value against dense. Dispatch is proven withMulCount: five products of n × n identities cost exactly n multiplications, against 550 to 1200 on main for n = 10, and the sparse-vector product costs whatP * xcosts (20 against 110). FullPkg.test()passes on nightly.Left out:
mul!into a sparse destination. That is slow for every pair of sparse factors, not only these wrappers (mul!(C, A, B)with plainA,Band sparseCtakes 488 ms at n = 1000 against 0.31 ms forA * B, since it runs the dense tiled generic product and writesCby index), so it is a separate change.Written by Claude Code (Claude Fable 5.1).
🤖 Generated with Claude Code