[Numpy-discussion] Enhancing dot()
wbaxter at gmail.com
Fri Jul 7 01:44:14 CDT 2006
On 7/7/06, Tim Hochberg <tim.hochberg at cox.net> wrote:
> > The funny thing is that having a dot(a,b,c,...) would lead to the
> > exact same kind of hidden performance problems you're arguing against.
> Not exactly arguing -- this isn't why I don't like H and friends -- just
> noting that this is one of the traps that people are likely to fall into
> when transferring equations to code.
There's a strong argument to be made that the whole design of most array
math packages is flawed and leads to inefficient code. The classic example
is something like:
A = B + C - 2*D
where all the matrices are 2million x 2million. I think for numpy that
would basically do:
tmp = B+C
tmp2 = 2*D
tmp3 = tmp - tmp2
A = tmp3
Allocating three huge tmp variables and probably doing an extra copy or two
in there, when the best thing to do would be more like:
A = D
A *= -2
A += C
A += B
Or something like that. The point is that you give up any notion of having
optimal code the minute you start using something like numpy. And you do so
happily for the ability to get stuff done faster and have nicer looking,
more readable code in the end. When everything works, that's when you hit
the "go fast button" if you even really need to.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion