c++ - 将 Eigen::PermutationMatrix.indices() 转换为数组/vector

标签 c++ eigen3

我想将 Eigen::PermutationMatrix 的公共(public)方法 indices() 的返回值存储为一个数组(例如稍后提取一些感兴趣的值).

我应该如何将其转换为数组(Eigen::Array 或 C++ STL vector )?

这是我尝试过的:

Eigen::FullPivLU<Eigen::MatrixXf> lu(LU_A); //LU_A is of type  Eigen::MatrixXf
    Eigen::ArrayXXf lins;
    lins = lu.permutationP().indices().cast<int>().array(); //trows an error

错误:

    In file included from /home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/Eigen/Core:347:0,
                     from /home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/Eigen/Dense:1,
                     from Matrice.hpp:5,
                     from Matrice.cpp:1:
    /home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/Eigen/src/Core/AssignEvaluator.h: In instantiation of ‘void Eigen::internal::call_assignment_no_alias(Dst&, const Src&, const Func&) [with Dst = Eigen::Array<float, -1, -1>; Src = Eigen::ArrayWrapper<const Eigen::Matrix<int, -1, 1> >; Func = Eigen::internal::assign_op<float, int>]’:
    /home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/Eigen/src/Core/AssignEvaluator.h:804:27:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&, const Func&, typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type) [with Dst = Eigen::Array<float, -1, -1>; Src = Eigen::ArrayWrapper<const Eigen::Matrix<int, -1, 1> >; Func = Eigen::internal::assign_op<float, int>; typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing<Src>::value), void*>::type = void*]’
    /home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/Eigen/src/Core/AssignEvaluator.h:782:18:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&) [with Dst = Eigen::Array<float, -1, -1>; Src = Eigen::ArrayWrapper<const Eigen::Matrix<int, -1, 1> >]’
    /home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/Eigen/src/Core/PlainObjectBase.h:710:32:   required from ‘Derived& Eigen::PlainObjectBase<Derived>::_set(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::ArrayWrapper<const Eigen::Matrix<int, -1, 1> >; Derived = Eigen::Array<float, -1, -1>]’
    /home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/Eigen/src/Core/Array.h:109:24:   required from ‘Eigen::Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& Eigen::Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::operator=(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::ArrayWrapper<const Eigen::Matrix<int, -1, 1> >; _Scalar = float; int _Rows = -1; int _Cols = -1; int _Options = 0; int _MaxRows = -1; int _MaxCols = -1]’
    Matrice.cpp:380:58:   required from here
    /home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/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);
/home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/Eigen/src/Core/util/XprHelper.h:816:3: note: in expansion of macro ‘EIGEN_STATIC_ASSERT’
   EIGEN_STATIC_ASSERT((Eigen::internal::has_ReturnType<ScalarBinaryOpTraits<LHS, RHS,BINOP> >::value), \
   ^~~~~~~~~~~~~~~~~~~
/home/ldfzor/Documents/CodeBlocks_Projects/POO_Matrice_Eigen/eigen3_3_3/Eigen/src/Core/AssignEvaluator.h:834:3: note: in expansion of macro ‘EIGEN_CHECK_BINARY_COMPATIBILIY’
   EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar);

最佳答案

您正在尝试将 int 数组存储在 float 数组中。只写:

Eigen::ArrayXi lins = lu.permutationP().indices().cast<int>().array();

关于c++ - 将 Eigen::PermutationMatrix.indices() 转换为数组/vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42861022/

相关文章:

c++ - wxWidgets - 将所有文件夹写入列表框

c++ - 使用 Eigen 3 线性系统求解器的错误结果

c++ - 如何在 Eigen 中将矩阵与另一个矩阵按行相乘?

c++ - 特征表达式模板比指数的手动循环慢

c++ - eigen 中的 vector 加和点不会通过 mkl 加速

c++ - 如何在使用继承和虚拟运算符()的系统中使用 odeint 求解器

c++ - 推导类的模板参数

c++ - 使用 Boost 库计算各种中心性

C++/TCP数据传输垃圾

c++ - 特征映射类 : mapping C-array to VectorXd pointer in an efficient way