Sparse/dense matrix inplace operations fail due to __numpy_ufunc__ #2938

Closed
pv opened this Issue Sep 27, 2013 · 1 comment

Comments

Projects
None yet
1 participant
Owner

pv commented Sep 27, 2013

With current Scipy master + Numpy master, the following fails:

>>> x = np.ones(4)
>>> y = scipy.sparse.csr_matrix(x)
>>> x += y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __numpy_ufunc__ not implemented for this type.

This used to work via csr_matrix.__radd__, but the current behavior in Numpy master is to pass through the exception rather than return NotImplemented, so that __radd__ is never called.

Two places to fix:

(i) The scipy.spmatrix should support the out array argument
(ii) Numpy should be fixed so that __radd__ gets called even if the __numpy_ufunc__ mechanism ends up with the conclusion that the operation is not supported.

Owner

pv commented Oct 11, 2013

Fixed in gh-2940

pv closed this Oct 11, 2013

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