-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
broadcastApplying a function over a collectionApplying a function over a collectionperformanceMust go fasterMust go fastersparseSparse arraysSparse arrays
Description
There appears to be quite poor performance when adding a Diagonal matrix to a matrix of type SparseMatrixCSC. MWE:
N = 63001
@time Diagonal(ones(N)) + spdiagm(0 => ones(N));
@time spdiagm(0 => ones(N)) + spdiagm(0 => ones(N));gives
julia> @time Diagonal(ones(N)) + spdiagm(0 => ones(N))
10.323352 seconds (77 allocations: 12.579 MiB)
julia> @time spdiagm(0 => ones(N)) + spdiagm(0 => ones(N))
0.053357 seconds (71 allocations: 12.982 MiB, 80.98% gc time)@briochemc also reports the same (see #linear-algebra in the julialang Slack)
julia> v = ones(1000) ;
julia> @btime spdiagm(0 => $v) + spdiagm(0 => $v) ; # fast
85.206 μs (40 allocations: 198.98 KiB)
julia> @btime sparse(Diagonal($v)) + spdiagm(0 => $v) ; # fastest
55.500 μs (26 allocations: 143.19 KiB)
julia> @btime Diagonal($v) + spdiagm(0 => $v) ; # slow
5.564 ms (45 allocations: 191.73 KiB)Metadata
Metadata
Assignees
Labels
broadcastApplying a function over a collectionApplying a function over a collectionperformanceMust go fasterMust go fastersparseSparse arraysSparse arrays