Skip to content
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

Base.stack is underperforming for SparseArrays #498

Closed
rcalxrc08 opened this issue Jan 23, 2024 · 3 comments
Closed

Base.stack is underperforming for SparseArrays #498

rcalxrc08 opened this issue Jan 23, 2024 · 3 comments

Comments

@rcalxrc08
Copy link

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
@ViralBShah
Copy link
Member

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)?

@rcalxrc08
Copy link
Author

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

@ViralBShah
Copy link
Member

Yes, making a sparse matrix dense and then back sparse is a very expensive operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants