[pypy-commit] pypy numpypy-complex2: test logical ops, does not translate

mattip noreply at buildbot.pypy.org
Tue Sep 25 12:50:10 CEST 2012


Author: mattip <matti.picus at gmail.com>
Branch: numpypy-complex2
Changeset: r57560:f48afe9e685b
Date: 2012-09-25 11:57 +0200
http://bitbucket.org/pypy/pypy/changeset/f48afe9e685b/

Log:	test logical ops, does not translate

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
@@ -526,8 +526,8 @@
             ('logical_xor', 'logical_xor', 2, {'comparison_func': True}),
             ('logical_not', 'logical_not', 1, {'bool_result': True}),
 
-            ("maximum", "max", 2),
-            ("minimum", "min", 2),
+            ("maximum", "max", 2, {"allow_complex": False}),
+            ("minimum", "min", 2, {"allow_complex": False}),
 
             ("copysign", "copysign", 2, {"promote_to_float": True,
                                          "allow_complex": False}),
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
@@ -262,7 +262,8 @@
 
     def test_not_complex(self):
         from _numpypy import (radians, deg2rad, degrees, rad2deg,
-                  isneginf, isposinf, logaddexp, logaddexp2, fmod)
+                  isneginf, isposinf, logaddexp, logaddexp2, fmod,
+                  max, min)
         raises(TypeError, radians, complex(90,90))
         raises(TypeError, deg2rad, complex(90,90))
         raises(TypeError, degrees, complex(90,90))
@@ -272,6 +273,8 @@
         raises(TypeError, logaddexp, complex(1, 1), complex(3, 3))
         raises(TypeError, logaddexp2, complex(1, 1), complex(3, 3))
         raises (TypeError, fmod, complex(90,90), 3) 
+        raises (TypeError, min, complex(90,90), 3) 
+        raises (TypeError, max, complex(90,90), 3) 
 
     def test_isnan_isinf(self):
         from _numpypy import isnan, isinf, array
@@ -414,6 +417,20 @@
         if got_err:
             raise AssertionError('Errors were printed to stdout')
 
