Blitz logo

Blitz Support :

From: Todd Veldhuizen (tveldhui_at_[hidden])
Date: 2003-08-29 11:40:08


Maybe it's best to visualize an outer product followed by a reduction.
The indices refer to the dimensions of the outer product.

Some examples:

firstIndex i;
secondIndex j;
thirdIndex k;
fourthIndex l;

A(i,j) * B(i,j)
This is a two-dimensional array (i,j)

sum(A(i,j) * B(i,j), j)
This is a one dimensional-array (i)

A(i,j) * B(k,l)
This is a four-dimensional array (i,j,k,l)

A(i,k) * B(k,j)
This is a three-dimensional array (i,j,k)

sum(A(i,k) * B(k,j), k)
This is a two-dimensional array (i,j)

Your example:
M(i1,j) * T(i2,i3,i4,j)
This is a five dimensional array (i1,i2,i3,i4,j)

sum(M(i1,j) * T(i2,i3,i4,j), j)
This is a four dimensional array (i1,i2,i3,i4)

Hope that helps!

Cheers,
Todd

-- 
Todd Veldhuizen  /  tveldhui_at_[hidden]  /  Indiana University Computer Science
On Fri, 29 Aug 2003, Fernando Perez wrote:
> Matthias Schillinger wrote:
> > declare j as thirdIndex and it should work, I think.
> > See also the user guide on page 57.
>
> Thanks a lot!  It does indeed work correctly.  Even though I read the docs
> several times, I just misunderstood something.
>
> However, perhaps more detail on the semantics of these magical index objects
> might be worth having in the manual, since I still find it quite confusing.
>
> The manual says:
>
> "There is a distinct index placeholder type associated with each dimension of
> an array. The types are called firstIndex, secondIndex, thirdIndex, ...,
> tenthIndex, eleventhIndex."
>
> This is fine when all your objects have the same rank.  But for example, the
> 4d version of my code (which thanks to your comments now works correctly), reads:
>
> // 4d version
> void mat_ten_inner0(Array<double,2>& M,
> 		   Array<double,4>& T, Array<double,4>& U ) {
> 	firstIndex i1;
> 	secondIndex i2;
> 	thirdIndex i3;
> 	fourthIndex i4;
>
> 	fifthIndex j;
>
> 	U = sum(M(i1,j)*T(i2,i3,i4,j),j);
> }
>
> j has to be declared as a fifthIndex, even though nothing is 5-dimensional
> here.  And i2,i3,i4 play the role of the 2nd, 3rd and 4th dimension for U, but
> one less each for T.
>
> So exactly what the semantics of these objects is, remains a bit of a mistery
> to me.  I'd love to understand it, though, as they make the code an absolute
> joy to write (once it works ;)
>
> Many thanks again for your help.
>
> Regards,
>
> Fernando.
>
> _______________________________________________
> Blitz-support mailing list
> Blitz-support_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>