本征3.3 SparseMatrix< bool>运作 [英] eigen 3.3 SparseMatrix<bool> operations

查看:77
本文介绍了本征3.3 SparseMatrix< bool>运作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Eigen :: SparseMatrix< bool> 来执行操作,而不必自己循环矩阵。
这在Eigen 3.2中曾经是可能的,但是该代码不再在3.3版中进行编译。
例如,以下代码在3.2中可以正常工作:

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;

在Eigen 3.3中是否有简单/简短的方法来执行与和或运算而无需

Is there an easy/short way of doing "and" and "or" operations in Eigen 3.3 without writing loops?

推荐答案

为了与c ++标准行为保持一致,现在添加布尔矩阵会返回整数表达式,但是同时,由于不明确,不建议添加布尔矩阵。使用密集矩阵,您可以使用运算符 ||| && 进行操作,而这些操作必须也可以添加到稀疏矩阵中(对于3.3.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).

同时,您仍然可以通过将结果强制转换为bool来解决(并忽略不建议使用的警告):

Meanwhile, you can still workaround by casting the result to bool (and ignore the deprecated warning):

a = (b+c).cast<bool>();

这篇关于本征3.3 SparseMatrix&lt; bool&gt;运作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