Boost logo

Glas :

[glas] question

From: Karl Meerbergen (Karl.Meerbergen_at_[hidden])
Date: 2007-08-07 04:54:41


Consider the following expression:

x = v / norm_2( v ) (*)

where v is a VectorExpression and x a DensevectorCollection e.g.

In the current glas backend implementation, (*) corresponds to something

for ( size_type i=0; i<size(x); ++i ) {
 x( i ) = v( i ) / norm_2( v ) ;

This implies that norm_2(v) is reevaluated for each entry in x. The
reason is that norm_2 does not return a value, but an expression that is
only evaluated when it is used in a backend. It is pretty easy to change
the evaluation system so that the result of norm_2 is first stored into
a temporary variable. The loop would then look like:

value_type< norm_2_expression ... >::type temp( norm_2(v) ) ;
for ( size_type i=0; i<size(x); ++i ) {
 x( i ) = v( i ) / temp ;

Personnally, I prefer the second option, since I see no advantage of the
first, but I may be wrong. Comments please.