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

Passing Eigen::MatrixXf as a function argument

Tags: None
(comma "," separated)
mehrdadh
Registered Member
Posts
26
Karma
0
I would like to know how to do that and if it works with Eigen ?

for example:

void my_func(Eigen::MatrixXf &myMat)
{
//... use myMat ...
}


int main()
{
Eigen::MatrixXf mat(6,4);
my_func(mat);
}


or should I use pointers and how to do that ?
PS: I know I can pass the .data() and matrix size and then use Map to use the matrix, but I've seen some matrix functionality is not available like that.
I want to know if I can do something like above and basically how to do it ?
User avatar
bjacob
Registered Member
Posts
658
Karma
3
You can perfectly pass either pointers or references to Eigen objects, as you want. Eigen doesn't make any difference here. Also, pointers and references are the same thing, once the code is compiled. This is generally true in c++, not eigen specific. So your code snippet will work. Make sure to use /constant/ references wherever possible.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]