Blitz logo

Blitz Support :

From: Julian Cummings (cummings_at_[hidden])
Date: 2005-06-16 15:01:44


Hello Peter,
 

> -----Original Message-----
> From: blitz-support-bounces_at_[hidden]
> [mailto:blitz-support-bounces_at_[hidden]] On Behalf Of
> Peter Kümmel
> Sent: Thursday, June 09, 2005 7:16 AM
> To: Support list for Blitz++
> Subject: [Blitz-support] blitz looping
>
> Hello,
>
> I've got a question to the code "generated" by blitz:
> Does following code
>
> struct C1{
> double f(double x)const {return x*x;}
> BZ_DECLARE_MEMBER_FUNCTION(C1,f)
> };
> struct C2{
> double f(double x)const {return sqrt(x);}
> BZ_DECLARE_MEMBER_FUNCTION(C2,f)
> };
> ...
> int N=314;
> Array<double, 2> A(N,N);
>
> firstIndex i;
> secondIndex j;
> C1 c2;
> C2 c2;
> A = c2.f( c1.f( A(i,j) ) );
>
>
> also result in only ONE loop?, e.g.:
>
> for(i...
> for(j...
> A[i][j]= c1.f( (A[i][j]) );
> A[i][j]= c2.f( (A[i][j]) );
>
> As I understand it this is the case, or I'm wrong?

There should be only one loop, and in fact, it should be slightly better
than what you wrote above because you do not need to store the temporary
result of c1.f(A(i,j)) back into A(i,j) first. This can be hard to verify
unless you have a compiler that preserves intermediate C code (e.g., KCC) or
prints out the templates it instantiates (e.g., SGI CC). By the way, you do
not need the index placeholders i and j on the right-hand side of your
expression unless there is an offset or restricted range with respect to the
original Array domain. So you can just say

A = c2.f(c1.f(A));

>
> Is there a difference in the generated code if I use the
> "inline" specifier?

No, since your scalar functions f are defined within the struct definition
and will be implicitly inlined.

>
>
>
> And is there a other syntax?
> Something like
>
> A = A(i,j) -> c1.f -> c2.f;
> (A goes first through c1.f then through c2.f) or A = c2.f ->
> c1.f -> A(i,j); (First c1.f is applied on A then c2.f)
>
> Would it be hard to implement such a overloading?

I think the existing syntax is superior, since it is more compact.

>
>
> And a other question: Is there a way to do looping manually
> (similar to FTensor), e.g:
>
> Array<int,1> A(N);
> Array<int,1> B(N);
>
> forall()
> [
> A=A+B,
> B=A*A
> ]
>

Yes. You can loop through the Array using either nested loops over the
indices or using a single loop with an Array iterator. In this case, you
don't need the special declarations of the member functions f as Array
functions because you will be applying f to single elements of the Array
manually. The BZ_DECLARE macros are there only to convert scalar functions
into Array functions.

Regards, Julian C.

> Maybe such a syntax is possible or exits already in the
> (other?) library.
>
>
> Best regards,
> Peter
>
> _______________________________________________
> Blitz-support mailing list
> Blitz-support_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>
>