eigen 3.3 SparseMatrix<bool> operations

…衆ロ難τιáo~ 提交于 2019-12-25 08:13:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!