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

Home » Public Forums » archive » Re: for loops for total newbies
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: for loops for total newbies [message #54795 is a reply to message #54792] Fri, 13 July 2007 11:45 Go to previous messageGo to previous message
Conor is currently offline  Conor
Messages: 138
Registered: February 2007
Senior Member
I'm afraid a lot of this you might just have to come up with
yourself. It's hard (for me anyway) to vectorize everything for you
because I'm just not that familiar with your code. I don't know the
dimensions of everything, and I don't really know what you're trying
to accomplish. However, I think I can provide some hints that should
help.

First of all, why do you have a wait inside a for loop??? Even if it
doesn't cost you that much time, it still has no purpose that I can
see.

Second, remember that if an operation doesn't have to be in the for
loop, don't put it in the for loop! So in your inner-most loop you
have these two lines:

k2=(k+1+ max_cor_shift) mod max_cor_shift
k1=(k-1+ max_cor_shift) mod max_cor_shift

However the loop itself is looping over f, and the loop above it is
looping over i, neither of which appear in either of these lines. It
seems to me that these two variables should be constants inside the
loop, so you should move them out of the loop entirely. That probably
won't make a huge difference, but it will help.

Now the important part. It might be very difficult to get rid of both
for loops, but it should be pretty easy to get rid of the innermost
one. The first trick you will have to do is use the dimensions
keyword to max(). You'll want to get rid of the for loop over f, and
instead try something like this:

crtot= fltarr(sz-1,(size(cor_array))[2],(size(cor_array))[3])
crtot(0:sz-3,*,*)= cor_array(0:sz-3,*,*)

meanarr = fltarr((size(cor_array))[2])
j= findgen(1000*max_cor_shift)/1000.0
avgz= fltarr(sz-2)
fit = fltarr(sz-2, max_cor_shift*1000)

k2=(k+1+max_cor_shift) mod max_cor_shift
k1=(k-1+ max_cor_shift) mod max_cor_shift

for i = 0, (size(cor_array))[2]-1 do begin
print, i

maxcrs = max(crtot,ks,dimension=1)
a = crtot(*,i,k2)/2 + crtot(*,i,k1)/2 - maxcrs
b = crtot(*,i,k2)/2 - crtot(*,i,k1)/2 - maxcrs
c = maxcrs

fit = a*(j-k)^2 + b*(j-k) + c
kaas = max(fit, s, dimension=1)
avgz = s/(float(sz)) - 10

meanarr(i)=mean(avgz)
endfor



Now I really doubt the above code will work, but that's essentially
what you want to do. By saying: maxcrs = max(crtot,ks,dimension=1)
you are returning not just the maximum of a row, but the maximum of
every row. Then, you calculate 'a' for every row, 'b' for every row,
'c' for every row, and 'fit' for every row. I'm not sure if I quite
did it right though, because I'm not very sure what the dimensions of
fit are, and whether or not everything matches up. You'll probably
have to adjust the code accordingly. Same with the calculation of
kaas and avgz. Hopefully though, this will give you an idea of what
needs to be done.

Actually, considering that very little is done in the outer loop, you
might be able to get rid of it as well and do the whole thing loop-
less. I'm not really sure though, you might have to play around with
that yourself.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: fortran feasability
Next Topic: Re: fortran feasability

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

Current Time: Fri Oct 10 02:33:17 PDT 2025

Total time taken to generate the page: 1.44613 seconds