Blitz logo

Blitz Devel :

From: Walter Landry (landry_at_[hidden])
Date: 1998-07-22 20:20:02


>
>The point here being that if you overload operator() it might mess up
>indices if you have same tensor used more than once in a statement. For
>example:
>
>(g_up(i,k)%dX(j,k) || g_up(j,k)%dX(i,k)) might create problem for g_up
>or dX. I'm not sure how your implementation works but it would be
>useful to try it with other compilers. In my case it surfaced when I
>tried KAI C++ (it used to work with SUN CC, all versions of gcc...).

   Actually, you've chosen a bad example. ",", "||", and "&&" are sequence
   guarantee points; i.e. they guarantee that the left argument is evaluated
   before the right argument. If the example replaced "||" with "+" then there
   could be a problem, although there shouldn't be if you design your classes
   right (IMHO).

     Jim

Ok, I see what you're talking about. I did actually think about this
when I designed my package. The function operator() with Index
arguments returns a *copy* of the original tensor, and the *copy* has
its indices set to i,j,k etc. That is why I had to have a Copy_Index.
Otherwise, when I tried to put the final answer into a tensor, it
would put it into a copy that would promptly disappear. The function
operator() with Copy_Index arguments returns the actual tensor, not a
copy. Thus, I have expressions like

   Copy_Index ii('i'), jj('j');
   Index i('i'), j('j');
 
   lX(ii,jj) < (g_up(i,k)%dX(j,k) || g_up(j,k)%dX(i,k))

However, if we unroll all of the loops, we don't really have to worry
about all of this subtlety. The indexes will only matter to the
compiler as it deciphers the templates, so it doesn't need to think
about setting indices twice.

Walter Landry
landry_at_[hidden]

--------------------- blitz-dev list --------------------------------
* To subscribe/unsubscribe: mail to majordomo_at_[hidden], with
"subscribe blitz-dev" or "unsubscribe blitz-dev" in the body of the message
* Blitz++ web page: http://oonumerics.org/blitz/