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

Compatibility between Eigen 2 and 3

Tags: None
(comma "," separated)
Zmatt
Registered Member
Posts
27
Karma
0
OS

Compatibility between Eigen 2 and 3

Thu Aug 12, 2010 9:26 am
Hello,

I've developped my own wrapper for an old matrix library and it works fine. I'm now trying use Eigen 3 Beta to see if my code is faster. I download the beta version a couple of days after it was released just to test with openmp and I download it again this morning but my previous code doesn't work. Indeed I can't now do derived(i,j) to access to the element (i,j), I need to add .coeff or .coeffRef .Do I miss something or need I to change my code ? (I use #define EIGEN2_SUPPORT)

Thanks ;D
User avatar
bjacob
Registered Member
Posts
658
Karma
3
See this page to help you porting your code:
http://eigen.tuxfamily.org/dox-devel/Ei ... igen3.html

But foo.derived(i,j) never worked in eigen2 either, perhaps you meant foo.derived()(i,j). That would still work in the same way with Eigen3. And the .derived() is useless there, just do foo(i,j) where foo is the object in question.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
Zmatt
Registered Member
Posts
27
Karma
0
OS
I had seen the page and yes I made a mistake it was obviously derived()(i,j).

I've a strange error of compilation that I don't understand : (perhapes because the beta version is beta :) )
Code: Select all
1>c:\*\eigen3\eigen\src/Core/DenseCoeffsBase.h(99) : error C2248: 'Eigen::ProductBase<Derived,Lhs,Rhs>::coeff' : impossible d'accéder à private membre déclaré(e) dans la classe 'Eigen::ProductBase<Derived,Lhs,Rhs>'
1>        with
1>        [
1>            Derived=Eigen::GeneralProduct<Eigen::Matrix<double,-1,-1>,Eigen::Matrix<double,-1,-1,1,-1,-1>,5>,
1>            Lhs=Eigen::Matrix<double,-1,-1>,
1>            Rhs=Eigen::Matrix<double,-1,-1,1,-1,-1>
1>        ]
1>        c:\*\eigen3\eigen\src/Core/ProductBase.h(151) : voir la déclaration de 'Eigen::ProductBase<Derived,Lhs,Rhs>::coeff'
1>        with
1>        [
1>            Derived=Eigen::GeneralProduct<Eigen::Matrix<double,-1,-1>,Eigen::Matrix<double,-1,-1,1,-1,-1>,5>,
1>            Lhs=Eigen::Matrix<double,-1,-1>,
1>            Rhs=Eigen::Matrix<double,-1,-1,1,-1,-1>
1>        ]
1>        c:\*\eigen3\eigen\src/Core/DenseCoeffsBase.h(96) : lors de la compilation de la fonction membre '<Inconnu>' de la classe <Inconnu>
1>        c:\*\eigen3\eigen\src/Core/util/XprHelper.h(384) : voir la référence à l'instanciation de la classe modèle 'Eigen::DenseCoeffsBase<Derived>' en cours de compilation
1>        with
1>        [
1>            Derived=Eigen::GeneralProduct<Eigen::Matrix<double,-1,-1>,Eigen::Matrix<double,-1,-1,1,-1,-1>,5>
1>        ]
1>        c:\*\eigen3\eigen\src/Core/DenseBase.h(45) : voir la référence à l'instanciation de la classe modèle 'Eigen::ei_special_scalar_op_base<Derived,Scalar,OtherScalar>' en cours de compilation
1>        with
1>        [
1>            Derived=Eigen::GeneralProduct<Eigen::Matrix<double,-1,-1>,Eigen::Matrix<double,-1,-1,1,-1,-1>,5>,
1>            Scalar=double,
1>            OtherScalar=double
1>        ]
1>        c:\*\eigen3\eigen\src/Core/MatrixBase.h(57) : voir la référence à l'instanciation de la classe modèle 'Eigen::DenseBase<Derived>' en cours de compilation
1>        with
1>        [
1>            Derived=Eigen::GeneralProduct<Eigen::Matrix<double,-1,-1>,Eigen::Matrix<double,-1,-1,1,-1,-1>,5>
1>        ]
1>        c:\*\eigen3\eigen\src/Core/ProductBase.h(73) : voir la référence à l'instanciation de la classe modèle 'Eigen::MatrixBase<Derived>' en cours de compilation
1>        with
1>        [
1>            Derived=Eigen::GeneralProduct<Eigen::Matrix<double,-1,-1>,Eigen::Matrix<double,-1,-1,1,-1,-1>,5>
1>        ]
1>        c:\*\eigen3\eigen\src/Core/products/GeneralMatrixMatrix.h(398) : voir la référence à l'instanciation de la classe modèle 'Eigen::ProductBase<Derived,Lhs,Rhs>' en cours de compilation
1>        with
1>        [
1>            Derived=Eigen::GeneralProduct<Eigen::Matrix<double,-1,-1>,Eigen::Matrix<double,-1,-1,1,-1,-1>,5>,
1>            Lhs=Eigen::Matrix<double,-1,-1>,
1>            Rhs=Eigen::Matrix<double,-1,-1,1,-1,-1>
1>        ]
1>        .\file.cpp(117) : voir la référence à l'instanciation de la classe modèle 'Eigen::GeneralProduct<Lhs,Rhs,ProductType>' en cours de compilation
1>        with
1>        [
1>            Lhs=Eigen::Matrix<double,-1,-1>,
1>            Rhs=Eigen::Matrix<double,-1,-1,1,-1,-1>,
1>            ProductType=5
1>        ]
1>c:\*\eigen3\eigen\src/Core/DenseCoeffsBase.h(99) : error C2440: 'return' : impossible de convertir de 'void' en 'double'
1>        Les expressions de type void ne peuvent pas être converties en d'autres types

(In french, sorry :S)

and line 117 is
h.foo(x*(x.transpose()));

Strange...
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Yes, so the issue is that you're trying to access a single coefficient in a product expression, and we currently don't allow that because that would be inefficient. We might allow that later, but that will always be inefficient.

You should probably evaluate your product into a plain matrix, and access that.


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

It's sad that that don't work in Eigen 3 because i worked in Eigen 2. But yes it will be obviously inefficient ! However it's simple to write.
Zmatt
Registered Member
Posts
27
Karma
0
OS
My question is probably silly but how evaluate my product into a plain matrix ?

It's strange because I can't reproduce the error but I've it in my project :S

When I evaluate a product with a transposed matrix, I have this error even if I write
matrix tmp = A;
matrix tmp2 = A.transpose().eval(); //the eval is useless but it change nothing
matrix tmp3 = tmp*tmp2;
It doesn't solve the problem (but it works if I do that in a new project !)
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
In Eigen 3 you can use A.lazyProduct(B) to have a purely lazy product expression (most of the time this is inefficient so use with caution).

To enforce evaluation to a temporary, do (A*B).eval().

Finally, when you write a template function template<typename Derived> foo(const MatrixBase<Derived>& a_mat), it is highly recommended to first copy mat to its nesting type:

const typename Derived::Nesting mat(a_mat.derived());

and then use mat instead of a_mat. For a standard expression Derived::Nesting is simply Derived&, but for a matrix product it is a Matrix<...> object, and so if your function foo is called with a produc (foo(A*B)), then the product will be automatically evaluated for you...


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]