-
-
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
Multiplication of sparse matrices with diagonal matrices is slow (fix suggested) #28934
Comments
This bug is related to incorrect function dispatch julia/stdlib/SparseArrays/src/linalg.jl Line 971 in c8450d8
There is no Let's see first several lines of profile
See, it is not diapatched correctly as @Pbellive mensioned. |
Thanks @GiggleLiu. I missed that the correct implementation existed in linalg.jl. Just need to change the type signatures to fix the bug. Nice and easy. Preparing a PR now. |
Hi all,
It's great to see all the work that's gone into the linear algebra support for 1.0! I've recently noticed one small area where I think significant performance is being left on the table. Namely, multiplication of sparse matrices with diagonal matrices. This was also mentioned last month on discourse. Multiplication between diagonal matrices and sparse matrices is currently defined at:
julia/stdlib/SparseArrays/src/linalg.jl
Lines 129 to 136 in 255030e
these methods seem to fall back to pretty generic matrix multiplication methods and not to any of the specialized methods defined in stdlib/LinearAlgebra/src/diagonal.jl. I've written a couple of potential replacements. The versions for right multiplying a sparse matrix by a diagonal matrix are benchmarked below. Please let me know if there is a reason why something similar hasn't been implemented already. If it's just an oversight then I can prepare a PR to add in the optimized methods. The benchmarking was run on a fresh clone of master from this morning
To benchmark I did the following. I wrote the following script and saved it to a file bnchmrkDiag.jl
Then from the REPL I did
As you can see the simple
B * D
is incredibly slow compared to the others. As you would expect, the differences become more significant for larger matrices. I re ran the benchmarks withFor reference, that gave
nnz(B)/n = 50.00124
. I got impatient and killed theB * D
benchmark after about a minute. The results for the other methods wereYou see about the same thing for left multiplication by a diagonal matrix.
Thanks, Patrick
The text was updated successfully, but these errors were encountered: