[pypy-commit] pypy default: added several new methods to numpy boxes
alex_gaynor
noreply at buildbot.pypy.org
Wed Feb 8 17:36:00 CET 2012
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r52247:886b1bb4c5ce
Date: 2012-02-08 11:35 -0500
http://bitbucket.org/pypy/pypy/changeset/886b1bb4c5ce/
Log: added several new methods to numpy boxes
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
@@ -81,8 +81,11 @@
descr_mul = _binop_impl("multiply")
descr_div = _binop_impl("divide")
descr_truediv = _binop_impl("true_divide")
+ descr_mod = _binop_impl("mod")
descr_pow = _binop_impl("power")
- descr_and = _binop_right_impl("bitwise_and")
+ 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")
@@ -181,8 +184,11 @@
__mul__ = interp2app(W_GenericBox.descr_mul),
__div__ = interp2app(W_GenericBox.descr_div),
__truediv__ = interp2app(W_GenericBox.descr_truediv),
+ __mod__ = interp2app(W_GenericBox.descr_mod),
__pow__ = interp2app(W_GenericBox.descr_pow),
__and__ = interp2app(W_GenericBox.descr_and),
+ __or__ = interp2app(W_GenericBox.descr_or),
+ __xor__ = interp2app(W_GenericBox.descr_xor),
__radd__ = interp2app(W_GenericBox.descr_radd),
__rsub__ = interp2app(W_GenericBox.descr_rsub),
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
@@ -383,9 +383,10 @@
("subtract", "sub", 2),
("multiply", "mul", 2, {"identity": 1}),
("bitwise_and", "bitwise_and", 2, {"identity": 1,
- 'int_only': True}),
+ "int_only": True}),
("bitwise_or", "bitwise_or", 2, {"identity": 0,
- 'int_only': True}),
+ "int_only": True}),
+ ("bitwise_xor", "bitwise_xor", 2, {"int_only": True}),
("invert", "invert", 1, {"int_only": True}),
("divide", "div", 2, {"promote_bools": True}),
("true_divide", "div", 2, {"promote_to_float": True}),
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
@@ -404,12 +404,16 @@
def test_operators(self):
from operator import truediv
- from _numpypy import float64, int_
+ from _numpypy import float64, int_, True_, False_
assert truediv(int_(3), int_(2)) == float64(1.5)
assert 2 ** int_(3) == int_(8)
assert int_(3) & int_(1) == int_(1)
raises(TypeError, lambda: float64(3) & 1)
+ assert int_(8) % int_(3) == int_(2)
+ assert int_(2) | int_(1) == int_(3)
+ assert int_(3) ^ int_(5) == int_(6)
+ assert True_ ^ False_ is True_
assert +int_(3) == int_(3)
assert ~int_(3) == int_(-4)
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
@@ -59,10 +59,6 @@
class BaseType(object):
def _unimplemented_ufunc(self, *args):
raise NotImplementedError
- # add = sub = mul = div = mod = pow = eq = ne = lt = le = gt = ge = max = \
- # min = copysign = pos = neg = abs = sign = reciprocal = fabs = floor = \
- # exp = sin = cos = tan = arcsin = arccos = arctan = arcsinh = \
- # arctanh = _unimplemented_ufunc
class Primitive(object):
_mixin_ = True
@@ -253,6 +249,10 @@
def bitwise_or(self, v1, v2):
return v1 | v2
+ @simple_binary_op
+ def bitwise_xor(self, v1, v2):
+ return v1 ^ v2
+
@simple_unary_op
def invert(self, v):
return ~v
@@ -313,6 +313,10 @@
def bitwise_or(self, v1, v2):
return v1 | v2
+ @simple_binary_op
+ def bitwise_xor(self, v1, v2):
+ return v1 ^ v2
+
@simple_unary_op
def invert(self, v):
return ~v
More information about the pypy-commit
mailing list