Open
Description
I posted this originally as a question here https://discourse.julialang.org/t/slow-arithmetic-on-views-of-sparse-matrices/3644 and got some useful feedback. It seems though that this functionality could be built into julia proper.
Arithmetic on views of sparse matrices fall back on general methods and are thus slow. Here is an example:
d = sprand(Bool,10000,10000, 0.01)
e = view(d, rand(1:10000,5000), rand(1:10000,9000))
using BenchmarkTools
@benchmark sum($d, 1)
BenchmarkTools.Trial:
memory estimate: 78.20 KiB
allocs estimate: 2
--------------
minimum time: 421.354 μs (0.00% GC)
median time: 450.828 μs (0.00% GC)
mean time: 463.575 μs (0.00% GC)
maximum time: 1.226 ms (0.00% GC)
--------------
samples: 10000
evals/sample: 1
@benchmark sum($e, 1)
BenchmarkTools.Trial:
memory estimate: 585.06 KiB
allocs estimate: 51
--------------
minimum time: 3.286 s (0.00% GC)
median time: 3.312 s (0.00% GC)
mean time: 3.312 s (0.00% GC)
maximum time: 3.339 s (0.00% GC)
--------------
samples: 2
evals/sample: 1
Specialized functions for these operations should fix this.
This appears to be related to (but not identical to?) JuliaLang/julia#13438
Metadata
Metadata
Assignees
Labels
No labels