[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Vectorization question
Hi Liam,
I came up with a different approach. For short arrays in a loop, it is 3
times slower than your method, Liam. However, with A being 1,000,000 and
both X and B 100,000 elements long, your method could not allocate
memory on my machine, while mine ran in 0.07 s. Check out the code
below. The loops were put in to get runtime extimates.
I run 5.3 on PowerMac G4, 192 MB total RAM, 64 MB allocated to IDL.
Cheers,
Pavel
pro pavel, a, b, x
out = a
start = systime(1)
;for i =0, 10000 do begin
ind = x[uniq(x, sort(x))]
loc = value_locate(x, ind)
sum_b = total(b, /cumulative)
res = [0, sum_b[loc], 0]
a_values = (res-shift(res, 1))[1:n_elements(res)-2]
out[ind] = a_values
;endfor
print, systime(1) - start
;print, out, format='(10i4)'
end
pro liam, a, b, x
out = a
start = systime(1)
;for i =0, 10000 do begin
tmp = intarr(n_elements(a), n_elements(x))
tmp[x, indgen(n_elements(x))] = b
out = a + total(tmp, 2)
;endfor
print, systime(1) - start
;print, out, format='(10i4)'
end