+    def test_logical_ops(self):
+        from _numpypy import logical_and, logical_or, logical_xor, logical_not
+
+        c1 = complex(1, 1)
+        c3 = complex(3, 0)
+        c0 = complex(0, 0)
+        assert (logical_and([True, False , True, True], [c1, c1, c3, c0])
+                == [True, False, True, False]).all()
+        assert (logical_or([True, False, True, False], [c1, c3, c0, c0])
+                == [True, True, True, False]).all()
+        assert (logical_xor([True, False, True, False], [c1, c3, c0, c0])
+                == [False, True, True, False]).all()
+        assert (logical_not([c1, c0]) == [False, True]).all()
+
     def test_basic(self):
         from _numpypy import (complex128, complex64, add,
             subtract as sub, multiply, divide, negative, abs, 
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
@@ -55,7 +55,7 @@
     def dispatcher(self, v):
         from pypy.module.micronumpy.interp_boxes import W_GenericBox
         assert isinstance(v, W_GenericBox)
-        return self.RealBoxType(
+        return self.box_component(
             func(
                 self,
                 self.for_computation(self.unbox(v))
@@ -991,6 +991,11 @@
             rffi.cast(self._COMPONENTS_T, value),
             rffi.cast(self._COMPONENTS_T, 0.0))
 
+    @specialize.argtype(1)
+    def box_component(self, value):
+        return self.ComponentBoxType(
+            rffi.cast(self._COMPONENTS_T, value))
+
     @specialize.argtype(1, 2)
     def box_complex(self, real, imag):
         return self.BoxType(
@@ -1112,31 +1117,22 @@
 
     @raw_binary_op
     def logical_and(self, v1, v2):
-        return bool(v1) and bool(v2)
+        return self.bool(v1) and self.bool(v2)
 
     @raw_binary_op
     def logical_or(self, v1, v2):
-        return bool(v1) or bool(v2)
+        return self.bool(v1) or self.bool(v2)
 
     @raw_unary_op
     def logical_not(self, v):
-        return not bool(v)
+        return not self.bool(v)
 
     @raw_binary_op
     def logical_xor(self, v1, v2):
-        return bool(v1) ^ bool(v2)
+        return self.bool(v1) ^ self.bool(v2)
 
     def bool(self, v):
-        return bool(self.for_computation(self.unbox(v)))
-
-    @simple_binary_op
-    def max(self, v1, v2):
-        return max(v1, v2)
-
-    @simple_binary_op
-    def min(self, v1, v2):
-        return min(v1, v2)
-
+        return bool(v[0]) or bool(v[1])
 
     @complex_binary_op
     def floordiv(self, v1, v2):
@@ -1244,7 +1240,7 @@
     def exp(self, v):
         if math.isinf(v[1]):
             if math.isinf(v[0]):
-                if v[0]<0:
+                if v[0] < 0:
                     return 0., 0.
                 return rfloat.INFINITY, rfloat.NAN
             elif (isfinite(v[0]) or \
@@ -1253,7 +1249,7 @@
         try:
             return rcomplex.c_exp(*v)
         except OverflowError:
-            if v[1]==0:
+            if v[1] == 0:
                 return rfloat.INFINITY, 0.0
             return rfloat.INFINITY, rfloat.NAN
 
@@ -1272,7 +1268,7 @@
 	# to implement seterr
         if math.isinf(v[1]):
             if math.isinf(v[0]):
-                if v[0]<0:
+                if v[0] < 0:
                     return -1., 0.
                 return rfloat.NAN, rfloat.NAN
             elif (isfinite(v[0]) or \
@@ -1283,7 +1279,7 @@
 	    res = (res[0]-1, res[1])
 	    return res
         except OverflowError:
-            if v[1]==0:
+            if v[1] == 0:
                 return rfloat.INFINITY, 0.0
             return rfloat.INFINITY, rfloat.NAN
 
@@ -1325,7 +1321,7 @@
 
     @complex_unary_op
     def arctan(self, v):
-        if v[0]==0 and (v[1]==1 or v[1] == -1):
+        if v[0] == 0 and (v[1] == 1 or v[1] == -1):
             #This is the place to print a "runtime warning"
             return rfloat.NAN, math.copysign(rfloat.INFINITY, v[1])
         return rcomplex.c_atan(*v)
@@ -1438,7 +1434,7 @@
     @complex_unary_op
     def log1p(self, v):
         try:
-            return rcomplex.c_log(v[0]+1, v[1])
+            return rcomplex.c_log(v[0] + 1, v[1])
         except OverflowError:
             return -rfloat.INFINITY, 0
         except ValueError:
@@ -1450,7 +1446,7 @@
     T = rffi.CHAR
     _COMPONENTS_T = rffi.FLOAT
     BoxType = interp_boxes.W_Complex64Box
-    RealBoxType = interp_boxes.W_Float32Box
+    ComponentBoxType = interp_boxes.W_Float32Box
 
 
 
@@ -1462,7 +1458,7 @@
     T = rffi.CHAR
     _COMPONENTS_T = rffi.DOUBLE
     BoxType = interp_boxes.W_Complex128Box
-    RealBoxType = interp_boxes.W_Float64Box
+    ComponentBoxType = interp_boxes.W_Float64Box
 
 
 NonNativeComplex128 = Complex128
diff --git a/pypy/rlib/rcomplex.py b/pypy/rlib/rcomplex.py
--- a/pypy/rlib/rcomplex.py
+++ b/pypy/rlib/rcomplex.py
@@ -68,7 +68,7 @@
 def c_pow(x, y):
     (r1, i1), (r2, i2) = x, y
     if i1 == 0 and i2 == 0 and r1>=0:
-        rr = pow(r1, r2)
+        rr = math.pow(r1, r2)
         ir = 0.
     elif r2 == 0.0 and i2 == 0.0:
         rr, ir = 1, 0


More information about the pypy-commit mailing list