来自特征的系数方式比较的数值类型

时间:2014-07-09 16:14:42

标签: c++ casting eigen

我想通过比较数组和标量来创建数组。这个数组应该是什么类型的?

这是我的代码:

Eigen::ArrayXXd eig_arr = Eigen::ArrayXXd::Random(n_rows,n_components);
//std::cout << (eig_arr >30 )<< std::endl; //the result here is correct
Eigen::ArrayXXd mask = Eigen::ArrayXXd::Zero(eig_arr.rows(), eig_arr.cols());
mask = (eig_arr >30 ); 

我得到YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY 我已经查找了cast方法,但我仍然不知道哪种类型转换为。

这是我得到的完整错误:

    e:\dev\eigen\eigen\src/Core/Assign.h(493): error C2338: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
          e:\dev\eigen\eigen\src/Core/PlainObjectBase.h(414) : see reference to function template instantiation 'Derived &Eigen::DenseBase<Derived>::lazyAssign<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const Eigen::DenseBase<Eigen::CwiseUnaryOp<UnaryOp,XprType>> &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-
          ]
          e:\dev\eigen\eigen\src/Core/PlainObjectBase.h(414) : see reference to function template instantiation 'Derived &Eigen::DenseBase<Derived>::lazyAssign<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const Eigen::DenseBase<Eigen::CwiseUnaryOp<UnaryOp,XprType>> &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-
          ]
          e:\dev\eigen\eigen\src/Core/Assign.h(520) : see reference to function template instantiation 'Derived &Eigen::PlainObjectBase<Derived>::lazyAssign<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const Eigen::DenseBase<Eigen::CwiseUnaryOp<UnaryOp,XprType>> &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-
          ]
          e:\dev\eigen\eigen\src/Core/Assign.h(520) : see reference to function template instantiation 'Derived &Eigen::PlainObjectBase<Derived>::lazyAssign<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const Eigen::DenseBase<Eigen::CwiseUnaryOp<UnaryOp,XprType>> &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-
          ]
          e:\dev\eigen\eigen\src/Core/Assign.h(520) : while compiling class template member function 'Eigen::Array<_Scalar,_Rows,_Cols> &Eigen::internal::assign_selector<Derived,OtherDerived,EvalBeforeAssigning>::run(Derived &,const OtherDerived &)'
          with
          [
              _Scalar=double,
              _Rows=-1,
              _Cols=-1,
              Derived=Eigen::Array<double,-1,-,
              OtherDerived=Eigen::CwiseUnaryOp<std::binder2nd<std::greater<double>>,const Eigen::Array<double,-1,->,
              EvalBeforeAssigning=false
          ]
          e:\dev\eigen\eigen\src/Core/PlainObjectBase.h(621) : see reference to function template instantiation 'Eigen::Array<_Scalar,_Rows,_Cols> &Eigen::internal::assign_selector<Derived,OtherDerived,EvalBeforeAssigning>::run(Derived &,const OtherDerived &)' being compiled
          with
          [
              _Scalar=double,
              _Rows=-1,
              _Cols=-1,
              Derived=Eigen::Array<double,-1,-,
              OtherDerived=Eigen::CwiseUnaryOp<std::binder2nd<std::greater<double>>,const Eigen::Array<double,-1,->,
              EvalBeforeAssigning=false
          ]
          e:\dev\eigen\eigen\src/Core/PlainObjectBase.h(621) : see reference to class template instantiation 'Eigen::internal::assign_selector<Derived,OtherDerived,EvalBeforeAssigning>' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              OtherDerived=Eigen::CwiseUnaryOp<std::binder2nd<std::greater<double>>,const Eigen::Array<double,-1,->,
              EvalBeforeAssigning=false
          ]
          e:\dev\eigen\eigen\src/Core/PlainObjectBase.h(606) : see reference to function template instantiation 'Derived &Eigen::PlainObjectBase<Derived>::_set_noalias<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const Eigen::DenseBase<Eigen::CwiseUnaryOp<UnaryOp,XprType>> &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-
          ]
          e:\dev\eigen\eigen\src/Core/PlainObjectBase.h(606) : see reference to function template instantiation 'Derived &Eigen::PlainObjectBase<Derived>::_set_noalias<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const Eigen::DenseBase<Eigen::CwiseUnaryOp<UnaryOp,XprType>> &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-
          ]
          e:\dev\eigen\eigen\src/Core/PlainObjectBase.h(598) : see reference to function template instantiation 'void Eigen::PlainObjectBase<Derived>::_set_selector<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const OtherDerived &,const Eigen::internal::false_type &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-,
              OtherDerived=Eigen::CwiseUnaryOp<std::binder2nd<std::greater<double>>,const Eigen::Array<double,-1,->
          ]
          e:\dev\eigen\eigen\src/Core/PlainObjectBase.h(598) : see reference to function template instantiation 'void Eigen::PlainObjectBase<Derived>::_set_selector<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const OtherDerived &,const Eigen::internal::false_type &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-,
              OtherDerived=Eigen::CwiseUnaryOp<std::binder2nd<std::greater<double>>,const Eigen::Array<double,-1,->
          ]
          e:\dev\eigen\eigen\src/Core/Array.h(89) : see reference to function template instantiation 'Derived &Eigen::PlainObjectBase<Derived>::_set<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const Eigen::DenseBase<Eigen::CwiseUnaryOp<UnaryOp,XprType>> &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-
          ]
          e:\dev\eigen\eigen\src/Core/Array.h(89) : see reference to function template instantiation 'Derived &Eigen::PlainObjectBase<Derived>::_set<Eigen::CwiseUnaryOp<UnaryOp,XprType>>(const Eigen::DenseBase<Eigen::CwiseUnaryOp<UnaryOp,XprType>> &)' being compiled
          with
          [
              Derived=Eigen::Array<double,-1,-,
              UnaryOp=std::binder2nd<std::greater<double>>,
              XprType=const Eigen::Array<double,-1,-
          ]
          ..\test.cxx(76) : see reference to function template instantiation 'Eigen::Array<_Scalar,_Rows,_Cols> &Eigen::Array<_Scalar,_Rows,_Cols>::operator =<Derived>(const Eigen::ArrayBase<Derived> &)' being compiled
          with
          [
              _Scalar=double,
              _Rows=-1,
              _Cols=-1,
              Derived=Eigen::CwiseUnaryOp<std::binder2nd<std::greater<double>>,const Eigen::Array<double,-1,->
          ]
          ..\test.cxx(76) : see reference to function template instantiation 'Eigen::Array<_Scalar,_Rows,_Cols> &Eigen::Array<_Scalar,_Rows,_Cols>::operator =<Derived>(const Eigen::ArrayBase<Derived> &)' being compiled
          with
          [
              _Scalar=double,
              _Rows=-1,
              _Cols=-1,
              Derived=Eigen::CwiseUnaryOp<std::binder2nd<std::greater<double>>,const Eigen::Array<double,-1,->
          ]

1 个答案:

答案 0 :(得分:1)

eig_arr > 30返回一个bools的表达式,所以如果你想要双打,那么你必须明确地将bool转换成双打,如下所示:

mask = (eig_arr >30 ).cast<double>()