[pypy-commit] pypy numpypy-complex2: dtype.real, dtype.imag return float values

mattip noreply at buildbot.pypy.org
Thu Sep 6 23:22:59 CEST 2012


Author: mattip <matti.picus at gmail.com>
Branch: numpypy-complex2
Changeset: r57197:4b6f2eae6d4e
Date: 2012-09-07 00:21 +0300
http://bitbucket.org/pypy/pypy/changeset/4b6f2eae6d4e/

Log:	dtype.real, dtype.imag return float values

diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -295,15 +295,15 @@
     _COMPONENTS_BOX = W_Float32Box
 
     def descr_get_real(self, space):
-        dtype = self._COMPONENTS_BOX._get_dtype(space)
+        dtype = W_Float64Box._get_dtype(space)
         box = self.convert_real_to(dtype)
-        assert isinstance(box, self._COMPONENTS_BOX)
+        assert isinstance(box, W_Float64Box)
         return space.wrap(box.value)
 
     def descr_get_imag(self, space):
-        dtype = self._COMPONENTS_BOX._get_dtype(space)
+        dtype = W_Float64Box._get_dtype(space)
         box = self.convert_imag_to(dtype)
-        assert isinstance(box, self._COMPONENTS_BOX)
+        assert isinstance(box, W_Float64Box)
         return space.wrap(box.value)
 
 class W_Complex128Box(ComplexBox, W_ComplexFloatingBox):
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -931,7 +931,7 @@
         from _numpypy import (equal, not_equal, greater, greater_equal, less,
                 less_equal)
 
-        for complex_ in complex128, complex64:
+        for complex_ in complex64, complex128:
 
             O = complex(0, 0)
             c0 = complex_(complex(2.5, 0))
@@ -985,9 +985,9 @@
             raises (TypeError, fmod, c0, 3) 
             inf_c = complex_(complex(float('inf'), 0.))
             assert repr(abs(inf_c)) == 'inf'
-            assert repr(abs(n)) == 'nan'
+            assert repr(abs(complex(float('nan'), float('nan')))) == 'nan'
 
-            assert False, 'untested: copysign, reciprocal, sign, floor_div, ' + \
+        assert False, 'untested: copysign, reciprocal, sign, floor_div, ' + \
                      'signbit, fabs, fmax, fmin, floor, ceil, trunc, ' + \
                      'exp2, expm1, isnan, isinf, isneginf, isposinf, ' + \
                      'isfinite, radians, degrees, log2, log1p, ' + \
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
@@ -1017,7 +1017,9 @@
         try:
             return rcomplex.c_div(v1, v2)
         except ZeroDivisionError:
-            return rfloat.NAN, rfloat.NAN
+            if rcomplex.c_abs(*v1) == 0:
+                return rfloat.NAN, rfloat.NAN
+            return rfloat.INFINITY, rfloat.INFINITY
 
 
 


More information about the pypy-commit mailing list