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

How ET optimisation is applied in following case

Tags: None
(comma "," separated)
wingsit
Registered Member
Posts
28
Karma
0
OS
hi all

I am starting to find that the technique of ET is very interesting thus and am looking into how it is used in practical library. I hope someone can help me here. Most of the articles online are about optimising the following addition expression
Code: Select all
a = b + c + d + e;

which ET can transform it into something like
Code: Select all
for(int i = 0; i < n; ++i){
a[i] = b[i] + c[i] + d[i] + e[i];
}

by walking the expression tree
Code: Select all
Assign<a, sum<sum<sum<d,e>, c>, b>>


This optimisation is rather for element-wise operation. Now suppose that I have the follow matrices computation (not exactly Eigen notation)

Code: Select all
int m, n, p, q, r;
MatrixXd a(m, n), b(n, p), c(p,q), d(q,r), result(m, r);
//Fill them up with doubles
result = a*b*c*d; //where * is matrix product


What kind of optimisations are performed here at compiled time?
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Eigen evaluates matrix-matrix product immediately. So in the case of an expression involving only matrix-matrix products, such as in your last example, Eigen's ETs won't make a big difference: they will only help ensure that no redundant copy of matrices is performed (as would be the case if operator* returned a new matrix by value).

If you are sure that you want matrix products to be lazy i.e. not evaluate immediately, you can do:

Code: Select all
result = a.lazyProduct(b).lazyProduct(c).lazyProduct(d);


but be very careful: this can be a very bad idea as the complexity of evaluating such a chained lazy product can be far worse than the complexity of the default i.e. evaluating each product immediately!!


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: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]