## How to copy Eigen Matrix to a POD double array?

pktrain
Registered Member
Posts
2
Karma
0
OS

### How to copy Eigen Matrix to a POD double array?

Fri Jun 10, 2011 10:32 am
Hello,

Per the first example found at http://eigen.tuxfamily.org/dox/classEigen_1_1Map.html, I have no problem using Map to map a double array to an Eigen Matrix. But I can find nowhere an example of mapping that Eigen Matrix back to the plain old double array.

Can someone please provide an example of the best way to do this without using loops?

Many thanks...
ggael
Moderator
Posts
2144
Karma
15
OS

### Re: How to copy Eigen Matrix to a POD double array?

Fri Jun 10, 2011 10:46 am
the same:

MatrixXf m(rows,cols);
...
Map<MatrixXf>(ptr,rows,cols) = m;

Note that you can also name the mapped object and directly use it in expressions instead of copying it:

MatrixXf A, B;
Map<MatrixXf> m(ptr,rows,cols);
...
B += 0.5 * m * B;
b.diagonal() += 1;
...
pktrain
Registered Member
Posts
2
Karma
0
OS

### Re: How to copy Eigen Matrix to a POD double array?

Fri Jun 10, 2011 10:57 am
ggael wrote:the same:

MatrixXf m(rows,cols);
...
Map<MatrixXf>(ptr,rows,cols) = m;

Note that you can also name the mapped object and directly use it in expressions instead of copying it:

MatrixXf A, B;
Map<MatrixXf> m(ptr,rows,cols);
...
B += 0.5 * m * B;
b.diagonal() += 1;
...

Works perfectly...exactly what I was looking for!

## Who is online

Registered users: alake, Baidu [Spider], Bing [Bot], Charblaze, Exabot [Bot], ghevan, Google [Bot], google01103, jensreuterberg, La Ninje, Leroux, lusque, maarten, Majestic-12 [Bot], pedrorodriguez, rzeta, sammuirhead, scummos, Sentynel, sir_herrbatka, TheraHedwig, trebor, Yahoo [Bot]