comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Can this be vectorized?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Can this be vectorized? [message #17457] Tue, 26 October 1999 00:00 Go to previous message
davis is currently offline  davis
Messages: 15
Registered: March 1995
Junior Member
I am looking for either a matlab or IDL solution to this problem.
Suppose that I have two 1-d arrays, `I' and `X', where `I' is an integer
array and `X' is a floating point array. `I' is assumed to be sorted in
ascending order. I would like to produce a third array `Y' that is
formed from the elements of `X' as follows (pseudocode):

len = length (X); #number of elements of X

i = 0;
j = 0;

while (i < len)
{
last_I = I[i];
sum = X[i];
i = i + 1;
while ((i < len)
AND (I[i] == last_I))
{
sum = sum + X[i];
i = i + 1;
}
Y[j] = sum;
j = j + 1;
}

For example, suppose

I = [ 1 2 3 3 4 4 4 5]
X = [ a b c d e f g h]

Then, Y would be 5 element array:

Y = [a b (c+d) (e+f+g) h]

One partially vectorized pseudocode solution would be:

jj = 0
for (i = min(I) to max(I))
{
J = WHERE (I == i);
Y[jj] = sum_elements (X[J])
jj = jj + 1
}

What is the best way to vectorize this? In reality, X consists of
about one million elements, so I would prefer a solution that is
memory efficient. I apologize for posting to both newsgroups, but I
am looking for a solution in either language.

Thanks,
--John
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Color problem on Mac, not Windows - something about 239?
Next Topic: undefined keyword variables

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 02:12:01 PDT 2025

Total time taken to generate the page: 1.35984 seconds