Expression template

Etranger via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 23 05:55:51 PDT 2016


On Saturday, 23 July 2016 at 12:27:39 UTC, rikki cattermole wrote:
>
> If you evaluate it as v = a + b + c instead of v = a + (b + c) 
> you will still have a temporary value. Remember structs are 
> just the values they carry and are basically optimized out. 
> Either way I recommend you not worry about it. Compilers can be 
> smart and dmd is mostly good enough in this department.
>
> If you use dynamic arrays and not fixed sized arrays, they will 
> go into the heap, so be careful with what you do with them. 
> Fixed sized arrays like gl3n does is fairly cheap since it goes 
> on to the stack and in some cases only in registers.
>
> Usually if we solve it on IRC we post the solution that we come 
> up with on the post.

For small matrices of fixed size, lazy evaluation may not be 
worth it, but for large matrices and vectors, it is worth it. For 
example, for testing purpose, I wrote 2 versions of and MLP 
(multi-layered perceptron) lib, one that uses openBLAS and one 
with Eigen. The one with Eigen was significantly faster than the 
one with openBLAS tanks to lazy evaluation. No wonder all the 
most known c++ linear algebra lib use this method (Eigen, 
Armadillo, Blitz++, Boost uBlas, ...).

This link http://eigen.tuxfamily.org/dox/TopicLazyEvaluation.html 
explain better than me the advantages of this technique. Given 
the emphasize of D over generics, I think it is worth to explore 
this direction (I hope with better results than what I wrote !).


More information about the Digitalmars-d-learn mailing list