The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Inactive » 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,761
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}];

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.

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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.