特征::<Derived> <Derived> 当列数固定时,无法将块转换为 Ref
Eigen:: cannot convert Block<Derived> to Ref<Derived> when number of cols is fixed
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)解决了此问题。话虽如此,您可以向特征开发人员提交错误报告,以确保注意到这一点(尽管在您这样做时,他们可能已经看过这篇文章了)。
相关文章:
- EASTL矢量<向量<int>>连续的
- 将sharet_ptr<Derived>转换为shared_ptr<Base>
- 从 std<Derived>::shared_ptr 的向量返回 std::shared_ptr<Base>
- 如何使用"derived input class"创建派生类?
- 如何从unique_ptr返回unique_ptr的引用<Derived><Base>?
- 如何将unique_ptr<derived>*转换为<base>unique_ptr*?
- <Base> <Derived> 具有相同原始指针共享引用的 shared_ptr 和 shared_ptr 实例是否计数?
- 如何从 Eigen::MatrixBase <Derived>获取存储选项
- 两个成员,在Base中默认初始化,可能在Derived中非默认初始化
- 从"<Base>std::unique_ptr"创建"ClassType<std::unique_ptr>"时出现编译错误<Derived>
- 为什么在此示例中从unique_ptr自动向上转换<derived>到unique_ptr<base>失败?
- 为什么unique_ptr<Derived>隐式投射到unique_ptr<Base>?
- 候选函数不可行:没有从 std::vector<derived> 到 std::vector <base>的已知转换
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- C 字符串比较“祝您好运”&gt;“再见”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- 将static_pointer_cast添加到<Derived> std::list<shared_ptr<Base>> 会导致称为 error 的纯虚拟方法
- 派生到矩阵库转换背后的故事<Derived>
- 如何将标准::make_unique<derived>() 转换为标准::unique_ptr<base>
- 最快的方式 std::vector<Derived> to std::vector<Base>