stl map for Eigen matrix

How to use stl map for Eigen::MatrixXd ? When i try to directly use it as
1
2
std::map<Eigen::MatrixXd,bool> matrix_map;
matrix_map[matrix] = true;

Its not working. Error is comming like:
1
2
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:834:3: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
   EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar);

I also tried to use unordered map but it is also not working.
Last edited on
What does 'not working' mean? Show us the compiler error next time...
<edit: one has since been added>

It's probably because a map is ordered but an Eigen library matrix does not define a sensible ordering for saying one matrix is "less than" another matrix.

Maybe try an unordered_map? http://www.cplusplus.com/reference/unordered_map/unordered_map/

Or you'd have use your own Compare class as the third template parameter to std::map,
http://www.cplusplus.com/reference/map/map/
Last edited on
This would seem to be the crucial part of the message:

YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY

Never having used Eigen, I wouldn't know what that means, but it gives you something specific to search for.
Registered users can post here. Sign in or register to post.