MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Why Does Repeated Dot Product Take So Long?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67966] Re: [mg67938] Why Does Repeated Dot Product Take So Long?
  • From: Gregory Lypny <gregory.lypny at videotron.ca>
  • Date: Wed, 19 Jul 2006 05:21:06 -0400 (EDT)
  • References: <25095685.1153187303323.JavaMail.root@eastrmwml07.mgt.cox.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Thank you Bob, János, Ssezi, and Carl for your thoughtful comments.

I think I found the problem.  Vector x contains a mixture of rational  
and irrational numbers.  I went back and recreated x, which is based  
on another computation, by applying the N[] function.  This reduced  
the time to compute the dot products from about 112 seconds to .06  
seconds for an even larger vectors of length 8,000!

Thanks once again, and it is always especially enlightening to see  
the different ways of arriving at an answer.

Regards,

	Gregory





On Mon, Jul 17, 2006, at 9:48 PM, Bob Hanlon wrote:

> Unless your matrices are symbolic, it should go pretty fast.
>
> $Version
>
> 5.2 for Mac OS X (June 20, 2005)
>
> n=2000;
> x=Table[Random[],{n},{3}];
> y=Table[Random[],{n},{3}];
>
> Timing[sol1=Table[x[[i]].y[[i]], {i, n}];]
>
> {0.007042 Second,Null}
>
> Timing[sol2=#[[1]].#[[2]]&/@Thread[{x,y}];]
>
> {0.028243 Second,Null}
>
> Timing[sol3=Dot@@@Thread[{x,y}];]
>
> {0.04984 Second,Null}
>
> Timing[sol4=MapThread[Dot,{x,y}];]
>
> {0.047926 Second,Null}
>
> sol1==sol2==sol3==sol4
>
> True
>
>
> Bob Hanlon
>
> ---- Gregory Lypny <gregory.lypny at videotron.ca> wrote:
>> Hello Everyone,
>>
>> x and y are both 2000 x 3 matrices.  I wanted to created a 2000 x 1
>> vector with each element equal to the dot product of the
>> corresponding rows of x and y.  So I tried this:
>>
>> Table[x[[i]].y[[i]], {i, 1, 2000}]
>>
>> It took more than two and a half minutes on my iBook G4.  Is that
>> normal?  I've done seemingly more demanding computations in Do loops
>> and Tables that are completed in a split second.  Am I doing
>> something wrong with this one?
>>
>> Regards,
>>
>> 	Gregory
>>
>


  • Prev by Date: RE: Efficient compounding of growth figures
  • Next by Date: Re: Filtering same elements from two lists
  • Previous by thread: Re: Why Does Repeated Dot Product Take So Long?
  • Next by thread: NDSolve Problems