Reply to topic

How to copy Eigen Matrix to a POD double array?

pktrain
Registered Member
Posts
2
Karma
0
OS
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...
User avatar ggael
Moderator
Posts
2194
Karma
15
OS
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
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! :)

 
Reply to topic

Bookmarks



Who is online

Registered users: alake, Alexa [Bot], Baidu [Spider], Bing [Bot], Blingy, Deevad, edmael, einar, Exabot [Bot], garthecho, Google [Bot], google01103, haroldtejada, jfredrickson, koriun, lazyit, legnaVI, Majestic-12 [Bot], newtonnickel, parzt, pedrorodriguez, Tuukka, W3C [Validator], Yahoo [Bot]