参考博客:https://www.cnblogs.com/wongyi/p/8734346.HTML
1. 数据类型报错
/home/wy/workdir/slambook/ch3/useEigen/build> make -j2Scanning dependencIEs of target eigenMatrix[ 50%] Building CXX object CMakefiles/eigenMatrix.dir/eigenMatrix.cpp.oIn file included from /usr/include/eigen3/Eigen/Core:348:0,from /home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:5:/usr/include/eigen3/Eigen/src/Core/Product.h: In instantiation of ‘struct Eigen::internal::product_result_scalar<Eigen::Matrix<float,2,3>,Eigen::Matrix<double,3,1>,Eigen::DenseShape,Eigen::DenseShape>’:/usr/include/eigen3/Eigen/src/Core/Product.h:78:73: required from ‘struct Eigen::internal::traits<Eigen::Product<Eigen::Matrix<float,0> >’/usr/include/eigen3/Eigen/src/Core/Product.h:151:7: required from ‘class Eigen::internal::dense_product_base<Eigen::Matrix<float,0,3>’/usr/include/eigen3/Eigen/src/Core/Product.h:183:7: required from ‘class Eigen::ProductImpl<Eigen::Matrix<float,Eigen::Dense>’/usr/include/eigen3/Eigen/src/Core/Product.h:107:7: required from ‘class Eigen::Product<Eigen::Matrix<float,0>’/home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:52:65: required from here/usr/include/eigen3/Eigen/src/Core/Product.h:41:98: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float,double>’ typedef typename scalar_product_traits<typename Lhs::Scalar,typename Rhs::Scalar>::ReturnType Scalar; ^In file included from /usr/include/eigen3/Eigen/Core:344:0,from /home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:5:/usr/include/eigen3/Eigen/src/Core/DenseBase.h: In instantiation of ‘class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<float,0> >’:/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:48:34: required from ‘class Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0>’/home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:52:65: required from here/usr/include/eigen3/Eigen/src/Core/DenseBase.h:78:25: error: using-declaration for non-member at class scope using Base::operator*; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:79:25: error: using-declaration for non-member at class scope using Base::operator/; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:80:17: error: using-declaration for non-member at class scope using Base::derived; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:81:17: error: using-declaration for non-member at class scope using Base::const_cast_derived; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:82:17: error: using-declaration for non-member at class scope using Base::rows; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:83:17: error: using-declaration for non-member at class scope using Base::cols; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:84:17: error: using-declaration for non-member at class scope using Base::size; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:85:17: error: using-declaration for non-member at class scope using Base::rowIndexByOuterInner; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:86:17: error: using-declaration for non-member at class scope using Base::colindexByOuterInner; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:87:17: error: using-declaration for non-member at class scope using Base::coeff; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:88:17: error: using-declaration for non-member at class scope using Base::coeffByOuterInner; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:89:26: error: using-declaration for non-member at class scope using Base::operator(); ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:90:26: error: using-declaration for non-member at class scope using Base::operator[]; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:91:17: error: using-declaration for non-member at class scope using Base::x; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:92:17: error: using-declaration for non-member at class scope using Base::y; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:93:17: error: using-declaration for non-member at class scope using Base::z; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:94:17: error: using-declaration for non-member at class scope using Base::w; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:95:17: error: using-declaration for non-member at class scope using Base::strIDe; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:96:17: error: using-declaration for non-member at class scope using Base::innerStrIDe; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:97:17: error: using-declaration for non-member at class scope using Base::outerStrIDe; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:98:17: error: using-declaration for non-member at class scope using Base::rowStrIDe; ^/usr/include/eigen3/Eigen/src/Core/DenseBase.h:99:17: error: using-declaration for non-member at class scope using Base::colStrIDe; ^In file included from /usr/include/eigen3/Eigen/Core:345:0,from /home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:5:/usr/include/eigen3/Eigen/src/Core/MatrixBase.h: In instantiation of ‘class Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >’:/usr/include/eigen3/Eigen/src/Core/Product.h:151:7: required from ‘class Eigen::internal::dense_product_base<Eigen::Matrix<float,0>’/home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:52:65: required from here/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:70:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<float,0> >}::derived’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::derived; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:71:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::const_cast_derived’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::const_cast_derived; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:72:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::rows’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::rows; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:73:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::cols’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::cols; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:74:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::size’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::size; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:75:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::coeff’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::coeff; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:76:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::coeffRef’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::coeffRef; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:78:17: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::eval’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::eval; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:81:25: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::operator*=’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::operator*=; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:82:25: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::operator/=’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::operator/=; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:83:25: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::operator*’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::operator*; ^/usr/include/eigen3/Eigen/src/Core/MatrixBase.h:84:25: error: no members matching ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}::operator/’ in ‘Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<float,0> >}’ using Base::operator/; ^In file included from /usr/include/eigen3/Eigen/Core:62:0,from /home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:5:/usr/include/eigen3/Eigen/src/Core/Product.h: In instantiation of ‘class Eigen::ProductImpl<Eigen::Matrix<float,Eigen::Dense>’:/usr/include/eigen3/Eigen/src/Core/Product.h:107:7: required from ‘class Eigen::Product<Eigen::Matrix<float,0>’/home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:52:65: required from here/usr/include/eigen3/Eigen/src/Core/util/Macros.h:790:15: error: no members matching ‘Eigen::ProductImpl<Eigen::Matrix<float,Eigen::Dense>::Base {aka Eigen::internal::dense_product_base<Eigen::Matrix<float,3>}::derived’ in ‘Eigen::ProductImpl<Eigen::Matrix<float,Eigen::Dense>::Base {aka class Eigen::internal::dense_product_base<Eigen::Matrix<float,3>}’ using Base::derived; ^/usr/include/eigen3/Eigen/src/Core/util/Macros.h:796:3: note: in expansion of macro ‘EIGEN_GENERIC_PUBliC_INTERFACE’ EIGEN_GENERIC_PUBliC_INTERFACE(Derived) ^/usr/include/eigen3/Eigen/src/Core/Product.h:191:5: note: in expansion of macro ‘EIGEN_DENSE_PUBliC_INTERFACE’ EIGEN_DENSE_PUBliC_INTERFACE(Derived) ^/usr/include/eigen3/Eigen/src/Core/util/Macros.h:791:15: error: no members matching ‘Eigen::ProductImpl<Eigen::Matrix<float,3>}::const_cast_derived’ in ‘Eigen::ProductImpl<Eigen::Matrix<float,3>}’ using Base::const_cast_derived; ^/usr/include/eigen3/Eigen/src/Core/util/Macros.h:796:3: note: in expansion of macro ‘EIGEN_GENERIC_PUBliC_INTERFACE’ EIGEN_GENERIC_PUBliC_INTERFACE(Derived) ^/usr/include/eigen3/Eigen/src/Core/Product.h:191:5: note: in expansion of macro ‘EIGEN_DENSE_PUBliC_INTERFACE’ EIGEN_DENSE_PUBliC_INTERFACE(Derived) ^/usr/include/eigen3/Eigen/src/Core/Product.h: In instantiation of ‘class Eigen::Product<Eigen::Matrix<float,0>’:/home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:52:65: required from here/usr/include/eigen3/Eigen/src/Core/util/Macros.h:790:15: error: no members matching ‘Eigen::Product<Eigen::Matrix<float,0>::Base {aka Eigen::internal::dense_product_base<Eigen::Matrix<float,3>}::derived’ in ‘Eigen::Product<Eigen::Matrix<float,0>::Base {aka class Eigen::internal::dense_product_base<Eigen::Matrix<float,3>}’ using Base::derived; ^/usr/include/eigen3/Eigen/src/Core/Product.h:122:5: note: in expansion of macro ‘EIGEN_GENERIC_PUBliC_INTERFACE’ EIGEN_GENERIC_PUBliC_INTERFACE(Product) ^/usr/include/eigen3/Eigen/src/Core/util/Macros.h:791:15: error: no members matching ‘Eigen::Product<Eigen::Matrix<float,3>}::const_cast_derived’ in ‘Eigen::Product<Eigen::Matrix<float,3>}’ using Base::const_cast_derived; ^/usr/include/eigen3/Eigen/src/Core/Product.h:122:5: note: in expansion of macro ‘EIGEN_GENERIC_PUBliC_INTERFACE’ EIGEN_GENERIC_PUBliC_INTERFACE(Product) ^/home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp: In function ‘int main(int,char**)’:/home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:52:63: error: conversion from ‘const Eigen::Product<Eigen::Matrix<float,0>’ to non-scalar type ‘Eigen::Matrix<double,1>’ requested Eigen::Matrix<double,1> result_wrong_type = matrix_23 * v_3d; ^CMakefiles/eigenMatrix.dir/build.make:62: recipe for target ‘CMakefiles/eigenMatrix.dir/eigenMatrix.cpp.o‘ Failedmake[2]: *** [CMakefiles/eigenMatrix.dir/eigenMatrix.cpp.o] Error 1CMakefiles/Makefile2:67: recipe for target ‘CMakefiles/eigenMatrix.dir/all‘ Failedmake[1]: *** [CMakefiles/eigenMatrix.dir/all] Error 2Makefile:83: recipe for target ‘all‘ Failedmake: *** [all] Error 2*** Failure: Exit code 2 ***
问题分析:
在Eigen中不能混合两种不同类型的矩阵,Eigen不会执行自动类型转换,需要手动进行显式转换。
编译如下代码即会得到上述错误,
Eigen::Matrix<float,3> matrix_23;Eigen::Vector3d v_3d;matrix_23 << 1,4,5,6;v_3d << 1,3;Eigen::Matrix<double,1> result_ = matrix_23 * v_3d;
更正代码如下,
Eigen::Matrix<float,1> result_ = matrix_23.cast<double>() * v_3d; // 显式类型转换
2. 矩阵维度报错
/home/wy/workdir/slambook/ch3/useEigen/build> make -j2Scanning dependencIEs of target eigenMatrix[ 50%] Building CXX object CMakefiles/eigenMatrix.dir/eigenMatrix.cpp.oIn file included from /usr/include/eigen3/Eigen/Core:297:0,from /home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:5:/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h: In instantiation of ‘voID Eigen::internal::call_assignment_no_alias(Dst&,const Src&,const Func&) [with Dst = Eigen::Matrix<double,3>; Src = Eigen::Product<Eigen::CwiseUnaryOp<Eigen::internal::scalar_cast_op<float,double>,const Eigen::Matrix<float,3> >,0>; Func = Eigen::internal::assign_op<double>]’:/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:700:41: required from ‘Derived& Eigen::PlainObjectBase<Derived>::_set_noalias(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Product<Eigen::CwiseUnaryOp<Eigen::internal::scalar_cast_op<float,0>; Derived = Eigen::Matrix<double,3>]’/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:510:19: required from ‘Eigen::PlainObjectBase<Derived>::PlainObjectBase(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Product<Eigen::CwiseUnaryOp<Eigen::internal::scalar_cast_op<float,3>]’/usr/include/eigen3/Eigen/src/Core/Matrix.h:379:29: required from ‘Eigen::Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols>::Matrix(const Eigen::EigenBase<OtherDerived>&) [with OtherDerived = Eigen::Product<Eigen::CwiseUnaryOp<Eigen::internal::scalar_cast_op<float,0>; _Scalar = double; int _Rows = 2; int _Cols = 3; int _Options = 0; int _MaxRows = 2; int _MaxCols = 3]’/home/wy/workdir/slambook/ch3/useEigen/eigenMatrix.cpp:62:86: required from here/usr/include/eigen3/Eigen/src/Core/util/StaticAssert.h:119:9: error: ‘YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES’ is not a member of ‘Eigen::internal::static_assertion<false>’ if (Eigen::internal::static_assertion<static_cast<bool>(CONDITION)>::MSG) {} ^/usr/include/eigen3/Eigen/src/Core/util/StaticAssert.h:184:3: note: in expansion of macro ‘EIGEN_STATIC_ASSERT’ EIGEN_STATIC_ASSERT( ^/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:744:3: note: in expansion of macro ‘EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE’ EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(ActualDstTypeCleaned,Src) ^CMakefiles/eigenMatrix.dir/build.make:62: recipe for target ‘CMakefiles/eigenMatrix.dir/eigenMatrix.cpp.o‘ Failedmake[2]: *** [CMakefiles/eigenMatrix.dir/eigenMatrix.cpp.o] Error 1CMakefiles/Makefile2:67: recipe for target ‘CMakefiles/eigenMatrix.dir/all‘ Failedmake[1]: *** [CMakefiles/eigenMatrix.dir/all] Error 2Makefile:83: recipe for target ‘all‘ Failedmake: *** [all] Error 2*** Failure: Exit code 2 ***
问题分析:
当矩阵运算的行和列不匹配时,即会出现上述报错,代码如下,
Eigen::Matrix<float,2> result_ = matrix_23.cast<double>() * v_3d;
解决方案
Eigen::Matrix<double,1> result_ = matrix_23.cast<double>() * v_3d;
3. 数据类型报错
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h: In instantiation of ‘voID Eigen::internal::call_assignment_no_alias(Dst&,const Func&) [with Dst = Eigen::Matrix<float,4>; Src = Eigen::Matrix<double,4>; Func = Eigen::internal::assign_op<float>]’:/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:700:41: required from ‘Derived& Eigen::PlainObjectBase<Derived>::_set_noalias(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double,4>; Derived = Eigen::Matrix<float,4>]’/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:510:19: required from ‘Eigen::PlainObjectBase<Derived>::PlainObjectBase(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double,4>]’/usr/include/eigen3/Eigen/src/Core/Matrix.h:379:29: required from ‘Eigen::Matrix<_Scalar,_MaxCols>::Matrix(const Eigen::EigenBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double,4>; _Scalar = float; int _Rows = 4; int _Cols = 4; int _Options = 0; int _MaxRows = 4; int _MaxCols = 4]’/home/gordon/ros_ws/src/ndtMap/src/ndtmap_2frame.cpp:162:44: required from here/usr/include/eigen3/Eigen/src/Core/util/StaticAssert.h:32:40: error: static assertion Failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPliCITLY #define EIGEN_STATIC_ASSERT(X,MSG) static_assert(X,#MSG); ^/usr/include/eigen3/Eigen/src/Core/util/XprHelper.h:707:3: note: in expansion of macro ‘EIGEN_STATIC_ASSERT’ EIGEN_STATIC_ASSERT((internal::functor_is_product_like<BInop>::ret ^/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:745:3: note: in expansion of macro ‘EIGEN_CHECK_BINARY_COMPATIBIliY’ EIGEN_CHECK_BINARY_COMPATIBIliY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scal
问题分析
初步猜想是数据类型错误,然而错误藏得比较深,一直没有排查出来。最后终于发现原因如下,
程序中创建了一个 pcl::normaldistributionstransform 对象NDT,该对象的成员函数需要接收一个4x4的矩阵变量。
于是乎,随手就创建了一个 Eigen::Matrix4d 类型的变量。
通过检查定义 pcl::normaldistributionstransform 类的头文件,发现其成员函数默认接收的4x4矩阵变量居然是float!
解决方案:
更改矩阵变量的数据类型,如下所示,
Eigen::Matrix4f init_guess;init_guess = Eigen::Matrix4f::IDentity();
总结 以上是内存溢出为你收集整理的使用Eigen遇到恶心报错全部内容,希望文章能够帮你解决使用Eigen遇到恶心报错所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)