[SciPy-Dev] __bool__ for sparse matrices

Blake Griffith blake.a.griffith at gmail.com
Wed Jun 19 11:31:50 EDT 2013


It looks like the ndarray inequality methods are basically ufuncs. So I'm
running into the problem of overriding ufuncs.


On Tue, Jun 18, 2013 at 6:39 PM, Blake Griffith
<blake.a.griffith at gmail.com>wrote:

> Recently I've been implementing boolean comparisons for sparse matrices,
> I've run into a problem supporting dense matrices.
>
> If A is a dense ndarray, and B is a sparse matrix. And I do:
>
>     A bool_op B
>
> The ndarray calls B.__bool__() for some reason, and I have not figured out
> how to set __bool__ to work appropriately for all bool ops. In my last PR I
> set __bool__ to raise a ValueError, like ndarrays do. And this is ok for A
> == B and A != B. In these cases, the sparse matrix B handles the operation,
> like it should. With __bool__ set to True or False, the ndarray tries to
> handle the operation and fails.
>
> But with A < B, A > B, the ValueError in bool is raised. So I'm not sure
> what to do.
>
> Any suggestions? I'm currently looking for the rich comparison
> implementation for ndarrays.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20130619/475992a8/attachment.html>


More information about the SciPy-Dev mailing list