Registered Member
|
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... |
Moderator
|
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; ... |
Registered Member
|
Works perfectly...exactly what I was looking for! |
Registered Member
|
hello sorry for resurrecting old thread.
I'm trying tto do the exact thing described in the OP: copy Eigen Matrix to a POD double array. However I always get segmentation fault while doing this, apparently I'm not alone, as described here http://stackoverflow.com/questions/8443 ... to-c-array Here is part of my code:
Am I doing anything wrong here? Thanks in advance. |
Moderator
|
You need to allocate targetArray! Map<MatrixXd> is to map existing buffer.
If you don't want to copy the data but just need a plain pointer, then use double* ptr = mat.data(); |
Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]