[pypy-commit] pypy default: add __floordiv__ functionality -- make tests pass =)
MichaelBlume
noreply at buildbot.pypy.org
Mon Mar 12 22:49:24 CET 2012
Author: Mike Blume <mike at loggly.com>
Branch:
Changeset: r53355:de4d8fcc27dd
Date: 2012-03-12 13:23 -0700
http://bitbucket.org/pypy/pypy/changeset/de4d8fcc27dd/
Log: add __floordiv__ functionality -- make tests pass =)
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
@@ -102,6 +102,7 @@
descr_mul = _binop_impl("multiply")
descr_div = _binop_impl("divide")
descr_truediv = _binop_impl("true_divide")
+ descr_floordiv = _binop_impl("floor_divide")
descr_mod = _binop_impl("mod")
descr_pow = _binop_impl("power")
descr_lshift = _binop_impl("left_shift")
@@ -1250,6 +1251,7 @@
__mul__ = interp2app(BaseArray.descr_mul),
__div__ = interp2app(BaseArray.descr_div),
__truediv__ = interp2app(BaseArray.descr_truediv),
+ __floordiv__ = interp2app(BaseArray.descr_floordiv),
__mod__ = interp2app(BaseArray.descr_mod),
__divmod__ = interp2app(BaseArray.descr_divmod),
__pow__ = interp2app(BaseArray.descr_pow),
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
@@ -388,6 +388,7 @@
"int_only": True}),
("bitwise_xor", "bitwise_xor", 2, {"int_only": True}),
("invert", "invert", 1, {"int_only": True}),
+ ("floor_divide", "floordiv", 2, {"promote_bools": True}),
("divide", "div", 2, {"promote_bools": True}),
("true_divide", "div", 2, {"promote_to_float": True}),
("mod", "mod", 2, {"promote_bools": True}),
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
@@ -280,6 +280,12 @@
return v1 / v2
@simple_binary_op
+ def floordiv(self, v1, v2):
+ if v2 == 0:
+ return 0
+ return v1 // v2
+
+ @simple_binary_op
def mod(self, v1, v2):
return v1 % v2
@@ -418,6 +424,15 @@
return rfloat.copysign(rfloat.INFINITY, v1 * v2)
@simple_binary_op
+ def floordiv(self, v1, v2):
+ try:
+ return v1 // v2
+ except ZeroDivisionError:
+ if v1 == v2 == 0.0:
+ return rfloat.NAN
+ return rfloat.copysign(rfloat.INFINITY, v1 * v2)
+
+ @simple_binary_op
def mod(self, v1, v2):
return math.fmod(v1, v2)
More information about the pypy-commit
mailing list