SparseArrays.jl
SparseArrays.jl copied to clipboard
Base.stack is underperforming for SparseArrays
Describe the bug Stacking arrays of SparseArrays is slow. Similar to JuliaGPU/CUDA.jl#2248.
To reproduce
The Minimal Working Example (MWE) for this bug:
using BenchmarkTools, SparseArrays;
N=100;
M=1000;
x=spzeros(N);
x[1]=10.0;
x_dense=collect(x);
@btime stack(fill($x,$M));
@btime stack(fill($x_dense,$M));
@btime sparse(stack(fill(collect($x),$M)));
As timing I am getting:
2.211 ms (15 allocations: 75.20 KiB)
74.900 μs (3 allocations: 789.23 KiB)
194.600 μs (7 allocations: 813.98 KiB)
Version info
Details on Julia: 1.10
Julia Version 1.10.0
Commit 3120989f39 (2023-12-25 18:01 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 8 × Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, skylake)
Threads: 1 on 8 virtual cores
Stacking sparse arrays should be slower compared to dense arrays. Is this issue that it is too slow (compared to some other system, or a regression)?
Stacking sparse arrays should be slower compared to dense arrays. Is this issue that it is too slow (compared to some other system, or a regression)?
Should it be slower than moving to dense, stacking, and moving back to Sparse? I don't think so
Yes, making a sparse matrix dense and then back sparse is a very expensive operation.