Glas :[glas] when to evaluate scalar expressions |
From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2006-04-20 16:14:32
The expression-template mechanism is used to evaluate the expression at
the assignment as mentioned here:
http://glas.sourceforge.net/doc/papers/introduction/index.html .
In addition to avoiding temporaries and loop fusion etc., evaluating the
expression at assignment allows us also to dispatch the expression as a
whole (i.e. lhs and rhs) to a specific backend.
But should we also delay evaluating scalar-expressions until assignment.
Suppose following code-snippet
glas::dense_vector<double> v(10),w(10) ;
glas::assign(w,mult(norm_2(v),v)) ;
where we multiply every element in the vector v with the norm_2 of v and
assign the result to a vector w. If we delay all evaluations until
assignment and avoid having temporaries, for every element in w we will
multiply the corresponding element in v with the norm_2 of v which we
recalculate every time again.
So should it not be better to evaluate scalar-expression always
immediately? Or are there scenario's where it would be better to delay
the evaluation of the scalar-expression?
toon