[pypy-commit] pypy default: Added radd, rsub, rmul, rdiv, rpow, rmod to numpy arrays

justinpeel noreply at buildbot.pypy.org
Tue Jul 12 00:47:09 CEST 2011


Author: Justin Peel <notmuchtotell at gmail.com>
Branch: 
Changeset: r45482:6eb35289ed58
Date: 2011-07-10 23:32 -0600
http://bitbucket.org/pypy/pypy/changeset/6eb35289ed58/

Log:	Added radd, rsub, rmul, rdiv, rpow, rmod to numpy arrays

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
@@ -45,7 +45,7 @@
     return v1 * v2
 def div(v1, v2):
     return v1 / v2
-def pow(v1, v2):
+def power(v1, v2):
     return math.pow(v1, v2)
 def mod(v1, v2):
     return math.fmod(v1, v2)
@@ -115,9 +115,32 @@
     descr_sub = _binop_impl(sub)
     descr_mul = _binop_impl(mul)
     descr_div = _binop_impl(div)
-    descr_pow = _binop_impl(pow)
+    descr_pow = _binop_impl(power)
     descr_mod = _binop_impl(mod)
 
+    def _binop_right_impl(function):
+        signature = Signature()
+        def impl(self, space, w_other):
+            new_sig = self.signature.transition(signature)
+            w_other = FloatWrapper(space.float_w(w_other))
+            res = Call2(
+                function,
+                w_other,
+                self,
+                new_sig.transition(w_other.signature)
+            )
+            self.invalidates.append(res)
+            return space.wrap(res)
+        return func_with_new_name(impl, 
+                                  "binop_right_%s_impl" % function.__name__)
+
+    descr_radd = _binop_right_impl(add)
+    descr_rsub = _binop_right_impl(sub)
+    descr_rmul = _binop_right_impl(mul)
+    descr_rdiv = _binop_right_impl(div)
+    descr_rpow = _binop_right_impl(power)
+    descr_rmod = _binop_right_impl(mod)
+
     def _reduce_sum_prod_impl(function, init):
         reduce_driver = jit.JitDriver(greens=['signature'],
                          reds = ['i', 'size', 'self', 'result'])
@@ -480,6 +503,12 @@
     __div__ = interp2app(BaseArray.descr_div),
     __pow__ = interp2app(BaseArray.descr_pow),
     __mod__ = interp2app(BaseArray.descr_mod),
+    __radd__ = interp2app(BaseArray.descr_radd),
+    __rsub__ = interp2app(BaseArray.descr_rsub),
+    __rmul__ = interp2app(BaseArray.descr_rmul),
+    __rdiv__ = interp2app(BaseArray.descr_rdiv),
+    __rpow__ = interp2app(BaseArray.descr_rpow),
+    __rmod__ = interp2app(BaseArray.descr_rmod),
 
     mean = interp2app(BaseArray.descr_mean),
     sum = interp2app(BaseArray.descr_sum),


More information about the pypy-commit mailing list