[pypy-commit] pypy numpypy-complex2: add 'allow_complex' to find_unaryop_result_dtype

mattip noreply at buildbot.pypy.org
Thu Sep 13 00:14:16 CEST 2012


Author: mattip <matti.picus at gmail.com>
Branch: numpypy-complex2
Changeset: r57305:c1db76d1853b
Date: 2012-09-12 22:49 +0300
http://bitbucket.org/pypy/pypy/changeset/c1db76d1853b/

Log:	add 'allow_complex' to find_unaryop_result_dtype

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
@@ -301,16 +301,16 @@
     _COMPONENTS_BOX = W_Float32Box
 
     def descr_get_real(self, space):
-        dtype = W_Float64Box._get_dtype(space)
+        dtype = W_Float32Box._get_dtype(space)
         box = self.convert_real_to(dtype)
-        assert isinstance(box, W_Float64Box)
-        return space.wrap(box.value)
+        assert isinstance(box, W_Float32Box)
+        return space.wrap(box)
 
     def descr_get_imag(self, space):
-        dtype = W_Float64Box._get_dtype(space)
+        dtype = W_Float32Box._get_dtype(space)
         box = self.convert_imag_to(dtype)
-        assert isinstance(box, W_Float64Box)
-        return space.wrap(box.value)
+        assert isinstance(box, W_Float32Box)
+        return space.wrap(box)
 
 class W_Complex128Box(ComplexBox, W_ComplexFloatingBox):
     descr__new__, _get_dtype = new_dtype_getter("complex128")
@@ -320,13 +320,13 @@
         dtype = self._COMPONENTS_BOX._get_dtype(space)
         box = self.convert_real_to(dtype)
         assert isinstance(box, self._COMPONENTS_BOX)
-        return space.wrap(box.value)
+        return space.wrap(box)
 
     def descr_get_imag(self, space):
         dtype = self._COMPONENTS_BOX._get_dtype(space)
         box = self.convert_imag_to(dtype)
         assert isinstance(box, self._COMPONENTS_BOX)
-        return space.wrap(box.value)
+        return space.wrap(box)
 
     
 
diff --git a/pypy/module/micronumpy/interp_ufuncs.py b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -234,7 +234,8 @@
         calc_dtype = find_unaryop_result_dtype(space,
                                   w_obj.get_dtype(),
                                   promote_to_float=self.promote_to_float,
-                                  promote_bools=self.promote_bools)
+                                  promote_bools=self.promote_bools,
+                                  allow_complex=self.allow_complex)
         if out is not None:
             if not isinstance(out, W_NDimArray):
                 raise OperationError(space.w_TypeError, space.wrap(
@@ -299,7 +300,7 @@
             )
         if space.is_w(w_out, space.w_None) or w_out is None:
             out = None
-        elif not isinstance(w_out, BaseArray):
+        elif not isinstance(w_out, W_NDimArray):
             raise OperationError(space.w_TypeError, space.wrap(
                     'output must be an array'))
         else:
@@ -395,9 +396,11 @@
 
 
 def find_unaryop_result_dtype(space, dt, promote_to_float=False,
-    promote_bools=False, promote_to_largest=False):
+    promote_bools=False, promote_to_largest=False, allow_complex=True):
     if promote_bools and (dt.kind == interp_dtype.BOOLLTR):
         return interp_dtype.get_dtype_cache(space).w_int8dtype
+    if not allow_complex and (dt.is_complex_type()):
+        raise OperationError(space.w_TypeError, space.wrap("Unsupported types"))
     if promote_to_float:
         if dt.kind == interp_dtype.FLOATINGLTR:
             return dt
@@ -516,7 +519,8 @@
             ("maximum", "max", 2),
             ("minimum", "min", 2),
 
-            ("copysign", "copysign", 2, {"promote_to_float": True}),
+            ("copysign", "copysign", 2, {"promote_to_float": True,
+                                         "allow_complex": False}),
 
             ("positive", "pos", 1),
             ("negative", "neg", 1),
@@ -526,7 +530,8 @@
             ("reciprocal", "reciprocal", 1),
             ("conjugate", "conj", 1),
 
-            ("fabs", "fabs", 1, {"promote_to_float": True}),
+            ("fabs", "fabs", 1, {"promote_to_float": True,
+                                 "allow_complex": False}),
             ("fmax", "fmax", 2, {"promote_to_float": True}),
             ("fmin", "fmin", 2, {"promote_to_float": True}),
             ("fmod", "fmod", 2, {"promote_to_float": True, 'allow_complex': False}),
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -449,8 +449,7 @@
             
         real, imag, should = (1e100, 3e66, '(1e+100+3e+66j)')
         c128 = numpy.complex128(complex(real, imag))
-        assert type(c128.real) is type(c128.imag)
-        assert type(c128.real) is numpy.float64
+        assert type(c128.real) is type(c128.imag) is numpy.float64
         assert c128.real == real
         assert c128.imag == imag
         assert repr(c128) == should
@@ -498,6 +497,7 @@
 
     def test_int(self):
         from _numpypy import int32, int64, int_
+        import sys
         assert issubclass(int_, int)
         if sys.maxint == (1<<31) - 1:
             assert issubclass(int32, int)
@@ -508,6 +508,7 @@
 
     def test_various_types(self):
         import _numpypy as numpy
+        import sys
 
         assert numpy.int16 is numpy.short
         assert numpy.int8 is numpy.byte


More information about the pypy-commit mailing list