-
Notifications
You must be signed in to change notification settings - Fork 52
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
dot(::SparseMatrixCSC, ::Array) should be specialized #23
Comments
Implementation proposal. This must be tweaked back to get the recursive version of fast_dot(x, y) = dot(x, y)
function fast_dot(A::Matrix{T1}, B::SparseArrays.SparseMatrixCSC{T2}) where {T1, T2}
T = promote_type(T1, T2)
(m, n) = size(A)
if (m, n) != size(B)
throw(DimensionMismatch("Size mismatch"))
end
s = zero(T)
if m * n == 0
return s
end
rows = SparseArrays.rowvals(B)
vals = SparseArrays.nonzeros(B)
for j in 1:n
for ridx in SparseArrays.nzrange(B, j)
i = rows[ridx]
v = vals[ridx]
s += v * A[i,j]
end
end
return s
end
julia> @btime fast_dot($M, $S);
389.750 ns (0 allocations: 0 bytes)
# the default version calling dot
julia> @btime fast_dot($S, $M);
632.688 μs (0 allocations: 0 bytes) |
Make a PR? |
Yes that's on the way, I just wanted to be sure I hadn't missed ongoing work on that (didn't have master built on my machine) |
@dkarrasch may know. I am not aware of it - but I might have missed something. |
There will be another PR to add in the same spirit on structurally sparse matrices from LinearAlgebra: |
Kicking the can of worms after seeing related issues: https://github.com/JuliaLang/julia/issues/31330 I think |
this could even be used to make the |
In comparison, even materializing
S
as dense is better time-wise at this scale:The specialized version should iterate only on the nonzeros of the sparse matrix
The text was updated successfully, but these errors were encountered: