Re: [eigen] aliasing system |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] aliasing system*From*: Andre Krause <post@xxxxxxxxxxxxxxxx>*Date*: Thu, 06 Sep 2007 16:02:15 +0200*Organization*: http://www.coreloop.com

Benoit Jacob wrote:

On Thu, 6 Sep 2007, Andre Krause wrote: Hi Andre,I do understand your concern. Let me first stress that the same problemexists in the other ET libraries. TVMET has a global function alias().Blitz++ is even worse: not only does it suffer from the same problem, itdoes not even provide an aliasing system! See here:http://www.oonumerics.org/blitz/docs/blitz_3.html#SEC81It would be impossible to determine exactly when aliasing is needed andwhen it's not, without paying the price of a constant overhead, which wedon't want.

m = m*m; is there some template magic available to detect this?

Expression templates eliminate temporaries. This is a big performanceimprovement.Let me try to explain what is going on here, because it really isimportant. Here is an example. Suppose that you have vectors u, v, w,and you do:u = v + w; Then Eigen2 will automatically evaluate this as: for(int i = 0; i < size; i++) u[i] = v[i] + w[i]; and the for loop can then be unrolled (I'll take care of this later). So this is fast.Now Eigen1 (like any library without ETs) does this: it evaluates theabove expression asoperator=(u, operator+(v, w))So it first calls operator+(v, w), which returns a result by value, socall r this result, and then it calls operator=(u, r).So all in all, Eigen1 evaluates this expression as: for(int i = 0; i < size; i++) r[i] = v[i] + w[i]; for(int i = 0; i < size; i++) u[i] = r[i];As you can see, Eigen1 is inefficient here, because it wastes time withthis useless temporary r. So the elimination of the temporary allowsEigen2 to be much faster.

Now alias() negates this. alias() forces the creation of a temporary. Soif we followed your suggestion of implementing operator= as"this->alias() = m" then we would negate much of the benefit of using expression templates!We really want to only use alias() when it's necessary, because it iscostly.I agree that it makes the API harder, but I don't see a better solution. I think, this will be Item #1 in our FAQ/troubleshooting.

for example, what about v = 2*v; // <-- doubling elements in a vector

Cheers, Benoit

**Follow-Ups**:**Re: [eigen] aliasing system***From:*Benoît Jacob

**References**:**[eigen] aliasing system***From:*Benoît Jacob

**Re: [eigen] aliasing system***From:*Andre Krause

**Re: [eigen] aliasing system***From:*Benoit Jacob

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] aliasing system** - Next by Date:
**Re: [eigen] aliasing system** - Previous by thread:
**Re: [eigen] aliasing system** - Next by thread:
**Re: [eigen] aliasing system**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |