Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to initialize a const Eigen matrix?

I have the following class:

class Foo
{
public:
   Foo(double a, double b, double c, double d, double e)
   // This does not work:
   // : m_bar(a, b, c, d, e)
   {
      m_bar << a, b, c, d, e;
   }

private:
   // How can I make this const?
   Eigen::Matrix<double, 5, 1, Eigen::DontAlign> m_bar;
};

How Can I make m_bar const and initialize it width a to f as values in the constructor? C++11 would also be fine, but initializer lists don't seem to be supported by eigen...

like image 342
Jan Rüegg Avatar asked Aug 06 '14 11:08

Jan Rüegg


1 Answers

Simplest solution I see since the class also defines a copy constructor:

class Foo
{
public:
   Foo(double a, double b, double c, double d, double e) :
       m_bar( (Eigen::Matrix<double, 5, 1, Eigen::DontAlign>() << a, b, c, d, e).finished() )
   {
   }

private:
   const Eigen::Matrix<double, 5, 1, Eigen::DontAlign> m_bar;
};
like image 52
Marco A. Avatar answered Oct 08 '22 18:10

Marco A.