![]() |
Blitz Support : |
From: Julian C. Cummings (cummings_at_[hidden])
Date: 2004-07-19 14:49:10
Hello Othmar,
I think what you are looking for is support for array indirection, where you
reference elements of an Array using indices stored in another Array. There
is some support for this built into blitz already, but it is currently
limited to using the indirect array view as an lvalue (on the left-hand side
of an assignment). This would need to be extended so that the IndirectArray
class (see <blitz/array/indirect.h>) was made to derive from ArrayExpr and
could be used as part of an array expression. There are also some code
comments in the <blitz/array-impl.h> header about possibly extending the
operator() methods used for array slicing to support the use of Vector<int>
indexing objects to produce an ArrayPick type analogous to VectorPick.
Presumably there would be one
Vector<int> argument for each Array dimension and each Vector would have the
same length.
Instead of using a set of Vector<int> arguments, one ought to be able to use
an Array of ints as well.
Let me experiment with this a bit and see how much work would be needed to
make such extensions. 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. Or if you wish to get your hands a little dirty, you
could write a loop using iterators over the dataMatrix objects and the
arrayOfIndices object and handle the indirection yourself:
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);
Regards, Julian C.
Dr. Julian C. Cummings
Staff Scientist, CACR/Caltech
(626) 395-2543
cummings_at_[hidden]
> -----Original Message-----
> From: blitz-support-bounces_at_[hidden]
> [mailto:blitz-support-bounces_at_[hidden]] On Behalf Of Othmar Frey
> Sent: Friday, July 16, 2004 8:06 AM
> To: blitz-support_at_[hidden]
> Subject: [Blitz-support] array of indices applied to a vector
> (or 1-dimarray)
>
>
> Hi.
>
> I am rather new to blitz++.
>
> I would like to evaluate a one dimensional array
> at indices that are given in a - let's say - 2-dimensional
> array of indices.
>
> What I would love to have working is something like:
> (something I am really fond of that it works in Matlab)
> -------------------------------------------------------
> ...
>
> Array<float,1> dataVector(100);
> Array<float,2> dataMatrix1(20,20);
> Array<float,2> dataMatrix2(20,20);
> Array<int,2> arrayOfIndices(20,20);
>
> ...
> // fill dataVector and dataMatrix1 with some data
> // and set the indices in arrayOfIndices according to my needs
> ...
>
> dataMatrix2 = dataMatrix1 + dataVector(arrayOfIndices);
>
> ...
> ---------------------------------------------------------
>
> I've learned from the example pick.cpp at
>
> http://www.oonumerics.org/blitz/examples/blitz/pick.cpp
>
> that there's a possibility to pick
> values from a vector according to a given index vector by using
> VectorPick.
> But then, all the nice elementwise operators don't work
> as the do for
> arrays.
>
> Is there straightforward solution to this problem, which I missed?
> (Maybe one that is even mentioned in the documentation?)
>
> Many thanks for your help.
>
> Cheers
>
> Othmar
>
> --
> --------------------------------------------------------------
> ---------
> Othmar Frey Remote Sensing
> Laboratories RSL
> ofrey_at_[hidden] University of Zurich
> http://www.geo.unizh.ch/~ofrey Winterthurerstrasse 190
> phone +41 44 635 51 64 CH-8057 Zurich
> fax +41 44 635 68 46 Switzerland
> --------------------------------------------------------------
> ---------
>
>
> _______________________________________________
> Blitz-support mailing list
> Blitz-support_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>