question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

question

Karl Meerbergen-2
Hi,

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
like:

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.

Karl

_______________________________________________
glas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/glas

Karl.Meerbergen.vcf (417 bytes) Download Attachment
Loading...