[SciPy-Dev] __bool__ for sparse matrices
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...
More information about the SciPy-Dev