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

Eigen's Optimizer

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

Eigen's Optimizer

Mon Apr 07, 2014 9:19 am
Hi all

Have a simple question about the Eigen's optimizer. Let's say I wanna compute an expression like:

M = M1*M2 + M3*M4 + M1*M5 + M3*M6

Where all Ms are matrices
Is the expression optimized, at compile time, as:

M = M1*(M2 + M5) + M3*(M4 + M6)

Or is it rather executed as a summation of four matrix-matrix multiplies? I've tried looking into slides, there are some examples about what the Eigen's tree optimizer can do, but I didn't find anything specific to this issue.

My *guess* is that the expression is left as it is because of two points:
- the user is supposed to be able to apply distributivity
- changing the the order/type of operations might affect numerical precision?

Thanks
jitseniesen
Registered Member
Posts
204
Karma
2

Re: Eigen's Optimizer

Mon Apr 07, 2014 11:09 am
Eigen does not apply the distributive property A*B + A*C ==> A*(B+C). I do not think it is possible to do this at compile-time within the confines of the C++ language: how can Eigen know that both multiplications share a common argument? It is in principle possible to do this at run-time, but it will incur a small cost in every expression of the form A*B + C*D. Your point on numerical precision is a good one, but I think that it will not arise often; if some user has done an error analysis and wants the expression to be evaluated in a specific way then they should indicate that with e.g. eval() or by splitting the expression.
fabiol
Registered Member
Posts
5
Karma
0

Re: Eigen's Optimizer

Mon Apr 07, 2014 2:49 pm
Well, I was looking at the slides on the website until I found the part about the tree optimizer. I didn't get into the details, but it felt like you could do some sort of static analysis of the expressions at compile-time, i.e. even before the c++ compilation takes place. In which case, you could spot properties of the expression, including distributivity, and somehow re-structure its computation.

OK, thanks for the clarification, much appreciated.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Eigen's Optimizer

Wed Apr 09, 2014 10:13 am
Let me clarify the tree optimizer is not in Eigen yet, but even when it will become real (not just a proof of concept) it will still not be possible to to do this kind of factorization because we cannot know at compile-time that 'A' appears twice... The tree optimizer only see two Matrix<> object, but that's all, we cannot know they the same object, sadely...


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]