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

Home » Public Forums » archive » Re: Optimization Question: Sum at each element of array
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: Optimization Question: Sum at each element of array [message #75083] Tue, 15 February 2011 12:15 Go to previous message
James[2] is currently offline  James[2]
Messages: 44
Registered: November 2009
Member
On Feb 14, 9:58 pm, Charles Steinhardt <charles.steinha...@ipmu.jp>
wrote:
> Hello,
>
> I'm trying to optimize the following:
>
>   for i=0, 100 do begin
>      y = y + myfunc(x, x + sigma * (i-50)/10.0, P[2]*myfunc2(x + sigma
> * (i-50)/10.0), sigma)
>   endfor
>
> Here, x, y, and sigma are arrays of the same cardinality.  I know the
> for loop is slow in IDL compared to array operations, but I'm having
> problems finding a faster way to do this.  Is it really faster to make
> an array of findgen(101) and then do some sort of summation over
> that?
>
> I'm hoping somebody has run into this before - I'd appreciate any
> advice you have!
>
> Thank you,
>
> -Charles

One simple optimization step is to replace:

y = y + (blahblahblah...)

with

y += (blahblahblah...)

This avoids making IDL acquire memory each iteration to store the
result of y + (blahblahblah...).
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Nonlinear Diffusion Image Filtering Package
Next Topic: Re: possible bug with center keyword option for FFT

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

Current Time: Wed Oct 08 15:06:02 PDT 2025

Total time taken to generate the page: 0.00368 seconds