[Numpy-discussion] optimizing power() for complex and real cases

David M. Cooke cookedm at physics.mcmaster.ca
Fri Feb 17 11:31:05 CST 2006

Tim Hochberg <tim.hochberg at cox.net> writes:

> Here's a little progress report: I now have A**2 running as fast as
> square(A). This is done by special casing stuff in array_power so that
> A**2 acutally calls square(A) instead of going through power(A,2).
> Things still need a bunch of cleaning up (in fact right now A**1
> segfaults, but I know why and it should be an easy fix). However, I
> think I've discovered why you couldn't get your special cased power to
> run as fast for A**2 as square(A) or A*A. It appears that the overhead
> of creating a new array object from the integer 2 is the bottleneck. I
> was running into the same mysterious overhead, even when dispatching
> from array_power, until I special cased on PyInt to avoid the array
> creation in that case.

Hmm, if that's true about the overhead, that'll hit all computations
of the type op(x, <some scalar>). Something to look at. That ufunc code
for casting the arguments is pretty big and hairy, so I'm not going to
look at right now :-)

|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca

More information about the Numpy-discussion mailing list