Compile time error from Eigen: THE_EVAL_EVALTO_FUNCTION_SHOULD_NEVER_BE_CALLED_FOR_DENSE_OBJECTS

StackOverflow https://stackoverflow.com/questions/23544049

  •  18-07-2023
  •  | 
  •  

Question

I've been struggling to write a utility function to convert between an Eigen Matrix and an STL vector. I've condensed my code down to:

#include <Eigen/Dense>
#include <vector>

#include <iostream>

template <int Flags=Eigen::RowMajor, typename Derived>
std::vector<typename Derived::Scalar>
eigenToStdVector(const Eigen::EigenBase<Derived>& b)
{
  typedef typename Derived::Scalar Scalar;
  std::vector<Scalar> out(b.size());
  Eigen::Map<Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Flags> >
    (out.data(), b.rows(), b.cols()) = b/*.derived()*/;
  return out;
}

int
main ()
{
  Eigen::MatrixXf v(2,4);
  v << 1,2,3,4,5,6,7,8;
  std::cout << v << std::endl;

  for (auto i : eigenToStdVector(v))
    std::cout << i << ' ';
  std::cout << std::endl;

  for (auto i : eigenToStdVector<Eigen::ColMajor>(v.transpose()))
    std::cout << i << ' ';
  std::cout << std::endl;

  return 0;
}

and I don't understand why including the (commented) .derived() line causes the compile to succeed. If anyone could comment as to why including this is necessary I'd be most grateful!

I'm using GCC 4.8 and Eigen 3.2.1.

Was it helpful?

Solution

You should use DenseBase instead of the too general EigenBase base classe. This discrepancy will probably go away in 3.3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top