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

Home » Public Forums » archive » improve calculation time
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: improve calculation time [message #88961 is a reply to message #88959] Tue, 08 July 2014 13:10 Go to previous messageGo to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
On Tuesday, July 8, 2014 2:29:57 PM UTC-4, g.na...@gmail.com wrote:
> Hello
>
>
>
> I am trying to improve my code in order to make it faster. A part of my code is the following
>
>
>
> DIM = make_array(301,301,/DOUBLE)
>
> pval = 0
>
>
>
> for i=0, 300 do begin
>
> for j=0, 300 do begin
>
> x = round(i + Bx[i, j])
>
> y = round(j + By[i, j])
>
> if (x lt 301) && (y lt 301) && (x ge 0) && (y ge 0) then begin
>
> DIM[i,j] = SIM[x, y]
>
> endif
>
> pval= pval + (DIM[i,j] - TIM[i, j])^2.
>
> endfor
>
> endfor
>
>
>
> Because I repeat the above procedure a lot of times it takes time to run. I noticed that the DIM array it's creating in every single iteration and I supposed that it takes time. I was wondering if I can write it in a different way in order to overwrite it in each iteration instead of delete it and create it all the time. To overwrite it I need to add it into the loop?
>
>
>
> Regards,
>
> Gina


I *think* this is what you want. Make sure to double check...


SIM = randomu(1, 301, 301)
TIM = randomu(8, 301, 301)
DIM = make_array(301,301,/DOUBLE)
pval = 0
Bx = randomu(5, 301, 301)
By = randomu(2, 301, 301)
x = round(rebin(lindgen(1,301), 301, 301) + Bx)
y = round(transpose(rebin(lindgen(1,301), 301, 301)) + Bx)

i_sim = where( (x lt 301) and (y lt 301) and (x ge 0) and (y ge 0), n_sim )
if n_sim gt 0 then DIM[i_sim] = SIM[i_sim]

pval = total( (DIM - TIM)^2 )
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Comparison between arrays with different lenght
Next Topic: No Raster Image via Imagemagick

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

Current Time: Sun Oct 12 04:35:39 PDT 2025

Total time taken to generate the page: 1.19974 seconds