Question

I'm trying to have a class that contains array but have an interface to them through eigen.

class A {
public:
  array<double,3> xa;
  Map<Matrix<double,3,1>> x;
  A() : x(xa.data(),xa.size()) {}
};

this doesn't work :

A a;
a.xa[0] = 0.12;
cout << a.x ;

I assume the problem is because Map<> doesn't have a default constructor. http://eigen.tuxfamily.org/dox/TutorialMapClass.html#TutorialMapPlacementNew

Was it helpful?

Solution

The example that you provide does work for me (Eigen 3.0.1 and GCC 4.6.1)

#include <Eigen/Core>
#include <array>
#include <iostream>

using namespace std;
using namespace Eigen;

class A {
public:
  array<double,3> xa;
  Map<Matrix<double,3,1>> x;
  A() : x(xa.data(),xa.size()) {}
};

int main()
{
    A a;
    a.xa[0] = 0.12;
    cout << a.x ;    
}

when compiled with

g++ test.cpp -std=c++0x -o test -I/usr/include/eigen3

I get the following output when calling the resulting test executable:

[/tmp]% ./test        
0.12
2.07717e-317
0%    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top