Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

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

Search the Archive

Re: Speed of dot product in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5277] Re: [mg5230] Speed of dot product in Mathematica
  • From: BobHanlon at aol.com
  • Date: Mon, 18 Nov 1996 02:30:24 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

You can also use

Plus @@ (a b)

If you want the dot product of portions of the factors, use only the
portions.  For example,

Take[a, {100, 1000}].Take[b, {200, 1100}]


FORWARDED MESSAGE:

Subj:  [mg5230] Speed of dot product in Mathematica
From:  carlos at mars.Colorado.EDU
To: mathgroup at smc.vnet.net
X-From: carlos at mars.Colorado.EDU (Carlos A. Felippa)
To: mathgroup at smc.vnet.net

The speed of dot products in Mathematica 2.2 depends
significantly on implementation.  For example, timing

 n=10000; a=Table[1.,{n}]; b=a;
 Print[Timing[a.b]];
 Print[Timing[s=Sum[a[[i]]*b[[i]],{i,1,n}]]]
 Print[Timing[s=0;Do[s+=a[[i]]*b[[i]],{i,1,n}]]];
 Print[Timing[s=0;For[i=0,i<=n,i++,s+=a[[i]]*b[[i]] ]]];

on a Mac 8500 gives

 {0.0666667 Second, 10000.}
 {1.48333 Second, 10000.}
 {2.38333 Second, Null}
 {3.95 Second, Null}

Is there a way to speed up the Sum form, for example using Compile, so that 
it achieves a performance similar to that of the built-in dot operator?

This is important in matrix routines where the dot product involves only
portions of rows or columns, or where the stride is not unity.

BTW, several of the LinearAlgebra Package functions (e.g. lufactor)
use the For-loop implementation.  As shown above, that has the worst
performance, being 60 times slower than the built-in operator.



  • Prev by Date: Re: Inverse of Error Function
  • Next by Date: Re: Strange Behaviour of Limits[...]
  • Previous by thread: Speed of dot product in Mathematica
  • Next by thread: Re: Speed of dot product in Mathematica