At 11:05 AM 6/15/98 -0600, James A. Crotinger wrote:
> tensor tst1 = t2("ik")*t4("ijlp")*t4("kjlq")*t2("pq");
> tst1 =
>sum(t2("ik")*sum(sum(t4("ijlp")*t4("kjlq"),"jl")*t2("pq"),"pq"),"ik");
Or without the quotes:
tst1 = t2(i,k)*t4(i,j,l,p)*t4(k,j,l,q)*t2(p,q);
versus
tst1 = sum(t2(i,k)*sum(sum(t4(i,j,l,p)*t4(k,j,l,q),j,l)*t2(p,q),p,q),i,k);
The first one is certainly shorter, and that is a plus. It could only be
done with expression templates unless we said that each index can appear
either once (in which case it is not summed over) or twice (in which case
it is summed over).
>Also, if we don't defer evaluation (with something like expression
>templates), then expressions like
>
> A_i = epsilon_ipq * B_p * C_q
>
>will be hard to do efficiently, won't they?
Actually, I think this particular case would evaluate efficiently. First
you would do:
T1_iq = epsilon_ipq * B_p
T1 is then an antisymmetric rank 2 tensor, which would be stored
efficiently. Multiplying that by C_q would also be efficient.
In the more general case however there is a good point here.
There are several questions here when comparing an ET version to a non-ET
version.
1. Which runs faster?
Depending on the expression and the compiler, I could see either one
running faster. The influences here are that the non-ET version might
effectively do some common subexpression elimination automatically, but for
cases with lots of zeros or ones the ET case might be able to eliminate
clauses better.
2. Which compiles faster?
For small expressions that don't generate high-rank intermediates, the
non-ET one would certainly compile faster. For high-rank intermediates,
I'm not sure, since the total amount of work may really be the same, but my
bet would be that the ET version compiles slower.
3. What are the user interface considerations?
If a tensor expression is a tensor with an expression engine, users might
be surprised. If you pass such a tensor to a subroutine which leaves the
engine general, the user will get an expression passed in. That may not be
bad, or we could provide some sort of 'eval' function to evaluate the
expression to a simple tensor. Then instead of passing the expression you
would pass eval(expression). That is what we're doing with Arrays anyway.
This may only be answerable experimentally.
-Steve Karmesin
======================================================================
Pooma Team Leader
karmesin@lanl.gov
phone: (505)665-6019
fax : (505)667-4939
For PGP public key, send message with subject line: SEND PUBLIC KEY
======================================================================
--------------------- blitz-dev list --------------------------------
* To subscribe/unsubscribe: mail to majordomo@oonumerics.org, with
"subscribe blitz-dev" or "unsubscribe blitz-dev" in the body of the message
* Blitz++ web page: http://oonumerics.org/blitz/
This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 04:30:05 EST