Repository navigation
Add O(nnz) issymmetric, count, ==, reverse, circshift, permutedims and sort for views and lazy adjoints of sparse matrices - #1024
Merged
Conversation
…s`, `sort`, `issymmetric` and `count` on views and lazy adjoints of sparse matrices The generic methods visit every entry. A 2-d view, or a lazy adjoint or transpose, of a sparse matrix now goes through its O(nnz) sparse copy and the existing kernels, and `issymmetric`, `ishermitian` and `count` on an adjoint or transpose use the parent in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1024 +/- ##
==========================================
- Coverage 95.63% 94.83% -0.80%
==========================================
Files 16 16
Lines 9407 9790 +383
==========================================
+ Hits 8996 9284 +288
- Misses 411 506 +95 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A view or a lazy adjoint/transpose of a sparse matrix falls to the generic elementwise method for a number of functions that the matrix itself handles in O(nnz). Found in a soundness review of the whole package; this is the follow-up batch for elementwise fallbacks. These are new methods, not bug fixes.
n = 3000, about 15,000 stored entries, one timed call after warm-up, ms / bytes. The last column is the branch at n = 200,000 with about 10⁶ stored entries, which
maincannot run in reasonable time.mainissymmetric(A')issymmetric(view(A, :, vec))count(iszero, A')V == V',V = view(A, :, 1:n)view(A, :, 1:n) + Ireverse(A')reverse(view(A, :, vec); dims=1)rot180(A')rotl90(view(A, :, 1:n))circshift(A', (1, 1))permutedims(view(A, :, vec))copy(reshape(A', n, n))sort(A'; dims=1)counton an adjoint or transpose forwards to the parent with the wrapper composed into the predicate, and allocates nothing.issymmetric/ishermitianon an adjoint or transpose ask the parent; on a view they use the view wheregetcolptrworks on it and its sparse copy otherwise. Everything else (==,isequal,reverse,rot180,rotl90,rotr90,circshift,permutedims,sort,copyof a 2-d reshape, and± Ion a view) takes the O(nnz) sparse copy of the argument and hands it to the existingSparseMatrixCSCkernel; the new allocations in the table are that copy. No dispatch alias is added: the methods are onSparseMatrixCSCSubArrayandAdjOrTrans{<:Any,<:AbstractSparseMatrixCSC}, so they cover any 2-d view, row subsets included.Touches dispatch throughout; each new method has a test that it is the one dispatched to. Not for backport.
Behaviour to know:
sort(X; dims)on a view or adjoint returns aSparseMatrixCSC, assort(A)does; the generic method returned aReshapedArray.SparseMatrixCSCkernels do; the generic path dropped them. Values are equal.isequal(V, V')for a complex view now agrees withisequal(A, A')on a plain sparse matrix, which treats the conjugate of an unstored zero as zero; dense givesfalsethere because of-0.0im.==is unaffected.Left out: an adjoint against an adjoint when one parent is a view (
V' == A'),copy(V')for a viewV, andcopy(reshape(x, len))to one dimension are still elementwise.issymmetriconview(A, :, 1:n),counton views,A' + IandA == A'were already O(nnz).A ± Ion a view checks squareness first, as onmain; #1019 makes the plain-matrix method do the same.Written by Claude Code.
🤖 Generated with Claude Code