[SciPy-User] Sparse matrices and dot product
Dag Sverre Seljebotn
dagss@student.matnat.uio...
Tue Nov 30 01:25:12 CST 2010
On 11/29/2010 12:51 PM, Pauli Virtanen wrote:
> Sun, 28 Nov 2010 18:32:39 -0800, Nathaniel Smith wrote:
> [clip]
>
>> If it's been decided that ndarray's should have a dot method, then I
>> agree that sparse matrices should too -- for compatibility. But it
>> doesn't actually solve the problem of writing generic code. If A is
>> dense and B is sparse, then A.dot(B) still won't work.
>>
> Yes, the .dot() method does not fully solve the generic code problem, and
> adding it was not motivated by that. However, in iterative methods you
> often only want to compute matrix-dense-vector products, and for that
> particular case it happens to be enough.
>
>
>> I just spent a few minutes trying to work out if this is fixable by
>> defining a protocol -- you need like an __rdot__ or something? -- but
>> didn't come up with anything I'd want to actually recommend.
>>
> The no-brain approach would probably be to ape what Python is doing,
> i.e., __dot__, __rdot__, and returning NotImplemented when the operation
> is not supported by a particular routine. I didn't try to think this
> fully out, though, so I don't know if there are some roadblocks.
>
A simple solution would be a __dotpriority__ integer (it'd seem to me
that the point is to have the correct class do the handling; left-mul
vs. right-mul doesn't matter that much).
That has it's own set of problems, and a more general but also more
heavy-weight solution may be this:
https://github.com/friedrichromstedt/priop
Here's the thread:
http://www.mail-archive.com/numpy-discussion@scipy.org/msg27895.html
But a solution like this may be the stuff of 3rd party libraries, not
something to put into NumPy *shrug*.
Dag Sverre
More information about the SciPy-User
mailing list