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

Home » Public Forums » archive » Vectorizing Code
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: Vectorizing Code [message #29642 is a reply to message #29539] Fri, 01 March 2002 05:40 Go to previous messageGo to previous message
robert.dimeo is currently offline  robert.dimeo
Messages: 42
Registered: November 2001
Member
Hi Steve,

I vectorized it as follows:

u = 1+bytarr(nstate)
v = 1+bytarr(nvec)
d = u#(indgen(nvec)) - (indgen(nstate))#v
sa = 10.^2*exp(-abs(d)*dz/h)

Your way took 0.125 seconds on my pc for nstate = 500 and nvec = 120.
The vectorized way above took 0.03 seconds.

By the way, the rebin method proposed by Kenneth Bowman also took 0.03 seconds.

Hope this helps,

Rob


Steve Jones <no@email.com> wrote in message news:<270220022244527274%no@email.com>...
> Is it possible to vectorize a simple double for-loop?
>
> for i=0,nstate-1 do begin
> for j=0,nvec-1 do begin
> sa(i,j)=10.^2*exp(-abs(i-j)*dz/h)
> endfor
> endfor
>
> I tend to write a large number of such loops and my indexes have been
> steadily increasing of late... Is there a faster alternative? Thanks
> in advance
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: IDL to MATLAB binary files
Next Topic: Best way to move a window

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

Current Time: Fri Oct 10 08:57:05 PDT 2025

Total time taken to generate the page: 0.00639 seconds