[pypy-commit] pypy default: fix for pow on ints, and translated binops

alex_gaynor noreply at buildbot.pypy.org
Mon Nov 28 18:20:49 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r49923:6f6b258f307e
Date: 2011-11-28 12:20 -0500
http://bitbucket.org/pypy/pypy/changeset/6f6b258f307e/

Log:	fix for pow on ints, and translated binops

diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -131,6 +131,7 @@
 
 
 def binop(func):
+    func._annspecialcase_ = "specialize:call_location"
     @functools.wraps(func)
     def impl(self, v1, v2):
         return self.adapt_val(func(self,
@@ -320,6 +321,18 @@
     @binop
     def mod(self, v1, v2):
         return v1 % v2
+    @binop
+    def pow(self, v1, v2):
+        res = 1
+        while v2 > 0:
+            if v2 & 1:
+                res *= v1
+            v2 >>= 1
+            if v2 == 0:
+                break
+            v1 *= v1
+        return res
+
 
 class SignedIntegerArithmeticDtype(IntegerArithmeticDtype):
     _mixin_ = True
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
@@ -466,7 +466,6 @@
         for i in range(5):
             assert b[i] == i ** i
 
-        skip("failing")
         a = array(range(5))
         assert (a ** 2 == a * a).all()
 
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -111,6 +111,8 @@
         for i in range(3):
             assert c[i] == a[i] / b[i]
 
+        assert (divide(array([-10]), array([2])) == array([-5])).all()
+
     def test_fabs(self):
         from numpypy import array, fabs
         from math import fabs as math_fabs


More information about the pypy-commit mailing list