【问题标题】:Eigen: multiply a float matrix by a bool vector特征:将浮点矩阵乘以布尔向量
【发布时间】:2016-07-13 06:04:29
【问题描述】:

我需要在Eigen 中执行A*v,其中v 是大小为p 的向量,t 位于随机位置,p-t 为零,有关更多详细信息,请查看this 问题。

我的第一个问题是:Eigen 有什么办法吗?如果你知道怎么做,请回答this问题。

我的第二个问题是:在第一个链接问题中,我通过std::vector<bool>找到了一种节省时间和内存的方法,然后通过Eigen::Map使用它会很容易。

问题是我尝试执行以下操作(仅用于测试目的):

Eigen::Matrix<bool,2,1> v;
Eigen::Matrix<float,2,2> A;
v<<1,0;
A<<1,2,3,4;
A*v;

但是我得到一个编译错误(在问题的末尾找到它)。我该怎么做?一个简单的解决方法可能是声明 Eigen::Matrix&lt;float,2,1&gt; v; 但这可能真的是内存效率低下(特别是考虑到 v 可能很大)。

/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h: In instantiation of ‘struct Eigen::internal::traits<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’:
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:41:34:   required from ‘class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:48:34:   required from ‘class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:114:7:   required from ‘class Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>’
../Math.hpp:83:7:   required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58:   required from here
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:43:112: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
   typedef typename scalar_product_traits<typename _LhsNested::Scalar, typename _RhsNested::Scalar>::ReturnType Scalar;
                                                                                                                ^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:69:51: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
                           || ( (ColsAtCompileTime % packet_traits<Scalar>::size) == 0
                                                   ^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:76:51: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
                           || ( (RowsAtCompileTime % packet_traits<Scalar>::size) == 0
                                                   ^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:94:63: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
                     : InnerSize * (NumTraits<Scalar>::MulCost + LhsCoeffReadCost + RhsCoeffReadCost)
                                                               ^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:95:41: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
                       + (InnerSize - 1) * NumTraits<Scalar>::AddCost,
                                         ^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:107:41: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
                           && (InnerSize % packet_traits<Scalar>::size == 0)
                                         ^
In file included from /usr/local/include/eigen3/Eigen/Core:278:0,
                 from ../Math.hpp:13,
                 from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h: In instantiation of ‘class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’:
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:48:34:   required from ‘class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:114:7:   required from ‘class Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>’
../Math.hpp:83:7:   required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58:   required from here
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:67:25: error: using-declaration for non-member at class scope
     using Base::operator*;
                         ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:68:17: error: using-declaration for non-member at class scope
     using Base::derived;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:69:17: error: using-declaration for non-member at class scope
     using Base::const_cast_derived;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:70:17: error: using-declaration for non-member at class scope
     using Base::rows;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:71:17: error: using-declaration for non-member at class scope
     using Base::cols;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:72:17: error: using-declaration for non-member at class scope
     using Base::size;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:73:17: error: using-declaration for non-member at class scope
     using Base::rowIndexByOuterInner;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:74:17: error: using-declaration for non-member at class scope
     using Base::colIndexByOuterInner;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:75:17: error: using-declaration for non-member at class scope
     using Base::coeff;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:76:17: error: using-declaration for non-member at class scope
     using Base::coeffByOuterInner;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:77:17: error: using-declaration for non-member at class scope
     using Base::packet;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:78:17: error: using-declaration for non-member at class scope
     using Base::packetByOuterInner;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:79:17: error: using-declaration for non-member at class scope
     using Base::writePacket;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:80:17: error: using-declaration for non-member at class scope
     using Base::writePacketByOuterInner;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:81:17: error: using-declaration for non-member at class scope
     using Base::coeffRef;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:82:17: error: using-declaration for non-member at class scope
     using Base::coeffRefByOuterInner;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:83:17: error: using-declaration for non-member at class scope
     using Base::copyCoeff;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:84:17: error: using-declaration for non-member at class scope
     using Base::copyCoeffByOuterInner;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:85:17: error: using-declaration for non-member at class scope
     using Base::copyPacket;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:86:17: error: using-declaration for non-member at class scope
     using Base::copyPacketByOuterInner;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:87:26: error: using-declaration for non-member at class scope
     using Base::operator();
                          ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:88:26: error: using-declaration for non-member at class scope
     using Base::operator[];
                          ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:89:17: error: using-declaration for non-member at class scope
     using Base::x;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:90:17: error: using-declaration for non-member at class scope
     using Base::y;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:91:17: error: using-declaration for non-member at class scope
     using Base::z;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:92:17: error: using-declaration for non-member at class scope
     using Base::w;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:93:17: error: using-declaration for non-member at class scope
     using Base::stride;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:94:17: error: using-declaration for non-member at class scope
     using Base::innerStride;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:95:17: error: using-declaration for non-member at class scope
     using Base::outerStride;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:96:17: error: using-declaration for non-member at class scope
     using Base::rowStride;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:97:17: error: using-declaration for non-member at class scope
     using Base::colStride;
                 ^
In file included from /usr/local/include/eigen3/Eigen/Core:279:0,
                 from ../Math.hpp:13,
                 from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h: In instantiation of ‘class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’:
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:114:7:   required from ‘class Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>’
../Math.hpp:83:7:   required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58:   required from here
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:71:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::derived’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::derived;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:72:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::const_cast_derived’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::const_cast_derived;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:73:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::rows’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::rows;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:74:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::cols’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::cols;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:75:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::size’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::size;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:76:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::coeff’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::coeff;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:77:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::coeffRef’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::coeffRef;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:79:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::eval’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::eval;
                 ^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:82:25: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::operator*=’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::operator*=;
                         ^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:83:25: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::operator/=’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     using Base::operator/=;
                         ^
In file included from /usr/local/include/eigen3/Eigen/Core:20:0,
                 from ../Math.hpp:13,
                 from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h: In instantiation of ‘class Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>’:
../Math.hpp:83:7:   required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58:   required from here
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:121:5: error: no members matching ‘Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>::Base {aka Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::derived’ in ‘Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>::Base {aka class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     EIGEN_DENSE_PUBLIC_INTERFACE(CoeffBasedProduct)
     ^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:121:5: error: no members matching ‘Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>::Base {aka Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::const_cast_derived’ in ‘Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>::Base {aka class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
     EIGEN_DENSE_PUBLIC_INTERFACE(CoeffBasedProduct)
     ^
In file included from /usr/local/include/eigen3/Eigen/Core:254:0,
                 from ../Math.hpp:13,
                 from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h: In instantiation of ‘Eigen::CoeffBasedProduct<Lhs, Rhs, NestingFlags>::CoeffBasedProduct(const Lhs&, const Rhs&) [with Lhs = Eigen::Matrix<float, 2, 2>; Rhs = Eigen::Matrix<bool, 2, 1>; LhsNested = const Eigen::Matrix<float, 2, 2>&; RhsNested = const Eigen::Matrix<bool, 2, 1>&; int NestingFlags = 6]’:
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:598:91:   required from ‘const typename Eigen::ProductReturnType<Derived, OtherDerived>::Type Eigen::MatrixBase<Derived>::operator*(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::Matrix<bool, 2, 1>; Derived = Eigen::Matrix<float, 2, 2>; typename Eigen::ProductReturnType<Derived, OtherDerived>::Type = Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>]’
../Math.hpp:83:7:   required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58:   required from here
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:154:7: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
       EIGEN_STATIC_ASSERT((internal::scalar_product_traits<typename Lhs::RealScalar, typename Rhs::RealScalar>::Defined),
       ^
subdir.mk:30: recipe for target 'CloudCache.o' failed
make: *** [CloudCache.o] Error 1

【问题讨论】:

    标签: c++ vector bit eigen


    【解决方案1】:

    您需要转换为相关类型。 Eigen 不支持隐式类型转换,因此您必须编写:

    A*v.cast<float>();
    

    在错误输出中有一个提示:

    /usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:154:7: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
    

    【讨论】:

    • 哎呀,我错了,但这个cast 操作将创建一个具有相同元素但类型为float 的临时对象?这听起来非常低效!
    • 是的,你错了。这只是一个明确的演员表。见here。来自here:(通常,转换发生在即时)
    • 如果false的数量很大,最好使用手动for循环做if(v(i) res+=A.col(i)
    猜你喜欢
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    相关资源
    最近更新 更多