Author: mattip <[email protected]>
Branch: numpy-fixes
Changeset: r76927:43ccc6f8802a
Date: 2015-04-24 17:20 +0300
http://bitbucket.org/pypy/pypy/changeset/43ccc6f8802a/
Log: test for nan in complex.sign
diff --git a/pypy/module/micronumpy/test/test_complex.py
b/pypy/module/micronumpy/test/test_complex.py
--- a/pypy/module/micronumpy/test/test_complex.py
+++ b/pypy/module/micronumpy/test/test_complex.py
@@ -331,6 +331,12 @@
complex(float('nan'), 0)], dtype=complex)) == \
[False, True, True, False, False]).all()
+ def test_sign_for_complex_nan(self):
+ from numpy import array, nan, sign, isnan
+ C = array([nan], dtype=complex)
+ res = sign(C)
+ assert isnan(res.real)
+ assert res.imag == 0+0j
def test_square(self):
from numpy import square
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1347,15 +1347,17 @@
sign of complex number could be either the point closest to the unit
circle
or {-1,0,1}, for compatability with numpy we choose the latter
'''
+ if rfloat.isnan(v[0]) or rfloat.isnan(v[1]):
+ return rfloat.NAN, 0
if v[0] == 0.0:
if v[1] == 0:
- return 0,0
+ return 0, 0
if v[1] > 0:
- return 1,0
- return -1,0
+ return 1, 0
+ return -1, 0
if v[0] > 0:
- return 1,0
- return -1,0
+ return 1, 0
+ return -1, 0
def fmax(self, v1, v2):
if self.ge(v1, v2) or self.isnan(v2):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit