Re: Speed of dot product in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg5350] Re: [mg5230] Speed of dot product in Mathematica
- From: Daniel Lichtblau <danl>
- Date: Wed, 27 Nov 1996 01:48:03 -0500
- Organization: wolfram.com
- Sender: owner-wri-mathgroup at wolfram.com
[Steve: Please junk my last reply to this thread. C Felippa pointed out
in e-mail that it is quite inefficient.]
carlos at 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 at wolfram.com