[Numpy-discussion] Sparse matrix hooks

Pearu Peterson pearu at scipy.org
Mon Feb 27 03:09:04 CST 2006


On Mon, 27 Feb 2006, Ed Schofield wrote:

>
> I'm trying to improve integration between SciPy's sparse matrices and
> NumPy's dense array/matrix objects.  One problem I'm facing is that
> NumPy matrices redefine the * operator to call NumPy's dot() function.
> Since dot() has no awareness of SciPy's sparse matrix objects, this
> doesn't work for the operation 'dense * sparse'.  (It does work for
> sparse * dense, which calls sparse.__mul__ first.)

Have you tried defining sparse.__rmul__? dense.__mul__ should raise
an exception when it does not know about the rhs operant and then Python 
calls <rhs operant>.__rmul__.

Pearu




More information about the Numpy-discussion mailing list