Should numpy.sqrt(-1) return 1j rather than nan?

pearu at pearu at
Wed Oct 11 18:13:16 CDT 2006

On Wed, 11 Oct 2006, Travis Oliphant wrote:

> On the other hand requiring all calls to numpy.sqrt to go through an 
> "argument-checking" wrapper is a bad idea as it will slow down other uses.

Interestingly, in worst cases numpy.sqrt is approximately ~3 times slower
than scipy.sqrt on negative input but ~2 times faster on positive input:

In [47]: pos_input = numpy.arange(1,100,0.001)

In [48]: %timeit -n 1000 b=numpy.sqrt(pos_input)
1000 loops, best of 3: 4.68 ms per loop

In [49]: %timeit -n 1000 b=scipy.sqrt(pos_input)
1000 loops, best of 3: 10 ms per loop

In [50]: neg_input = -pos_input

In [52]: %timeit -n 1000 b=numpy.sqrt(neg_input)
1000 loops, best of 3: 99.3 ms per loop

In [53]: %timeit -n 1000 b=scipy.sqrt(neg_input)
1000 loops, best of 3: 29.2 ms per loop

nan's are making things really slow,

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list