Skip to content

Performance bencmarks comparison with scipy.sparse #331

Closed

Description

@rth

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?

Activity

  1. hameerabbasi commented on Mar 10, 2020

    @hameerabbasi
    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.

  2. hameerabbasi commented on Mar 10, 2020

    @hameerabbasi
    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)
    
  3. hameerabbasi commented on Mar 10, 2020

    @hameerabbasi
    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)
    
  4. rth commented on Mar 10, 2020

    @rth
    Author

    Thanks for the explanations @hameerabbasi !

  5. rgommers commented on Mar 10, 2020

    @rgommers

    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.

  6. rgommers commented on Mar 10, 2020

    @rgommers

    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.

  7. hameerabbasi commented on Mar 10, 2020

    @hameerabbasi
    Collaborator

    dot is implemented in Numba here:

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

    Perhaps the memoization isn't working.

  8. hameerabbasi commented on Jun 1, 2020

    @hameerabbasi
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions