Re: [eigen] Using Eigen::Map to use eigen operations on my data

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


   float data[4] = { 1, 2, 3, 4 };
   MatrixXf mat2x2 = MatrixXf(Map<MatrixXf>(data, 2, 2));
Here you are constructing a new MatrixXf, mat2x2, from the map.

after this line, mat2x2 is just another matrix and doesn't even
remember that it was copied from the Map.

I realised that that must be the problem, but the documentation implied (to me) that it ought to work:

Map
Any memory buffer can be mapped as an Eigen expression:
....
int data[4] = 1, 2, 3, 4;
MatrixXi mat2x2 = Map<MatrixXi>(data,2,2);

Whereas this is in fact performing a copy.

If you want to initialize an array as the identity matrix, do:
Map<MatrixXf>(data, 2, 2).setIdentity();

No, that's just the example. I'm actually working on a swig interface from numpy, based on the one in rikrd-loudia

if you want to write your own function, make it like this:
template<typename Derived>
void identity(MatrixBase<Derived> *x)

Now I'm confused. I want a MatrixXf that shares memory with data[] that I can pass to a pre-existing library. How does this help?

					R




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/