This forum has been archived. All content is frozen. Please use KDE Discuss instead.

accessing the data buffer of a Matrix object

Tags: None
(comma "," separated)
martinakos
Registered Member
Posts
53
Karma
0
OS
Hi again!

I wonder if there is any form of accessing the data buffer of a Matrix object?
I'm looking for something like double *buffer = eigenMatrix.Data();

I need to interface Eigen Matrixes with a legacy Matrix class,
there is a lot of code already written for this legacy class, so changing it to Eigen matrix is not an option atm.

So far I'm using a Map in this way:

double *buffer = legacyMatrix.Data();
Map<MatrixXd> mapMatrix(buffer, rows, cols);

....
operate my mapMatrix
....

....
pass my legacyMatrix to another function
....


However, now I'm using some legacy debug functions to compare numeric accuracy with Matlab counterparts,
and I'm having to rename and replicate the structure above lots of times, which is getting annoying. I tried to assign a Eigen::Matrix
to a generic Eigen::Map that is already mapped to the legacyMatrix, it builds but gives a runtime exception.

As a last resource I'll copy the elements of the Eigen::Matrix manually, which for debuging it's not a problem,
but it would be nice it I could do the
double *buffer = eigenMatrix.Data();


Thanks,
Martin.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
martinakos wrote:Hi again!

I wonder if there is any form of accessing the data buffer of a Matrix object?
I'm looking for something like double *buffer = eigenMatrix.Data();


You got it almost right, it's .data() (notice lowercase d)


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
martinakos
Registered Member
Posts
53
Karma
0
OS
Hi bjacob,

Thanks for your reply. For some reason I couldn't access the forum all yesterday. I hope I wasn't banned for asking a too obvious question :-)

I guess it's obvious it would be .data(), although I haven't been able to find that in the Eigen documentation, is that an undocumented method?

Cheers
Martin
martinakos
Registered Member
Posts
53
Karma
0
OS
Oh! now I see what happens.

The .data() method appears in the stable branch documentation but not in the development branch, and that's the one I was looking in.

Well thanks again.

Martin.
jitseniesen
Registered Member
Posts
204
Karma
2
In the development branch, the .data() method is in the DenseStorageBase class, documented at http://eigen.tuxfamily.org/dox-devel/classEigen_1_1DenseStorageBase.html . The Matrix class inherits the DenseStorageBase class. Unfortunately, the automatically generated documentation does not show this inheritance, so I cannot blame you for not finding this. I guess that Eigen's template-heavy inheritance tree is too complicated for doxygen. You can read a bit about Eigen's class hierarchy at http://eigen.tuxfamily.org/dox-devel/TopicClassHierarchy.html .


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]