[eigen] How to return an Eigen matrix |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] How to return an Eigen matrix
- From: Hung Dang <hungptit@xxxxxxxxx>
- Date: Fri, 30 Sep 2011 23:24:44 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:reply-to:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=/9aVNbZHBi8Dqe4gZ8boZ/xJRYPaeOAAWKSrxks4jGg=; b=YkPQRzacWy7MN1OeqDYlo4G/HqJFdl0R4WOBNmvw9LXZHXzff2cTSZPQUv5peP6KVi lPS2dUz1NzCU8IaN7l6JvmPEY7lk6OmoYwGXhpiZcHf8AaYU8UomLozEkk6Z/k84j0o2 WncXoGyyA+UNQy9ZhvB9X+HMYp2WuYlSIQ3ag=
Hi all,
I am new to Eigen so I am sorry for my naive question. I am trying to
write a function which will return an Eigen template matrix (see code
below). In my code func2 works fine, however, func1 does not. The g++
compiler complain that there is no matching function for call to func1.
What should I do to return an Eigen matrix?
Thanks in advance
Hung
My test code:
#include <iostream>
#include <fstream>
#include <string>
#include "Eigen/Dense"
using std::string;
using std::cout;
using std::endl;
using namespace Eigen;
template <class T>
inline Matrix<T, Dynamic, Dynamic> & func1(){
// Do something then return a matrix
Matrix<T, 3, 5> A;
return A;
}
inline MatrixXd func2(){
// Do something then return a matrix
MatrixXd A(3,5);
return A;
}
int main (int nargc, char *argv[]){
string dataFileName = "dat.txt";
Matrix<double, Dynamic, Dynamic> A = func1();
cout << "Matrix A:" << endl << A << endl;
// MatrixXd B = func2();
// cout << "Matrix B:" << endl << B << endl;
return 0;
}