[pypy-commit] pypy default: rdivmod for ndarray
alex_gaynor
noreply at buildbot.pypy.org
Thu Feb 9 15:13:25 CET 2012
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r52290:9f3109756878
Date: 2012-02-09 09:01 -0500
http://bitbucket.org/pypy/pypy/changeset/9f3109756878/
Log: rdivmod for 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
@@ -138,6 +138,11 @@
descr_rand = _binop_right_impl("bitwise_and")
+ def descr_rdivmod(self, space, w_other):
+ w_quotient = self.descr_rdiv(space, w_other)
+ w_remainder = self.descr_rmod(space, w_other)
+ return space.newtuple([w_quotient, w_remainder])
+
def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False):
def impl(self, space, w_axis=None):
if space.is_w(w_axis, space.w_None):
@@ -1255,6 +1260,7 @@
__rmul__ = interp2app(BaseArray.descr_rmul),
__rdiv__ = interp2app(BaseArray.descr_rdiv),
__rmod__ = interp2app(BaseArray.descr_rmod),
+ __rdivmod__ = interp2app(BaseArray.descr_rdivmod),
__rpow__ = interp2app(BaseArray.descr_rpow),
__rand__ = interp2app(BaseArray.descr_rand),
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
@@ -632,6 +632,13 @@
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_rdivmod(self):
+ from _numpypy import arange
+
+ a, b = divmod(3, arange(1, 5))
+ assert (a == [3, 1, 1, 0]).all()
+ assert (b == [0, 1, 0, 3]).all()
+
def test_lshift(self):
from _numpypy import array
More information about the pypy-commit
mailing list