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

Home » Public Forums » archive » Optimizing loops
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: Optimizing loops [message #92398 is a reply to message #92368] Tue, 08 December 2015 08:28 Go to previous messageGo to previous message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
On Wednesday, December 2, 2015 at 1:04:33 PM UTC-6, sam.t...@gmail.com wrote:
> If anyone has optimization suggestions, please let me know! Thanks :)

In addition to the suggestions that Sergey provided, let's add a couple more:

> ind14 = WHERE(dist LE 14.)
> land14 = land_mask(ind14)
> landy = WHERE(land14 EQ 0, landy_cnt)
> land_perc[j] = FLOAT(landy_cnt)/FLOAT(N_ELEMENTS(land14))*100

For the last line, no need to "float" both numbers. Also, you might consider either a) dropping the *100 and do that at the end or b) reordering the operations so that you don't need to call FLOAT at all. Consider:

IDL> 1/2 ;we know this is not the number we are looking for
IDL> 1/FLOAT(2) ;closer, but we'll have to multiply the final array by 100
IDL> 100.0 * 1/2 ;this works, but only if the "100.0" comes first

Also, you don't need to count the number of elements in land14 - you already have that information. It's the same size as ind14, and you can get that size using the count argument.

Further, x*x is faster than x^2...although the cost/benefit depends on the size of the arrays.

Finally, there *is* a way to further vectorize your code. But, whether it's worth it depends on the size of the land/sat arrays. There's some black magic using rebins, pound signs, etc.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Text print in figure with format
Next Topic: Using IDLgrShaderBytscl on Windows to display floating-point image data quickly.

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

Current Time: Sat Oct 11 09:48:10 PDT 2025

Total time taken to generate the page: 0.31764 seconds