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

How to wrap Eigen

Tags: None
(comma "," separated)
daniel_i_l
Registered Member
Posts
1
Karma
0
OS

How to wrap Eigen

Tue Apr 06, 2010 8:20 pm
I want to use Eigen in a project of mine but not in a way that will make it hard for me to try a different library in the future. In other words, I dont want to use Eigen explicitly in my code - I want to hide it behind a genaric interface and only implement the interface with Eigen.
What's a good way to do this?
If I make a class called MyVector that stores an Eigen Vector3d for example, and implement the operators like this:
Code: Select all
class MyVector{
private:
    Eigen::Vector3d vec;
public:
    MyVector(Eigen::Vector3d v) : vec(v) {}
    const MyVector operator+(const MyVector& rhs) const
    {
        return MyVector(this->vec + rhs.vec);
    }
};

Then will I loose the optimization that Eigen provides? It seems like the custom + operator in MyVector will negate the advantages of Eigen's expression templates by returning a new MyVector for every call.
Is this right? If so than how can I create an efficient wrapper?
Thanks.
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: How to wrap Eigen

Wed Apr 07, 2010 3:53 am
daniel_i_l wrote:I want to use Eigen in a project of mine but not in a way that will make it hard for me to try a different library in the future. In other words, I dont want to use Eigen explicitly in my code - I want to hide it behind a genaric interface and only implement the interface with Eigen.
What's a good way to do this?
If I make a class called MyVector that stores an Eigen Vector3d for example, and implement the operators like this:
Code: Select all
class MyVector{
private:
    Eigen::Vector3d vec;
public:
    MyVector(Eigen::Vector3d v) : vec(v) {}
    const MyVector operator+(const MyVector& rhs) const
    {
        return MyVector(this->vec + rhs.vec);
    }
};

Then will I loose the optimization that Eigen provides? It seems like the custom + operator in MyVector will negate the advantages of Eigen's expression templates by returning a new MyVector for every call.
Is this right?


Right, you lose the expression templates.

You keep other optimizations though, such as SIMD and cache friendliness.

If so than how can I create an efficient wrapper?


The best approach is probably to either use the plugins system to add method to Eigen classes, or if that isn't enough, inherit from Eigen classes. Both are described here: http://eigen.tuxfamily.org/dox-devel/Cu ... Eigen.html


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]