19 Jun 2013 01:39
__bool__ for sparse matrices
Blake Griffith <blake.a.griffith <at> gmail.com>
2013-06-18 23:39:44 GMT
2013-06-18 23:39:44 GMT
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.
_______________________________________________ SciPy-Dev mailing list SciPy-Dev <at> scipy.org http://mail.scipy.org/mailman/listinfo/scipy-dev
RSS Feed