Blitz logo

Blitz Support :

From: Julian C. Cummings (cummings_at_[hidden])
Date: 2004-08-03 13:36:20


Hello Othmar,

>
> Questions:
>
> 1.
> >In the meantime, I'm afraid you will need to assign
> >the selected elements from your 1d dataVector object into a
> temporary 2d >dataMatrix object first, and then use the
> temporary dataMatrix object in >your array expression.
>
> Is there another, more efficient way of assigning the
> selected elements than assigning them elementwise in for-loops?

No, I think using for loops (or equivalently using iterators) is the only
reasonable way you can do this.

> 2.
> If assigning by for-loops is the only way, is it still worth,
> with respect to performance, to 1. assign all the elements
> and 2. calculate the array expression instead of replacing
> the whole thing by an elementwise approach like the following?
>
> for (i=0; i<sizeX; i++)
> {
> for (j=0; j<sizeY; j++)
> {
> // calculate index for element i,j
> index = ...;
>
> dataMatrix2(i,j) = dataMatrix1(i,j) + dataVector(index);
> }
> }

It is only worthwhile to store the result of the indirection as a temporary
2d Array if you plan to reuse that result multiple times. Otherwise, it is
probably more efficient to use for loops as above or iterators, like I did
in my previous e-mail example:

> >Array<float,2>::iterator pdm1 = dataMatrix1.begin(), pdm2 =
> >dataMatrix2.begin(),
> > pend = dataMatrix2.end();
> >Array<int,2>::iterator pind = arrayOfIndices.begin();
> >for (; pdm2 != pend; ++pdm1, ++pdm2, ++pind)
> > *pdm2 = *pdm1 + dataVector(*pind);

> 3.
> When I use VectorPick, which options do I have to assign the
> data to a
> Vector or an Array object to
> ease further calculations?

You can assign a VectorPick directly to a Vector as a Vector expression.
The Vector should be the same length as the number of items in the
VectorPick. But Array expressions and Vector expressions do not mix. So
you would have to use explicit loops with indices or iterators in order to
assign to an Array object.

Regards, Julian C.

Dr. Julian C. Cummings
Staff Scientist, CACR/Caltech
(626) 395-2543
cummings_at_[hidden]