Re: Avoiding FOR loops (version googleplex.infinity) [message #59779 is a reply to message #59696] |
Fri, 11 April 2008 00:52   |
weitkamp
Messages: 33 Registered: October 1998
|
Member |
|
|
Gaurav,
I suggest a solution that is essentially identical to yours, with the
sole difference that I think the use of WHERE is superfluous because
it is much easier to use only its argument. (Using WHERE in cases
where its argument alone is much easier to handle is actually one of
the most frequent programming flaws that I have seen in this group,
and I was tempted to submit to David Fanning's recent survey.) Below
is the code I propose.
Cheers,
Timm
count = 0B * image ; This will contain the result
FOR ix = -width/2, width/2 DO BEGIN
FOR iy = -height/2, height/2 DO BEGIN
IF (ix NE 0) OR (iy NE 0) THEN BEGIN
shiftedImage = SHIFT(image, ix, iy)
count = count + (shiftedImage EQ image)
ENDIF
ENDFOR
ENDFOR
END
Gaurav a écrit :
> Dear Tom,
> The trouble is that coming into this group, I always feel I am a
> novice with IDL programming and algorithm designing. Hence, my
> reluctance in asserting my views.
>
> For example, my perusal of IDL help documents has led me to the belief
> that creating temporary arrays help hasten things up while you mention
> something to the contrary. I shall definitely look this up and would
> appreciate pointers in the right direction.
>
> As far as your code generating a result different from mine at the
> edges is concerned, that-of course-is true. In that respect, my code
> produces the same effect as the normal FOR loop, and this has been
> verified.
>
> And as for the bug in my code, I definitely stand corrected for my
> code would fail if all the array elements in the kernel are different.
> Thanks indeed for pointing it out to me.
>
> Thanks indeed,
> Gaurav
|
|
|