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

Tim Hochberg tim.hochberg at cox.net
Fri Feb 17 11:14:12 EST 2006


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.

-tim





More information about the NumPy-Discussion mailing list