Repository navigation
Closed
Labels
Description
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]
sparseversion (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
hameerabbasi commentedon Jul 20, 2020
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).
eric-wieser commentedon Jul 21, 2020
The fact that this gives SystemError is a pretty strong indication that this is a numba bug.
seberg commentedon Jul 21, 2020
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.
TomAugspurger commentedon Jul 21, 2020
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.
eric-wieser commentedon Jul 21, 2020
Well,
SystemErrorboils down to "numba thought something could never fail but then it did". You should never assume a python API call will not fail.hameerabbasi commentedon Jul 22, 2020
@TomAugspurger are you still seeing this with NumPy master? Because I don't see it. I installed everything else the same as you did.
TomAugspurger commentedon Jul 28, 2020
I just tried again with the following versions, and saw the TypeError followed by a SystemError.
hameerabbasi commentedon Jul 28, 2020
Reported upstream at numba/numba#6041
eric-wieser commentedon Jul 28, 2020
The upstream report has no SystemError - can you construct one that does?
hameerabbasi commentedon Jul 28, 2020
The SystemError was raised due to that exception, which was the root cause.
Just replace the
returnline witheric-wieser commentedon Jul 28, 2020
SystemError is an indication of invalid code being generated, which is definitely worth reporting separately
eric-wieser commentedon Jul 28, 2020
Does this reproduce it too?
hameerabbasi commentedon Jul 28, 2020
No, it doesn't.
eric-wieser commentedon Jul 28, 2020
I think the systemerror is caused by the numba tuple boxer being broken.
hameerabbasi commentedon Aug 6, 2020
The original error should be fixed in Numba
master.