Re: Cumulative max() in *arbitrary* dimension? [message #79583 is a reply to message #79382] |
Sat, 10 March 2012 09:21   |
Heinz Stege
Messages: 189 Registered: January 2003
|
Senior Member |
|
|
First: On Fri, 09 Mar 2012 18:58:13 +0100, I wrote:
> for i=off,ns-off,off do a[i]=a[i-off:i-1]>a[i:i+off-1]
There is a mistake. It has to read:
for i=off,n_elements(a)-off,off do a[i]=a[i-off:i-1]>a[i:i+off-1]
Second: My contribution => my work. ;-) I measured the times for an
array a=byte(randomu(seed,60,400,3000),/long). I tested the following
versions:
[1] i1=0 &i2=off-1 & $
for i=1,s[d]-1 do a[i*off]=a[i1:i2]>a[(i1+=off):(i2+=off)]
[2] for i=1,s[d]-1 do $
a[i*off]=a[(i-1)*off:i*off-1]>a[i*off:(i+1)*off-1]
[3] for i=off,n_elements(a)-off,off do a[i]=a[i-off:i-1]>a[i:i+off-1]
I ran each version 2000 times and found no significant differences in
the run-time. There only seems to be a slight trend for [2] beeing the
slowest. However it does not have any practical relevance. Here are
the details:
[1] 134.3 (+/-0.2) ms (calculation of i1 and i2 included)
[2] 134.9 (+/-0.2) ms
[3] 134.2 (+/-0.2) ms
The given errors are statistical standard-errors ("1 sigma").
Heinz
|
|
|