Author: Alex Gaynor <[email protected]>
Branch:
Changeset: r52288:9b833e2a9dae
Date: 2012-02-09 08:53 -0500
http://bitbucket.org/pypy/pypy/changeset/9b833e2a9dae/
Log: added divmod to ndarray
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
@@ -101,8 +101,8 @@
descr_sub = _binop_impl("subtract")
descr_mul = _binop_impl("multiply")
descr_div = _binop_impl("divide")
+ descr_mod = _binop_impl("mod")
descr_pow = _binop_impl("power")
- descr_mod = _binop_impl("mod")
descr_lshift = _binop_impl("left_shift")
descr_eq = _binop_impl("equal")
@@ -115,6 +115,11 @@
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)
+ return space.newtuple([w_quotient, w_remainder])
+
def _binop_right_impl(ufunc_name):
def impl(self, space, w_other):
w_other = scalar_w(space,
@@ -1234,8 +1239,9 @@
__sub__ = interp2app(BaseArray.descr_sub),
__mul__ = interp2app(BaseArray.descr_mul),
__div__ = interp2app(BaseArray.descr_div),
+ __mod__ = interp2app(BaseArray.descr_mod),
+ __divmod__ = interp2app(BaseArray.descr_divmod),
__pow__ = interp2app(BaseArray.descr_pow),
- __mod__ = interp2app(BaseArray.descr_mod),
__lshift__ = interp2app(BaseArray.descr_lshift),
__radd__ = interp2app(BaseArray.descr_radd),
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
@@ -625,6 +625,13 @@
for i in range(5):
assert b[i] == i / 5.0
+ def test_divmod(self):
+ from _numpypy import arange
+
+ a, b = divmod(arange(10), 3)
+ assert (a == [0, 0, 0, 1, 1, 1, 2, 2, 2, 3]).all()
+ assert (b == [0, 1, 2, 0, 1, 2, 0, 1, 2, 0]).all()
+
def test_lshift(self):
from _numpypy import array
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit