[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: subscript array question




In article <7a0j1q$mvb$1@news.NERO.NET> bennetsc@ucs.orst.edu 
(Scott Bennett) writes:

[..snip histogram solution, among other things..]

>	That sure looks ingeniously devious to me.  I had to try out all
> the pieces to see how it worked. :-)  

I agree - almost sinister - a big contender for Hi-Tech Tip of the
year (and it's still just February!).

> However, I couldn't get my 2D
> case to perform well.  I'm omitting here some non-essentials, but the
> routine originally had this in it:
>
[..]
>	       ths[thsubs,ssubs] = ths[thsubs,ssubs] + llvol
[..]
>
> Written like that, it ran in ~15 seconds on my test data set, but gave
> values in ths that were often too small, as I originally posted.

[..loop version taking ~46 seconds omitted..]

[..hist_2d version taking 37 *minutes* omitted...]

What you ought to try instead is to calculate the one-dimensional
index values from the two-dimensional indices:
 
    subs = thsubs + ssubs * (size(ths))(1)

And then just plug it into the original scheme:

  ths[min(subs):max(subs)] = ths[min(subs):max(subs)] +histogram(subs)

On a general note, if "subs" covers the array very sparsely, the
histogram method is not necessarily faster than the loop version (as a
limiting case, consider a huge array, and you want to add 1 to the
first and last element only - the histogram is just as huge as the
array, and a lot of time will be spent adding zeros to the array!)

Regards,

Stein Vidar