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

Calling Eigen functions within template class

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

I attempted to call eigen functions from member functions within a template class. Many functions work, however the triangularView() function does not compile. These functions all work when I call them from a plain function.

The error I recieve is:
expected primary-expression before ‘)’ token
For example:
Code: Select all
#include <iostream>
#include "Eigen/Eigen"
#include "Eigen/Core"

using namespace std;
using namespace Eigen;

template<int N1,int N2>
class test
{
    public:
    Matrix<double,N1,N2> a;
    void test1()
    {
        //Bunch of operations go here.
        //For example
        a=a.Random();
        a=(a*2).eval();
        cout<<a<<"\n\n";
        cout<<"compile time size:"<<a.SizeAtCompileTime<<"\n\n ";
    }
    void test2()
    {
        //Some other bunch of operations go here.
        a.triangularView<StrictlyLower>().setZero(); //This line produces compile error.
        cout<<"Zeroing lower triangular part:\n"<<a<<"\n\n";
    }
};

int main()
{
    test<5,5> t1;
    t1.test1();
    t1.test2();

    test<4,4> t2;
    t2.test1();
    t2.test2();

    //Repeat same functions in the class directly.

    Matrix<double,5,5> b;
    b=b.Random();
    b=(b*2).eval();
    cout<<b<<"\n\n";
    b.triangularView<StrictlyLower>().setZero();
    cout<<b<<"\n\n";

    return 0;
}


In the above code, the triangularView function compiles properly when it is outside the template class but produces a compile error within the template class' member function.

Is it possible to do something like this?

The reason I am looking for something like this is that I am implementing an estimator for systems of different sizes (known at compile time and small - 1 to 10 max), and I was hoping I could give the system size as a template parameter and reduce rewriting the code and / avoid using defines.

Edit: I should mention, I am using the trunk version on Ubuntu 10.10, 64 bit. and gcc 4.4.5

Regards
Sri
jitseniesen
Registered Member
Posts
204
Karma
2
This is caused by a nuance in the C++ language. You need to add the template keyword. So replace the offending line by
Code: Select all
a.template triangularView<StrictlyLower>().setZero();
sri
Registered Member
Posts
5
Karma
0
That fixed the problem.

Thank you!

Regards
Sri


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft