![]() |
Blitz Support : |
From: Faheem Mitha (faheem_at_[hidden])
Date: 2004-12-23 18:41:12
On Thu, 23 Dec 2004, Robert M Dorazio wrote:
> This seems to be a recurring question on the Blitz support mailing list, so
> I am posting a previous reply:
Ooh. Sorry, for some reason it never occured to me to do a search of the
archives (assuming that is possible). Google did not give me anything.
> The enclosed file "Extract.h" contains source code for extracting the
> elements of a 1D Array or of a row or column of a 2D Array using an integer
> array or a boolean array to index the elements to be extracted. I make no
> claims about the code's efficiency, but it does work. The enclosed file
> "driver.cc" provides examples of how the function extract() may be used.
Thanks for the code. I'll study it.
Is there some technical reason why this feature is not implemented in
Blitz? It seems a relatively natural thing.
Faheem.
***************************************************************************
I've written a naive function as follows.
typedef set<int> IntSet;
blitz::Array<string, 2> take(blitz::Array<std::string, 2> arr, IntSet ind)
{
int i, j, rows = arr.rows();
IntSet::iterator intsetpos;
int indlen = ind.size();
blitz::Array<string, 2> slice(rows, indlen);
for(i = 0; i<rows; i++)
for(j = 0, intsetpos = ind.begin(); j < indlen; j++, intsetpos++)
slice(i, j) = arr(i,*intsetpos);
return slice;
}
But I am sure one can do better. Faheem.