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

Passing a matrix to a function

Tags: None
(comma "," separated)
inktomi
Registered Member
Posts
5
Karma
0

Passing a matrix to a function

Sun Jun 07, 2009 8:00 pm
Hi,

I'm using Eigen2 and I want a function to accept arbitrarily size matrices. But since the matrix size is specified as a template, I'm at a loss how to do this.

Any help is appreciated.
User avatar
bjacob
Registered Member
Posts
658
Karma
3

RE: Passing a matrix to a function

Sun Jun 07, 2009 8:47 pm
Example function taking any expression as argument:

Code: Select all
template
void foo(const MatrixBase& m)
{
   std::cout << "Here's your matrix expression:" << std::endl << m << std::endl;
}


If you want a function that accepts only plain matrices, just replace MatrixBase by Matrix and make it template in the 6 template parameters of Matrix...

Last edited by bjacob on Sun Jun 07, 2009 8:49 pm, edited 1 time in total.


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

RE: Passing a matrix to a function

Sun Jun 07, 2009 9:16 pm
Thanks for your reply.

I don't know the size of the matrix at compile time, so I presume I can't use that. And I'm only interested in plain Matrices.

Edit: Seems that using MatrixBase will solve the problem. But I don't think it's possible with Matrix.

Last edited by inktomi on Sun Jun 07, 2009 9:33 pm, edited 1 time in total.
inktomi
Registered Member
Posts
5
Karma
0

RE: Passing a matrix to a function

Sun Jun 07, 2009 10:14 pm
Nevermind, I noticed I have to use Dynamic


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]