-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SparseArrays: Speed up right-division by diagonal matrices #35533
SparseArrays: Speed up right-division by diagonal matrices #35533
Conversation
6cbecdb
to
f95beb5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2-arg *div!
s should work, at least they exist.
f95beb5
to
de7b264
Compare
S**t, I thought I wrote a long comment, but must have forgotten to push the button. To make the long story short, the left-division is currently working nicely, there is no need for an additional method. The right-division is not too bad in that it doesn't fall back to generic dense methods or whatever, but can be improved still using SparseArrays, LinearAlgebra, BenchmarkTools, Test
A = sprand(10000,10000,0.1);
D = Diagonal(rand(10000));
function mydiv(A::AbstractMatrix, D::Diagonal)
rdiv!(typeof(oneunit(eltype(A))/oneunit(eltype(D))).(A), D)
end
@test A/D ≈ mydiv(A, D)
@btime mydiv($A, $D);
@btime $A / $D;
@btime $D \ $A; # for comparison with mydiv My function julia/stdlib/LinearAlgebra/src/diagonal.jl Lines 486 to 487 in ac82513
to |
@dkarrasch Do you suggest to provide a generic method for Should we instead relax the existing division operator to include sparse matrices only? |
Yes. Look at this one: julia/stdlib/LinearAlgebra/src/diagonal.jl Lines 597 to 598 in ac82513
If there is an issue with the underlying |
eeff9f2
to
9d4c542
Compare
@dkarrasch Done. |
Ok, my sincere apologies for the mess. Now we've got a method ambiguity. Apparently, there is a subtle reason for the different signatures of function (/)(A::AbstractSparseMatrixCSC, D::Diagonal)
T = typeof(oneunit(eltype(A))/oneunit(eltype(D)))
rdiv!(LinearAlgebra.copy_oftype(A, T), D)
end to Initially, my main point was that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry again for the back and forth, this time just a trivial comment on the tests, and I hope with my last suggestion we'll be all set.
9d4c542
to
a73f14e
Compare
@dkarrasch Done. Thanks for the suggestions; this is now a much better implementation. |
@eschnett Ok, the tests look good now, but you still have the method ambiguity due to my own bold suggestion (sorry again). You'll need to undo the change in |
a73f14e
to
5b740f5
Compare
Sorry, did not see your final comment earlier. I didn't spot the method ambiguity when I ran the test suite locally. |
* origin/master: (833 commits) Improve typesubtract for tuples (#35600) Make searchsorted*/findnext/findprev return values of keytype (#32978) fix buggy rand(RandomDevice(), Bool) (#35590) remove `Ref` allocation on task switch (#35606) Revert "partr: fix multiqueue resorting stability" (#35589) exclude types with free variables from `type_morespecific` (#35555) fix small typo in NEWS.md (#35611) enable inline allocation of structs with pointers (#34126) SparseArrays: Speed up right-division by diagonal matrices (#35533) Allow hashing 1D OffsetArrays NEWS item for introspection macros (#35594) Special case empty covec-diagonal-vec product (#35557) [GCChecker] fix a few tests by looking through casts Use norm instead of abs in generic lu factorization (#34575) [GCChecker,NFC] run clang-format -style=llvm [GCChecker] fix tests and add Makefile Add introspection macros support for dot syntax (#35522) Specialize `union` for `OneTo` (#35577) add pop!(vector, idx, [default]) (#35513) bump Pkg version (#35584) ...
No description provided.