Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r67938:7acb38913282 Date: 2013-11-10 20:11 -0500 http://bitbucket.org/pypy/pypy/changeset/7acb38913282/
Log: fix a numpy complex zero division case diff --git a/pypy/module/micronumpy/test/dummy_module.py b/pypy/module/micronumpy/test/dummy_module.py --- a/pypy/module/micronumpy/test/dummy_module.py +++ b/pypy/module/micronumpy/test/dummy_module.py @@ -1,6 +1,7 @@ from _numpypy.multiarray import * from _numpypy.umath import * +inf = float('inf') nan = float('nan') newaxis = None ufunc = type(sin) diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py --- a/pypy/module/micronumpy/test/test_scalar.py +++ b/pypy/module/micronumpy/test/test_scalar.py @@ -96,3 +96,20 @@ assert str(np.complex128(complex(1, float('-nan')))) == '(1+nan*j)' assert str(np.complex128(complex(1, float('inf')))) == '(1+inf*j)' assert str(np.complex128(complex(1, float('-inf')))) == '(1-inf*j)' + + def test_complex_zero_division(self): + import numpy as np + for t in [np.complex64, np.complex128]: + a = t(0.0) + b = t(1.0) + assert np.isinf(b/a) + b = t(complex(np.inf, np.inf)) + assert np.isinf(b/a) + b = t(complex(np.inf, np.nan)) + assert np.isinf(b/a) + b = t(complex(np.nan, np.inf)) + assert np.isinf(b/a) + b = t(complex(np.nan, np.nan)) + assert np.isnan(b/a) + b = t(0.) + assert np.isnan(b/a) 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 @@ -1132,7 +1132,8 @@ try: return rcomplex.c_div(v1, v2) except ZeroDivisionError: - if rcomplex.c_abs(*v1) == 0: + if rcomplex.c_abs(*v1) == 0 or \ + (rfloat.isnan(v1[0]) and rfloat.isnan(v1[1])): return rfloat.NAN, rfloat.NAN return rfloat.INFINITY, rfloat.INFINITY _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit