问题
I would like to perform operations using Eigen::SparseMatrix<bool>
without having to loop the matrices myself.
This used to be possible in Eigen 3.2 but that code no longer compiles in version 3.3.
For instance, the following code worked fine in 3.2:
Eigen::SparseMatrix<bool> a(3,3), b(3,3), c(3,3);
a = b + c;
Is there an easy/short way of doing "and" and "or" operations in Eigen 3.3 without writing loops?
回答1:
To be consistent with c++ standard behavior, adding boolean matrices now returns integer expressions, but at the same time, because of the ambiguity adding boolean matrices is deprecated. With dense matrices, you have access to operators ||
and &&
for that purpose, and these have to be added to sparse matrices too (for 3.3.1).
Meanwhile, you can still workaround by casting the result to bool (and ignore the deprecated warning):
a = (b+c).cast<bool>();
来源:https://stackoverflow.com/questions/40537884/eigen-3-3-sparsematrixbool-operations