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

Re: Convolution of Stick Spectra



bjackel@phys.ucalgary.ca wrote:

>It helps a bit to pre-calculate your variance term.
>Cuts execution time from 27 to 18 seconds on my PC.
>
>variance_term= ( ( (.12*sqrt(energy/1000))/1.6651)*1000)^2
>FOR indx=0L,nstick-1 DO BEGIN
>   result = result + intensity[indx]* $
>               exp(-((energy_scale - energy[indx])^2)/
>variance_term[indx] )
>ENDFOR
>

Actually, I was surprised to find that didn't change the timing any on my
sytem (alpha OSF unix 5.3 Nov 11 1999) to any appreciable degree. With the
code I first posted (attached below as a procedure), it took about 10.5
seconds either way.

IDL> test
time other:        10.706325
time precalc:        10.545039

Jumping up to 20,000 elements, the timing was still pretty much identical
(42.9 vs. 42.7 seconds).

Todd

----

pro test
convoluted = fltarr( 2, 2048 )
convoluted[0,*] = findgen( 2048 ) / 2047. * 4.

;; Let's fake a stick spectrum, we usually have at least this many elements
stick = abs(randomn( systime(1), 2, 5000 ))
stick[0,*] = stick[0,*] * 4.
stick[1,*] = stick[1,*] * 1000.

time = systime(1)

variance = (((.12*sqrt(stick[0,*]/1000))/1.6651)*1000)^2
for i=0L, n_elements( stick ) / 2 -1 do $
     convoluted[1,*] = stick[1,i]*exp(-((convoluted[0,*] - stick[0,i])^2)/ $
                variance[i]) $
                 + convoluted[1,*]

time2 = systime(1)

for i=0L, n_elements( stick ) / 2 -1 do $
     convoluted[1,*] = stick[1,i]*exp(-((convoluted[0,*] - stick[0,i])^2)/ $
                (((.12*sqrt(stick[0,i]/1000))/1.6651)*1000)^2) $
                 + convoluted[1,*]

print, 'time other: ', systime(1) - time2
print, 'time precalc: ', time2 - time

end