[SciPy-Dev] __bool__ for sparse matrices

Blake Griffith blake.a.griffith@gmail....
Tue Jun 18 18:39:44 CDT 2013

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.scipy.org/pipermail/scipy-dev/attachments/20130618/3dcae163/attachment.html 

More information about the SciPy-Dev mailing list