Skip to content

Performance bencmarks comparison with scipy.sparse #331

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

Closed
rth opened this issue Mar 10, 2020 · 8 comments
Closed

Performance bencmarks comparison with scipy.sparse #331

rth opened this issue Mar 10, 2020 · 8 comments

Comments

@rth
Copy link

rth commented Mar 10, 2020

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?

@rth rth added the support label Mar 10, 2020
@hameerabbasi
Copy link
Collaborator

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
Copy link
Collaborator

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)

@hameerabbasi
Copy link
Collaborator

For __matmul__:

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)

@rth
Copy link
Author

rth commented Mar 10, 2020

Thanks for the explanations @hameerabbasi !

@rgommers
Copy link

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.

@rgommers
Copy link

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
Copy link
Collaborator

dot is implemented in Numba here:

def _dot_coo_coo(coords1, data1, coords2, data2): # pragma: no cover

Perhaps the memoization isn't working.

@hameerabbasi
Copy link
Collaborator

#350 makes this a bit better.

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

No branches or pull requests

3 participants