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

Home » Public Forums » archive » Re: Was: Index... Now: Vectorize, huh?
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: Was: Index... Now: Vectorize, huh? [message #24610 is a reply to message #24606] Thu, 05 April 2001 13:13 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Pavel A. Romashkin" <pavel.romashkin@noaa.gov> writes:

> Craig and Med,
>
> I appreciate it! This is exactly what I needed. My problem is the lack
> of matrix operations knowledge. Craig's generic solution is exactly what
> I expected to see from Craig :-)

You're welcome.

> By the way. We all are big on vectorizing things in IDL. But look at this:
>
> IDL> a = test(2000)
> 1.4968959
> IDL> a = test(2000, /v)
> 3.2976190
>
> where TEST is below. I don't even mention that /VEC causes extremely
> high memory usage and gets totally out of hand on my system if S > 5000
> or so.

Yes, you can go too far overboard with vectorization. Part of the
problem is that you coded your vectorized path inefficiently. However
I think that when your matrices start to get huge, then the benefits
of vectorization can actually degrade, especially when you need to
artificially promote vectors into matrices as you are doing.

I've always said that if you can vectorize the inner loop of your
operation then you are usually fine. Pavel, you actually did that in
your *non*-vectorized case. :-)

A new version of TEST improves things slightly, but doesn't tip the
scales. w/ your version I get 1.6 and 3.8 s. With my version I get
1.5 and 2.7 s.

Craig

pro test, s, vec=vec
start = systime(1)
x = findgen(s)
if keyword_set(vec) then begin
a = rebin(x,s,s)^2
a = sqrt(transpose(a) + a)
endif else begin
a = fltarr(s, s)
for i = 0, s-1 do begin
a[0, i] = sqrt(x^2 + i^2.)
endfor
endelse
print, systime(1) - start
end



--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Header File *.h?
Next Topic: Re: Cant find functions in lib

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

Current Time: Sat Oct 11 16:55:38 PDT 2025

Total time taken to generate the page: 0.39976 seconds