[pypy-commit] pypy numpy-dtype-alt: bunch of small fixes in the tests.

alex_gaynor noreply at buildbot.pypy.org
Mon Aug 22 03:10:33 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: numpy-dtype-alt
Changeset: r46693:cccc58163d20
Date: 2011-08-21 20:15 -0500
http://bitbucket.org/pypy/pypy/changeset/cccc58163d20/

Log:	bunch of small fixes in the tests.

diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -37,8 +37,7 @@
         def f(i):
             ar = SingleDimArray(i, dtype=self.float64_dtype)
             v = interp_ufuncs.add(self.space, ar, ar)
-            concrete = v.get_concrete()
-            return concrete.dtype.getitem(concrete.storage, 3).val
+            return v.get_concrete().eval(3).val
 
         result = self.meta_interp(f, [5], listops=True, backendopt=True)
         self.check_loops({'getarrayitem_raw': 2, 'float_add': 1,
@@ -50,7 +49,7 @@
         def f(i):
             ar = SingleDimArray(i, dtype=self.float64_dtype)
             v = interp_ufuncs.add(self.space, ar, scalar_w(self.space, W_Float64Dtype, 4.5))
-            return v.dtype.getitem(v.get_concrete().storage, 3)
+            return v.get_concrete().eval(3).val
 
         result = self.meta_interp(f, [5], listops=True, backendopt=True)
         self.check_loops({"getarrayitem_raw": 1, "float_add": 1,
@@ -91,7 +90,7 @@
             ar = SingleDimArray(i, dtype=self.float64_dtype)
             j = 0
             while j < i:
-                ar.get_concrete().storage[j] = float(j)
+                ar.get_concrete().setitem(space, j, float(j))
                 j += 1
             return ar.descr_add(space, ar).descr_max(space)
 
@@ -109,7 +108,7 @@
             ar = SingleDimArray(i, dtype=self.float64_dtype)
             j = 0
             while j < i:
-                ar.get_concrete().storage[j] = float(j)
+                ar.get_concrete().setitem(space, j, float(j))
                 j += 1
             return ar.descr_add(space, ar).descr_min(space)
 
@@ -127,7 +126,7 @@
             ar = SingleDimArray(i, dtype=self.float64_dtype)
             j = 0
             while j < i:
-                ar.get_concrete().storage[j] = float(j)
+                ar.get_concrete().setitem(space, j, float(j))
                 j += 1
             return ar.descr_add(space, ar).descr_argmin(space)
 
@@ -145,9 +144,10 @@
             ar = SingleDimArray(i, dtype=self.float64_dtype)
             j = 0
             while j < i:
-                ar.get_concrete().storage[j] = 1.0
+                ar.get_concrete().setitem(space, j, float(j))
                 j += 1
             return ar.descr_add(space, ar).descr_all(space)
+
         result = self.meta_interp(f, [5], listops=True, backendopt=True)
         self.check_loops({"getarrayitem_raw": 2, "float_add": 1,
                           "int_add": 1, "float_ne": 1,
@@ -171,9 +171,9 @@
         def f(i):
             ar = SingleDimArray(i, dtype=self.float64_dtype)
             v1 = interp_ufuncs.add(self.space, ar, scalar_w(self.space, W_Float64Dtype, 4.5))
-            v2 = interp_ufuncs.mul(self.space, v1, scalar_w(self.space, W_Float64Dtype, 4.5))
+            v2 = interp_ufuncs.multiply(self.space, v1, scalar_w(self.space, W_Float64Dtype, 4.5))
             v1.force_if_needed()
-            return v2.get_concrete().storage[3]
+            return v2.get_concrete().eval(3).val
 
         result = self.meta_interp(f, [5], listops=True, backendopt=True)
         # This is the sum of the ops for both loops, however if you remove the
@@ -190,7 +190,7 @@
             ar = SingleDimArray(i, dtype=self.float64_dtype)
             v1 = interp_ufuncs.add(space, ar, ar)
             v2 = interp_ufuncs.negative(space, v1)
-            return v2.get_concrete().storage[3]
+            return v2.get_concrete().eval(3).val
 
         result = self.meta_interp(f, [5], listops=True, backendopt=True)
         self.check_loops({"getarrayitem_raw": 2, "float_add": 1, "float_neg": 1,
@@ -209,8 +209,8 @@
             v2.get_concrete()
 
             for i in xrange(5):
-                v1 = interp_ufuncs.mul(space, ar, ar)
-                v2 = negative(space, v1)
+                v1 = interp_ufuncs.multiply(space, ar, ar)
+                v2 = interp_ufuncs.negative(space, v1)
                 v2.get_concrete()
 
         self.meta_interp(f, [5], listops=True, backendopt=True)
@@ -226,7 +226,7 @@
             ])
             s = SingleDimSlice(0, step*i, step, i, ar, new_sig)
             v = interp_ufuncs.add(self.space, s, s)
-            return v.get_concrete().storage[3]
+            return v.get_concrete().eval(3).val
 
         result = self.meta_interp(f, [5], listops=True, backendopt=True)
         self.check_loops({'int_mul': 1, 'getarrayitem_raw': 2, 'float_add': 1,
@@ -238,11 +238,17 @@
         def f(i):
             step1 = 2
             step2 = 3
-            ar = SingleDimArray(step2*i)
-            s1 = SingleDimSlice(0, step1*i, step1, i, ar, ar.signature.transition(SingleDimSlice.static_signature))
-            s2 = SingleDimSlice(0, step2*i, step2, i, ar, ar.signature.transition(SingleDimSlice.static_signature))
-            v = Call2(add, s1, s2, Signature())
-            return v.get_concrete().storage[3]
+            ar = SingleDimArray(step2*i, dtype=self.float64_dtype)
+            new_sig = signature.Signature.find_sig([
+                SingleDimSlice.signature, ar.signature
+            ])
+            s1 = SingleDimSlice(0, step1*i, step1, i, ar, new_sig)
+            new_sig = signature.Signature.find_sig([
+                SingleDimSlice.signature, s1.signature
+            ])
+            s2 = SingleDimSlice(0, step2*i, step2, i, ar, new_sig)
+            v = interp_ufuncs.add(self.space, s1, s2)
+            return v.get_concrete().eval(3).val
 
         result = self.meta_interp(f, [5], listops=True, backendopt=True)
         self.check_loops({'int_mul': 2, 'getarrayitem_raw': 2, 'float_add': 1,
@@ -257,13 +263,13 @@
             step = NonConstant(3)
             ar = SingleDimArray(step*i, dtype=self.float64_dtype)
             ar2 = SingleDimArray(i, dtype=self.float64_dtype)
-            ar2.storage[1] = 5.5
+            ar2.get_concrete().setitem(space, 1, 5.5)
             if NonConstant(False):
                 arg = ar2
             else:
                 arg = ar2.descr_add(space, ar2)
             ar.setslice(space, 0, step*i, step, i, arg)
-            return ar.get_concrete().storage[3]
+            return ar.get_concrete().eval(3).val
 
         result = self.meta_interp(f, [5], listops=True, backendopt=True)
         self.check_loops({'getarrayitem_raw': 2,
@@ -278,8 +284,8 @@
         x = x.compute()
         assert isinstance(x, SingleDimArray)
         assert x.size == 10
-        assert x.storage[0] == 0
-        assert x.storage[1] == ((1 + 1) * 1.2) / 1.2 - 1
+        assert x.eval(0).val == 0
+        assert x.eval(1).val == ((1 + 1) * 1.2) / 1.2 - 1
 
     def test_translation(self):
         # we import main to check if the target compiles
diff --git a/pypy/rlib/nonconst.py b/pypy/rlib/nonconst.py
--- a/pypy/rlib/nonconst.py
+++ b/pypy/rlib/nonconst.py
@@ -24,6 +24,12 @@
     def __add__(self, other):
         return self.__dict__['constant'] + other
 
+    def __radd__(self, other):
+        return other + self.__dict__['constant']
+
+    def __mul__(self, other):
+        return self.__dict__['constant'] * other
+
 class EntryNonConstant(ExtRegistryEntry):
     _about_ = NonConstant
 


More information about the pypy-commit mailing list