Author: Maciej Fijalkowski <[email protected]>
Branch: refactor-signature
Changeset: r50533:876091f5df5a
Date: 2011-12-15 10:34 +0200
http://bitbucket.org/pypy/pypy/changeset/876091f5df5a/

Log:    rpythonization, remove one int_add

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
@@ -782,10 +782,11 @@
     """
     Class for representing virtual arrays, such as binary ops or ufuncs
     """
-    def __init__(self, shape, res_dtype, order):
+    def __init__(self, name, shape, res_dtype, order):
         BaseArray.__init__(self, shape, order)
         self.forced_result = None
         self.res_dtype = res_dtype
+        self.name = name
 
     def _del_sources(self):
         # Function for deleting references to source arrays, to allow 
garbage-collecting them
@@ -837,8 +838,8 @@
 
 
 class Call1(VirtualArray):
-    def __init__(self, ufunc, shape, res_dtype, values, order):
-        VirtualArray.__init__(self, shape, res_dtype,
+    def __init__(self, ufunc, name, shape, res_dtype, values, order):
+        VirtualArray.__init__(self, name, shape, res_dtype,
                               values.order)
         self.values = values
         self.ufunc = ufunc
@@ -855,14 +856,14 @@
     def create_sig(self):
         if self.forced_result is not None:
             return self.forced_result.create_sig()
-        return signature.Call1(self.ufunc, self.values.create_sig())
+        return signature.Call1(self.ufunc, self.name, self.values.create_sig())
 
 class Call2(VirtualArray):
     """
     Intermediate class for performing binary operations.
     """
-    def __init__(self, ufunc, shape, calc_dtype, res_dtype, left, right):
-        VirtualArray.__init__(self, shape, res_dtype, left.order)
+    def __init__(self, ufunc, name, shape, calc_dtype, res_dtype, left, right):
+        VirtualArray.__init__(self, name, shape, res_dtype, left.order)
         self.ufunc = ufunc
         self.left = left
         self.right = right
@@ -881,7 +882,7 @@
     def create_sig(self):
         if self.forced_result is not None:
             return self.forced_result.create_sig()
-        return signature.Call2(self.ufunc, self.left.create_sig(),
+        return signature.Call2(self.ufunc, self.name, self.left.create_sig(),
                                self.right.create_sig())
 
 class ViewArray(BaseArray):
diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -50,7 +50,7 @@
         return self.reduce(space, w_obj, multidim=False)
 
     def reduce(self, space, w_obj, multidim):
-        from pypy.module.micronumpy.interp_numarray import convert_to_array, 
Scalar, Call2
+        from pypy.module.micronumpy.interp_numarray import convert_to_array, 
Scalar
         
         if self.argcount != 2:
             raise OperationError(space.w_ValueError, space.wrap("reduce only "
@@ -68,7 +68,8 @@
             promote_to_largest=True
         )
         shapelen = len(obj.shape)
-        sig = find_sig(ReduceSignature(self.func, ScalarSignature(dtype),
+        sig = find_sig(ReduceSignature(self.func, self.name,
+                                       ScalarSignature(dtype),
                                        obj.create_sig()))
         frame = sig.create_frame(obj)
         if shapelen > 1 and not multidim:
@@ -117,7 +118,8 @@
         if isinstance(w_obj, Scalar):
             return self.func(res_dtype, w_obj.value.convert_to(res_dtype))
 
-        w_res = Call1(self.func, w_obj.shape, res_dtype, w_obj, w_obj.order)
+        w_res = Call1(self.func, self.name, w_obj.shape, res_dtype, w_obj,
+                      w_obj.order)
         w_obj.add_invalidates(w_res)
         return w_res
 
@@ -156,7 +158,7 @@
             )
 
         new_shape = shape_agreement(space, w_lhs.shape, w_rhs.shape)
-        w_res = Call2(self.func, new_shape, calc_dtype,
+        w_res = Call2(self.func, self.name, new_shape, calc_dtype,
                       res_dtype, w_lhs, w_rhs)
         w_lhs.add_invalidates(w_res)
         w_rhs.add_invalidates(w_res)
diff --git a/pypy/module/micronumpy/signature.py 
b/pypy/module/micronumpy/signature.py
--- a/pypy/module/micronumpy/signature.py
+++ b/pypy/module/micronumpy/signature.py
@@ -1,7 +1,7 @@
-from pypy.rlib.objectmodel import r_dict, compute_identity_hash
+from pypy.rlib.objectmodel import r_dict, compute_identity_hash, compute_hash
 from pypy.module.micronumpy.interp_iter import ViewIterator, ArrayIterator, \
      BroadcastIterator, OneDimIterator, ConstantIterator
-from pypy.rlib.jit import hint, unroll_safe
+from pypy.rlib.jit import hint, unroll_safe, promote
 
 # def components_eq(lhs, rhs):
 #     if len(lhs) != len(rhs):
@@ -37,18 +37,23 @@
 class NumpyEvalFrame(object):
     _virtualizable2_ = ['iterators[*]', 'final_iter']
 
+    @unroll_safe
     def __init__(self, iterators):
-        self = hint(self, access_directly=True)
-        self.iterators = iterators
-        for i, iter in enumerate(self.iterators):
+        self = hint(self, access_directly=True, fresh_virtualizable=True)
+        self.iterators = iterators[:]
+        for i in range(len(self.iterators)):
+            iter = self.iterators[i]
             if not isinstance(iter, ConstantIterator):# or not 
isinstance(iter, BroadcastIterator):
                 self.final_iter = i
                 break
         else:
-            raise Exception("Cannot find a non-broadcast non-constant iter")
+            self.final_iter = -1
 
     def done(self):
-        return self.iterators[self.final_iter].done()
+        final_iter = promote(self.final_iter)
+        if final_iter < 0:
+            return False
+        return self.iterators[final_iter].done()
 
     @unroll_safe
     def next(self, shapelen):
@@ -159,12 +164,13 @@
         raise NotImplementedError
 
 class Call1(Signature):
-    def __init__(self, func, child):
+    def __init__(self, func, name, child):
         self.unfunc = func
         self.child = child
+        self.name = name
 
     def hash(self):
-        return compute_identity_hash(self.unfunc) ^ self.child.hash() << 1
+        return compute_hash(self.name) ^ self.child.hash() << 1
 
     def eq(self, other):
         if type(self) is not type(other):
@@ -172,7 +178,7 @@
         return self.unfunc is other.unfunc and self.child.eq(other.child)
 
     def debug_repr(self):
-        return 'Call1(%s)' % (self.child.debug_repr())
+        return 'Call1(%s, %s)' % (self.name, self.child.debug_repr())
 
     def _invent_numbering(self, cache, allnumbers):
         self.child._invent_numbering(cache, allnumbers)
@@ -189,13 +195,14 @@
         return self.unfunc(arr.res_dtype, v)
 
 class Call2(Signature):
-    def __init__(self, func, left, right):
+    def __init__(self, func, name, left, right):
         self.binfunc = func
         self.left = left
         self.right = right
+        self.name = name
 
     def hash(self):
-        return (compute_identity_hash(self.binfunc) ^ (self.left.hash() << 1) ^
+        return (compute_hash(self.name) ^ (self.left.hash() << 1) ^
                 (self.right.hash() << 2))
 
     def eq(self, other):
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
@@ -80,7 +80,7 @@
     def test_add(self):
         result = self.run("add")
         self.check_simple_loop({'getinteriorfield_raw': 2, 'float_add': 1,
-                                'setinteriorfield_raw': 1, 'int_add': 3,
+                                'setinteriorfield_raw': 1, 'int_add': 2,
                                 'int_ge': 1, 'guard_false': 1, 'jump': 1})
         assert result == 3 + 3
 
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to