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

Operation speed up

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

Operation speed up

Tue Sep 06, 2011 12:14 pm
Hello,

i have big matrix operations. the matrices are size of ~400x400. I create the matrices with the constructor:

Code: Select all
MatrixXd m(i, j)


all used matrices are stored in objects like:

Code: Select all
class A
{
private:
 MatrixXd m1, m2...;
};


the expressions are like:
Code: Select all
res.noalias() = (m1 * m2 + (m2 * m4) * m5.transpose()) * m5.transpose() * vector1 +
    ...(more multi.)...
   m6 * vector2 * std::pow(constant1, constant2) / constant3.;


The size of mx (res, vectorx...) changes sometimes. But not often.

How can i speed up the matrix operations? Is this expression optimal? Should i "preallocate" some matrices for the provisional results?

Thanks for your help!

PS: EIGEN_MAKE_ALIGNED_OPERATOR_NEW results in an error: "Return has value in function returning void". What can id do?
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Operation speed up

Wed Sep 07, 2011 1:11 pm
Eigen normally evaluates each matrix product in a temporary in chained matrix products, so you shouldn't have to do much yourself here. if you want to tweak things yourself, the .eval() method allows you to force evaluation at a certain point in the expression.

About EIGEN_MAKE_ALIGNED_OPERATOR_NEW, that doesn't make much sense, where did you put it?


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Operation speed up

Wed Sep 07, 2011 2:38 pm
you can use parenthesis to change the default priority in chained matrix product. For I see in your expression something like:

A*B*v

where v is a vector. It is much faster to write:

A*(B*v)




Then you can also split the summations over multiple expression, e.g.:

res.noalias() = A*B + C*D - s*E*F;

becomes:

res.noalias() = A*B;
res.noalias() += C*D;
res.noalias() -= s*E*F;

This avoids some temporaries, but don't expect significant speed gain.


Bookmarks



Who is online

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