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

Home » Public Forums » archive » A more efficient way of multiplying this
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: A more efficient way of multiplying this [message #91582 is a reply to message #91581] Sun, 02 August 2015 06:14 Go to previous messageGo to previous message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
Hello,

I modified Nikola's Code a little (see below). First I excluded the
creation of the arrays a and b from the time measurement. Second I
added the Reform/Rebin method. You can find a lot of discussions in
other threads of this group and in the internet. (Thanks to JD Smith
and David Fanning.)

Here are my results:

IDL> .run multiply_arrays_example
% Compiled module: $MAIN$.
Slow Loop: 7.8099990
Fast Loop: 0.48500013
"# operator": 0.31200004
reform/rebin: 0.14099979

and here is the file multiply_arrays_example.pro:

a = randomu(seed,3)
b = RANDOMU(seed, 150, 3)

seconds0 = SYSTIME(1)
for k=0,9999 do begin ; "Slow Loop" (scaled by 10)
c1 = FLTARR(150, 3)
FOR i = 0, 2 DO FOR j = 0, 149 DO c1[j, i] = a[i]*b[j, i]
end
seconds1 = SYSTIME(1)

for k=0,99999 do begin ; "Fast Loop"
c2 = FLTARR(150, 3)
FOR i = 0, 2 DO c2[*, i] = a[i]*b[*, i]
end
seconds2= SYSTIME(1)

for k=0,99999 do begin ; "# operator"
aa = (FLTARR(150)+1)#a
c3 = aa*b
end
seconds3 = SYSTIME(1)

for k=0,99999 do begin ; "reform/rebin"
c4 = rebin(reform(a,1,3),150,3,/sample)*b
end
seconds4 = SYSTIME(1)

print, 'Slow Loop: ', (seconds1-seconds0)*10
if array_equal(c2,c1) then print, 'Fast Loop: ', seconds2-seconds1
if array_equal(c3,c1) then print, '"# operator":', seconds3-seconds2
if array_equal(c4,c1) then print, 'reform/rebin:', seconds4-seconds3

end ; end of file multiply_arrays_example.pro

Cheers, Heinz
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Help Doing HDF(-EOS) to Multi-layer GeoTIFF Conversion with IDL
Next Topic: IDL-69024 bug fixed in v8.4?

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

Current Time: Wed Oct 08 16:16:16 PDT 2025

Total time taken to generate the page: 0.00488 seconds