Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: [mg5230] Speed of dot product in Mathematica
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Daniel Lichtblau

Posts: 1,756
Registered: 12/7/04
Re: [mg5230] Speed of dot product in Mathematica
Posted: Nov 27, 1996 1:33 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

[Steve: Please junk my last reply to this thread. C Felippa pointed out
in e-mail that it is quite inefficient.]

carlos@mars.Colorado.EDU (Carlos A. Felippa) writes:

>However, the dot product cannot always be done using unit strides
>in both arrays, and use of Sum, Do or For exert big speed penalties.
>To overcome that problem I once tried the form
>
> Take [list, {from,to,step}]
>
>but that was rejected as illegal. It seems an unreasonable
>restriction for the Take function.



One can do Table[list[[j]], {j,from,to,step}], but this is also not
terribly efficient (thanks to C. Falippa for pointing this out to me in
e-mail). A better method, shown to me by Michael Trott of WRI, is to use
Part or Extract. For example, using Part one does it as below.

indices = Table[j, {j,from,to,step}];
list[[indices]]

This is still a bit slow compared to Take; for the example below I found
Take to be nearly 3x faster.


aa = Table[j, {j,1,50000}];
Timing[b1 = Take[aa, {1000,49000}];]
indices = Table[j, {j,1000,49000}];
Timing[b2 = aa[[indices]];]


We will look into the suggestions to extend Take/Drop, and also look
into the possibility of allowing dot products with non-unit steps.


Daniel Lichtblau
Wolfram Research, Inc.
danl@wolfram.com







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.