特征::<Derived> <Derived> 当列数固定时,无法将块转换为 Ref

Eigen:: cannot convert Block<Derived> to Ref<Derived> when number of cols is fixed

本文关键字:Derived gt lt Ref 转换 特征 定时      更新时间:2023-10-16

i最近已更新到最近的eigen版本(3.3.90),看起来我虽然打破了我之前正在工作的东西(在此之前我使用了特征版本3.2.10,已运送了libigl库)。

我想将一个块的结果存储到一个将传递的ref对象中,并最终用于更新提取块的矩阵表单的内部。

最小示例,不再编译:

#include <Eigen/Dense>
int main(int argc, char *argv[])
{
  typedef Eigen::Matrix<bool, Eigen::Dynamic, 1> Mtype;
  typedef Eigen::Block<Mtype> Btype;
  typedef Eigen::Ref<Mtype> Rtype;
  Mtype m(2, 1);
  Btype bm = m.block(0, 0, 1, 1);
  Rtype rm = m; // OK
  Rtype rbm = bm; // Visual studio 2017 error C2440: 'initialisation' : impossible conversion
}

请注意,const版本确实有效,我认为这是由于CONS的专业化造成的,该专业重新创建了临时副本:

typedef Eigen::Ref<const Mtype> CRtype;
CRtype crbm = bm; // OK

类似地,使用行数和cols dynamic 的矩阵类型,也编译:

typedef Eigen::Matrix<bool, Eigen::Dynamic, Eigen::Dynamic> Mtype;
typedef Eigen::Block<Mtype> Btype;
typedef Eigen::Ref<Mtype> Rtype;
Mtype m(2, 1);
Btype bm = m.block(0, 0, 1, 1);
Rtype rbm = bm;

有线索?

非常感谢!

最好的问候

Jerome

我以前的答案的结论太快了。现在已修复:https://bitbucket.org/eigen/eigen/commits/cacb7b4ace39/

尽管如此,最好将编译时向量作为编译时向量仍然更好。此信息被Block<VectorXd>(和m.block(0, 0, 1, 0))丢失,因为它可能在运行时具有1或0列,例如:

Block<VectorXd> bm = m.block(0, 0, 1, 0);

很好。因此,在您的情况下,我仍然建议保留此信息,例如:

auto bm = m.segment(0,1);
auto bm = m.block(0,0,1,fix<1>);       // fix is new in Eigen 3.4
auto bm = m.block<Dynamic,1>(0,0,1,1); // <3.4 version of the above cleaner line

这是您应该真正使用auto的典型情况。您也可以直接初始化参考文献,例如:

Ref<MType> rm = m.segment(0,1);

eigen版本3.3.90是一个开发分支,那里的东西可能会破坏。使用最新的稳定版本(3.3.7)解决了此问题。话虽如此,您可以向特征开发人员提交错误报告,以确保注意到这一点(尽管在您这样做时,他们可能已经看过这篇文章了)。