Skip to content

SystemError for COO.dot with NumPy 1.20 #383

Closed

Description

@TomAugspurger

Describe the bug

a.dot(a) raises a SystemError (and TypeError) with the latest version of sparse and NumPy 1.20.

To Reproduce

In [1]: import sparse

In [2]: a = sparse.zeros((4, 4))

In [4]: a.dot(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
TypeError: expected dtype object, got 'numpy.dtype[float64]'

The above exception was the direct cause of the following exception:

SystemError                               Traceback (most recent call last)
<ipython-input-4-569a015a6581> in <module>
----> 1 a.dot(a)

~/Envs/dask-dev/lib/python3.7/site-packages/sparse/_coo/core.py in dot(self, other)
   1675                [ 6, 11]], dtype=int64)
   1676         """
-> 1677         return dot(self, other)
   1678
   1679     def __matmul__(self, other):

~/Envs/dask-dev/lib/python3.7/site-packages/sparse/_coo/common.py in dot(a, b)
    291     if b.ndim == 1:
    292         b_axis = -1
--> 293     return tensordot(a, b, axes=(a_axis, b_axis))
    294
    295

~/Envs/dask-dev/lib/python3.7/site-packages/sparse/_coo/common.py in tensordot(a, b, axes, return_type)
    172     at = a.transpose(newaxes_a).reshape(newshape_a)
    173     bt = b.transpose(newaxes_b).reshape(newshape_b)
--> 174     res = _dot(at, bt, return_type)
    175     return res.reshape(olda + oldb)
    176

~/Envs/dask-dev/lib/python3.7/site-packages/sparse/_coo/common.py in _dot(a, b, return_type)
    301         b = b.T
    302         coords, data = _dot_coo_coo_type(a.dtype, b.dtype)(
--> 303             a.coords, a.data, b.coords, b.data
    304         )
    305

SystemError: CPUDispatcher(<function _dot_coo_coo_type.<locals>._dot_coo_coo at 0x11a0ec8c0>) returned a result with an error set

In [6]: np.__version__
Out[6]: '1.20.0.dev0+4771e3f'

Expected behavior

With NumPy<= 1.19

In [4]: a.dot(a)
Out[4]: <COO: shape=(4, 4), dtype=float64, nnz=0, fill_value=0.0>

System

  • OS and version: [MacOS 10.14.5]
  • sparse version (0.10.0+13.g2243192)
  • NumPy version ('1.20.0.dev0+4771e3f)
  • Numba version ('0.50.1')

Additional context
Add any other context about the problem here.

It's not clear to me yet if the issue is in sparse or numba. Do you have any tips for differentiating that?

Activity

  1. added
    bug
    on Jul 20, 2020
  2. hameerabbasi commented on Jul 20, 2020

    @hameerabbasi
    Collaborator

    Thanks for the report. The issue is almost certainly in Numba, given the new dtype changes that went into NumPy 1.20. I will try to get a reproducer when I’m back from vacation (which is Wednesday).

  3. eric-wieser commented on Jul 21, 2020

    @eric-wieser
    Contributor

    The fact that this gives SystemError is a pretty strong indication that this is a numba bug.

  4. seberg commented on Jul 21, 2020

    @seberg

    Well, there were some changes in dot and the function using dot (I assume the dtype discovery itself has nothing to do with it, since would have larger fallout). Since the error-paths in that function were buggy, its plausible that there was a sublte change, or just the fix of the error handling causing an error to be raised that was previously cleared.

    Let me know if I should track the bug down.

  5. TomAugspurger commented on Jul 21, 2020

    @TomAugspurger
    Author

    cc @sklam for the numba side, since that's likely where the work will need to be done. This probably boils down to "numba support for NumPy 1.20". Apologies that I don't have a minimal reproducible example yet.

  6. eric-wieser commented on Jul 21, 2020

    @eric-wieser
    Contributor

    Well, SystemError boils down to "numba thought something could never fail but then it did". You should never assume a python API call will not fail.

  7. hameerabbasi commented on Jul 22, 2020

    @hameerabbasi
    Collaborator

    @TomAugspurger are you still seeing this with NumPy master? Because I don't see it. I installed everything else the same as you did.

    In [1]: import sparse
    
    In [2]: a = sparse.zeros((4, 4))
    
    In [3]: a.dot(a)
    Out[3]: <COO: shape=(4, 4), dtype=float64, nnz=0, fill_value=0.0>
    
    In [5]: import numpy as np
    
    In [6]: np.__version__
    Out[6]: '1.20.0.dev0+82efaab'
  8. TomAugspurger commented on Jul 28, 2020

    @TomAugspurger
    Author

    I just tried again with the following versions, and saw the TypeError followed by a SystemError.

    $ pip list 
    Package    Version
    ---------- -------------------
    llvmlite   0.33.0
    numba      0.50.1
    numpy      1.20.0.dev0+1ce5457
    pip        19.2.3
    scipy      1.5.2
    setuptools 41.2.0
    sparse     0.10.0
    
  9. added and removed
    bug
    on Jul 28, 2020
  10. hameerabbasi commented on Jul 28, 2020

    @hameerabbasi
    Collaborator

    Reported upstream at numba/numba#6041

  11. eric-wieser commented on Jul 28, 2020

    @eric-wieser
    Contributor

    The upstream report has no SystemError - can you construct one that does?

  12. hameerabbasi commented on Jul 28, 2020

    @hameerabbasi
    Collaborator

    The SystemError was raised due to that exception, which was the root cause.

    Just replace the return line with

    return np.empty((2, 0), dtype=np.intp), np.empty((0,), dtype=dtr)
    
  13. eric-wieser commented on Jul 28, 2020

    @eric-wieser
    Contributor

    SystemError is an indication of invalid code being generated, which is definitely worth reporting separately

  14. eric-wieser commented on Jul 28, 2020

    @eric-wieser
    Contributor

    Does this reproduce it too?

    np.empty((2, 0), dtype=np.intp)
    return True
    
  15. hameerabbasi commented on Jul 28, 2020

    @hameerabbasi
    Collaborator

    No, it doesn't.

  16. eric-wieser commented on Jul 28, 2020

    @eric-wieser
    Contributor

    I think the systemerror is caused by the numba tuple boxer being broken.

  17. hameerabbasi commented on Aug 6, 2020

    @hameerabbasi
    Collaborator

    The original error should be fixed in Numba master.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions