[pypy-commit] pypy default: added xor in a few places

alex_gaynor noreply at buildbot.pypy.org
Thu Feb 9 15:44:26 CET 2012


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r52296:0792068a39d9
Date: 2012-02-09 09:44 -0500
http://bitbucket.org/pypy/pypy/changeset/0792068a39d9/

Log:	added xor in a few places

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
@@ -106,6 +106,7 @@
     descr_rrshift = _binop_right_impl("right_shift")
     descr_rand = _binop_right_impl("bitwise_and")
     descr_ror = _binop_right_impl("bitwise_or")
+    descr_rxor = _binop_right_impl("bitwise_xor")
 
     descr_pos = _unaryop_impl("positive")
     descr_neg = _unaryop_impl("negative")
@@ -222,6 +223,7 @@
     __rrshift__ = interp2app(W_GenericBox.descr_rrshift),
     __rand__ = interp2app(W_GenericBox.descr_rand),
     __ror__ = interp2app(W_GenericBox.descr_ror),
+    __rxor__ = interp2app(W_GenericBox.descr_rxor),
 
     __eq__ = interp2app(W_GenericBox.descr_eq),
     __ne__ = interp2app(W_GenericBox.descr_ne),
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -105,6 +105,9 @@
     descr_pow = _binop_impl("power")
     descr_lshift = _binop_impl("left_shift")
     descr_rshift = _binop_impl("right_shift")
+    descr_and = _binop_impl("bitwise_and")
+    descr_or = _binop_impl("bitwise_or")
+    descr_xor = _binop_impl("bitwise_xor")
 
     descr_eq = _binop_impl("equal")
     descr_ne = _binop_impl("not_equal")
@@ -113,9 +116,6 @@
     descr_gt = _binop_impl("greater")
     descr_ge = _binop_impl("greater_equal")
 
-    descr_and = _binop_impl("bitwise_and")
-    descr_or = _binop_impl("bitwise_or")
-
     def descr_divmod(self, space, w_other):
         w_quotient = self.descr_div(space, w_other)
         w_remainder = self.descr_mod(space, w_other)
@@ -138,9 +138,9 @@
     descr_rpow = _binop_right_impl("power")
     descr_rlshift = _binop_right_impl("left_shift")
     descr_rrshift = _binop_right_impl("right_shift")
-
     descr_rand = _binop_right_impl("bitwise_and")
     descr_ror = _binop_right_impl("bitwise_or")
+    descr_rxor = _binop_right_impl("bitwise_xor")
 
     def descr_rdivmod(self, space, w_other):
         w_quotient = self.descr_rdiv(space, w_other)
@@ -1256,9 +1256,9 @@
     __pow__ = interp2app(BaseArray.descr_pow),
     __lshift__ = interp2app(BaseArray.descr_lshift),
     __rshift__ = interp2app(BaseArray.descr_rshift),
-
     __and__ = interp2app(BaseArray.descr_and),
     __or__ = interp2app(BaseArray.descr_or),
+    __xor__ = interp2app(BaseArray.descr_xor),
 
     __radd__ = interp2app(BaseArray.descr_radd),
     __rsub__ = interp2app(BaseArray.descr_rsub),
@@ -1269,9 +1269,9 @@
     __rpow__ = interp2app(BaseArray.descr_rpow),
     __rlshift__ = interp2app(BaseArray.descr_rlshift),
     __rrshift__ = interp2app(BaseArray.descr_rrshift),
-
     __rand__ = interp2app(BaseArray.descr_rand),
     __ror__ = interp2app(BaseArray.descr_ror),
+    __rxor__ = interp2app(BaseArray.descr_rxor),
 
     __eq__ = interp2app(BaseArray.descr_eq),
     __ne__ = interp2app(BaseArray.descr_ne),
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
@@ -423,6 +423,7 @@
         assert 2 | int_(1) == int_(3)
         assert int_(3) ^ int_(5) == int_(6)
         assert True_ ^ False_ is True_
+        assert 5 ^ int_(3) == int_(6)
 
         assert +int_(3) == int_(3)
         assert ~int_(3) == int_(-4)
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -734,8 +734,19 @@
         from _numpypy import arange
 
         a = arange(5)
+        assert (3 | a == [3, 3, 3, 3, 7]).all()
 
-        assert (3 | a == [3, 3, 3, 3, 7]).all()
+    def test_xor(self):
+        from _numpypy import arange
+
+        a = arange(5)
+        assert (a ^ 3 == [3, 2, 1, 0, 7]).all()
+
+    def test_rxor(self):
+        from _numpypy import arange
+
+        a = arange(5)
+        assert (3 ^ a == [3, 2, 1, 0, 7]).all()
 
     def test_pos(self):
         from _numpypy import array


More information about the pypy-commit mailing list