Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Daniel Lichtblau Posts: 1,761 Registered: 12/7/04
Re: [mg5230] Speed of dot product in Mathematica
Posted: Nov 27, 1996 1:33 AM

in e-mail that it is quite inefficient.]

>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