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

Home » Public Forums » archive » Re: Avoiding FOR loops (version googleplex.infinity)
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: Avoiding FOR loops (version googleplex.infinity) [message #59727 is a reply to message #59677] Wed, 09 April 2008 08:18 Go to previous messageGo to previous message
Tom McGlynn is currently offline  Tom McGlynn
Messages: 13
Registered: January 2008
Junior Member
On Apr 8, 5:41 am, Gaurav <selfishgau...@gmail.com> wrote:
> Unfortunately, Michael's method fails for my array which is quite
> large (it being an image). Some of the images are pretty massive (at
> around 10k by 10k pixels).
>
> I am still tring to make the best out of Jim's method which somehow
> makes use of Convolution and that is supposed to be good. I would love
> to hear more responses.
>
> Thank you,
>
> Gaurav


Dear Guarav,

One thing you might keep in mind is that there is nothing wrong or
necessarily inefficent using for loops. You just need to make sure
that you are doing enough within each loop to amortize the cost of
interpreting the statements. E.g., for the very large images you are
dealing with you might try something as simple as the little (largely
untested) function below. I doubt it's optimal, but it's reasonably
fast for 10Kx10k images (~20 seconds for a 5x5 box). I suspect that a
cleverer algorithm would be able to use the memory cache more
efficiently, but with 100 million comparisons per loop iteration for a
10K image, the loop overhead is not going to be an issue!

Regards,
Tom McGlynn

function comparebox, input, boxsize

sz = size(input)
if sz[0] ne 2 then begin
print,'Input not 2-D array'
return, 0
endif

nx = sz[1]
ny = sz[2]

if nx lt boxsize or ny lt boxsize then begin
print,'Box too large for input'
endif

output = intarr(nx,ny)

offset = boxsize/2
for i=-offset,offset do begin
mnx = 0 > (-i)
mxx = (nx-1) < (nx-1-i)
for j=-offset,offset do begin
mny = 0 > (-j)
mxy = (ny-1) < (ny-1-j)

if (i ne 0 or j ne 0) then begin
output(mnx:mxx,mny:mxy) = output(mnx:mxx,mny:mxy)+ $
(input(mnx:mxx,mny:mxy) eq input(mnx+i:mxx+i, mny+j:mxy
+j))
endif
endfor
endfor
return, output
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: fastest way to find the first non-zero value in an array
Next Topic: delvar, all

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

Current Time: Sun Oct 12 00:02:48 PDT 2025

Total time taken to generate the page: 1.19937 seconds