[Numpy-discussion] optimization of arr**-2

Sebastian Haase haase at msg.ucsf.edu
Sun Jul 15 04:48:50 EDT 2007


Hi,
I compared for a 256x256 float32  normal-noise (x0=100,sigma=1) array
the times to do
1./ (a*a)
vs.
a**-2

>>> U.timeIt('1./(a*a)', 1000)
(0.00090877471871, 0.00939644563778, 0.00120674694689, 0.000687777554628)
>>> U.timeIt('a**-2', 1000)
(0.00876591857354, 0.0263829620803, 0.00952076311375, 0.00173311803255)

The numbers are min,max, mean, stddev over thousand runs.
N.__version == 1.0.1

The slowdown is almost 10 fold.  Similar tests for **-1, and **2  show
that the corresponding times are identical - i.e. those cases are
optimized to not call the pow routine.

Can this be fixed for the **-2 case ?

Thanks,
Sebastian Haase



More information about the NumPy-Discussion mailing list