[pypy-commit] pypy numpy-single-jitdriver: expose logical ops, not lazy yet.

fijal noreply at buildbot.pypy.org
Fri Feb 3 09:53:13 CET 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: numpy-single-jitdriver
Changeset: r52049:0d51aa842503
Date: 2012-02-03 10:52 +0200
http://bitbucket.org/pypy/pypy/changeset/0d51aa842503/

Log:	expose logical ops, not lazy yet.

diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -98,6 +98,10 @@
         ('bitwise_not', 'invert'),
         ('isnan', 'isnan'),
         ('isinf', 'isinf'),
+        ('logical_and', 'logical_and'),
+        ('logical_xor', 'logical_xor'),
+        ('logical_not', 'logical_not'),
+        ('logical_or', 'logical_or'),
     ]:
         interpleveldefs[exposed] = "interp_ufuncs.get(space).%s" % impl
 
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
@@ -404,6 +404,11 @@
             ("isnan", "isnan", 1, {"bool_result": True}),
             ("isinf", "isinf", 1, {"bool_result": True}),
 
+            ('logical_and', 'logical_and', 2, {'comparison_func': True}),
+            ('logical_or', 'logical_or', 2, {'comparison_func': True}),
+            ('logical_xor', 'logical_xor', 2, {'comparison_func': True}),
+            ('logical_not', 'logical_not', 1, {'bool_result': True}),
+
             ("maximum", "max", 2),
             ("minimum", "min", 2),
 
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
@@ -433,3 +433,14 @@
         assert (isnan(array([0.2, float('inf'), float('nan')])) == [False, False, True]).all()
         assert (isinf(array([0.2, float('inf'), float('nan')])) == [False, True, False]).all()
         assert isinf(array([0.2])).dtype.kind == 'b'
+
+    def test_logical_ops(self):
+        from _numpypy import logical_and, logical_or, logical_xor, logical_not
+
+        assert (logical_and([True, False , True, True], [1, 1, 3, 0])
+                == [True, False, True, False]).all()
+        assert (logical_or([True, False, True, False], [1, 2, 0, 0])
+                == [True, True, True, False]).all()
+        assert (logical_xor([True, False, True, False], [1, 2, 0, 0])
+                == [False, True, True, False]).all()
+        assert (logical_not([True, False]) == [False, True]).all()
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
@@ -181,6 +181,22 @@
     def ge(self, v1, v2):
         return v1 >= v2
 
+    @raw_binary_op
+    def logical_and(self, v1, v2):
+        return bool(v1) and bool(v2)
+
+    @raw_binary_op
+    def logical_or(self, v1, v2):
+        return bool(v1) or bool(v2)
+
+    @raw_unary_op
+    def logical_not(self, v):
+        return not bool(v)
+
+    @raw_binary_op
+    def logical_xor(self, v1, v2):
+        return bool(v1) ^ bool(v2)
+
     def bool(self, v):
         return bool(self.for_computation(self.unbox(v)))
 


More information about the pypy-commit mailing list