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

Home » Public Forums » archive » Need a function to multiply the elements of an array
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: Need a function to multiply the elements of an array [message #4143 is a reply to message #4065] Fri, 28 April 1995 00:00 Go to previous message
rlw is currently offline  rlw
Messages: 1
Registered: April 1995
Junior Member
In article <3nm2uk$qqq@pinot.umd.edu>, barsam@Glue.umd.edu (Barsam Marasli) writes:

|> I am looking for a routine to multiply the elements of an array.

Here is one more approach for this problem. I did some tests and found
it to be roughly the same speed as the previous approaches (using logarithms)
for short vectors (< 100 elements), but it is faster by about a factor
of 3 for long vectors. It is about 15 times faster than a direct loop
for long vectors.

function prod,x
; Compute product of elements of x. Returns result as double.
; R. White, 1995 April 28
n = n_elements(x)
y = double(x)
mm = 1.0d0
; takes about log3(n) passes through this loop
; 20 elements is about the right break point where the direct loop becomes
; fastest
while (n GT 20) do begin
mval = n MOD 3
if mval eq 1 then begin
mm = mm*y(n-1)
endif else if mval eq 2 then begin
mm = mm*y(n-1)*y(n-2)
endif
n = n/3
y = y(0:n-1)*y(n:2*n-1)*y(2*n:3*n-1)
endwhile
for i=0,n-1 do mm=mm*y(i)
return, mm
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: ARMA (was Re: Need a function to multiply the elements of an array)
Next Topic: Re: strart up file in idl

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

Current Time: Fri Oct 10 18:59:13 PDT 2025

Total time taken to generate the page: 0.72245 seconds