You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Performance bencmarks comparison with scipy.sparse #331
I see there is an asv setup in the repo but I couldn't find any results.
How does pydata/sparse currently compare to scipy.sparse (e.g. for dot product)? Or is most of linalg operations expected to use scipy.sparse.linlag in the long run and so the performance would be equivalent?
In [3]: x = sparse.random((5000, 5000), density=0.001)
In [4]: y = sparse.random((5000, 5000), density=0.001)
In [5]: %timeit x + y # Numba compilation
5.86 ms ± 190 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [6]: %timeit x + y
5.97 ms ± 70.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
In [7]: xs = x.tocsr()
In [8]: ys = y.tocsr()
In [9]: %timeit xs + ys
408 µs ± 8.44 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [11]: %timeit x @ y
1.05 s ± 18.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [12]: %timeit xs @ ys
1.09 ms ± 17.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
It seems like matmul could easily be improved though right? I just had a peek at the SciPy implementation (csr_matmul in sparsetools/csr.h) and it's a relatively straightforward triple for-loop in C++. So I guess no one has put much effort into a similar Numba implementation here, otherwise it wouldn't be 1000x slower.
Not that I'm suggesting to optimize that right now, I just want to say there's no fundamental reason why it's slow, just no one got around to it since this package is still new.
Activity
hameerabbasi commentedon Mar 10, 2020
Tl;dr: It's bad. Sometimes 10 times worse, even for element-wise operations.
We're looking at approaches that essentially guarantee optimal performance and GPU support in all cases (#326). However, we don't have a ETA for this.
hameerabbasi commentedon Mar 10, 2020
hameerabbasi commentedon Mar 10, 2020
For
__matmul__:rth commentedon Mar 10, 2020
Thanks for the explanations @hameerabbasi !
rgommers commentedon Mar 10, 2020
It seems like
matmulcould easily be improved though right? I just had a peek at the SciPy implementation (csr_matmulinsparsetools/csr.h) and it's a relatively straightforward triple for-loop in C++. So I guess no one has put much effort into a similar Numba implementation here, otherwise it wouldn't be 1000x slower.rgommers commentedon Mar 10, 2020
Not that I'm suggesting to optimize that right now, I just want to say there's no fundamental reason why it's slow, just no one got around to it since this package is still new.
hameerabbasi commentedon Mar 10, 2020
dotis implemented in Numba here:sparse/sparse/_coo/common.py
Line 1150 in 98a39cd
Perhaps the memoization isn't working.
hameerabbasi commentedon Jun 1, 2020
#350 makes this a bit better.