Should numpy.sqrt(-1) return 1j rather than nan?
Travis Oliphant
oliphant at ee.byu.edu
Wed Oct 11 18:24:35 CDT 2006
pearu at cens.ioc.ee wrote:
>
>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
>
>
This is the one that concerns me. Slowing everybody down who knows they
have positive values just for people that don't seems problematic.
>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,
>
>
Yeah, they do. This actually makes the case for masked arrays, rather
than using NAN's.
-Travis
-------------------------------------------------------------------------
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
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
More information about the Numpy-discussion
mailing list