Open
Description
using LinearAlgebra, SparseArrays
using BenchmarkTools
julia> M = rand(500, 300);
julia> S = spzeros(size(M)...);
julia> @btime dot($M, $S);
521.241 μs (0 allocations: 0 bytes)
In comparison, even materializing S
as dense is better time-wise at this scale:
julia> @btime dot($S, $S);
236.493 ns (0 allocations: 0 bytes)
julia> @btime dot($M, $M);
42.695 μs (0 allocations: 0 bytes)
julia> @btime dot(collect($S), $M);
248.822 μs (2 allocations: 1.14 MiB)
The specialized version should iterate only on the nonzeros of the sparse matrix