Author: Richard Plangger <[email protected]>
Branch: vecopt
Changeset: r77689:b47f0d81442a
Date: 2015-05-29 15:55 +0200
http://bitbucket.org/pypy/pypy/changeset/b47f0d81442a/

Log:    first try to merge iterators in call2

diff --git a/pypy/module/micronumpy/iterators.py 
b/pypy/module/micronumpy/iterators.py
--- a/pypy/module/micronumpy/iterators.py
+++ b/pypy/module/micronumpy/iterators.py
@@ -116,6 +116,16 @@
                 factors[ndim-i-1] = factors[ndim-i] * shape[ndim-i]
         self.factors = factors
 
+    def matches_range(self, other_iter):
+        assert isinstance(other_iter, ArrayIter)
+        return self.size == other_iter.size and \
+               self.contiguous == other_iter.contiguous and \
+               self.ndim_m1 == other_iter.ndim_m1 and \
+               self.shape_m1 == other_iter.shape_m1 and \
+               self.strides == other_iter.strides and \
+               self.factors == other_iter.factors and \
+               self.backstrides == other_iter.backstrides
+
     @jit.unroll_safe
     def reset(self, state=None, mutate=False):
         index = 0
diff --git a/pypy/module/micronumpy/loop.py b/pypy/module/micronumpy/loop.py
--- a/pypy/module/micronumpy/loop.py
+++ b/pypy/module/micronumpy/loop.py
@@ -15,7 +15,7 @@
 
 call2_driver = jit.JitDriver(
     name='numpy_call2',
-    greens=['shapelen', 'func', 'calc_dtype', 'res_dtype'],
+    greens=['shapelen', 'func', 'left_advance', 'right_advance', 'calc_dtype', 
'res_dtype' ],
     reds='auto', vectorize=True)
 
 def call2(space, shape, func, calc_dtype, res_dtype, w_lhs, w_rhs, out):
@@ -58,24 +58,40 @@
         w_right = None
         right_iter, right_state = w_rhs.create_iter(shape)
         right_iter.track_index = False
-
     if out is None:
         out = W_NDimArray.from_shape(space, shape, res_dtype,
                                      w_instance=lhs_for_subtype)
     out_iter, out_state = out.create_iter(shape)
+
+    left_advance = True
+    right_advance = True
+    if left_iter and left_iter.matches_range(out_iter):
+        left_advance = False
+        left_state = out_state
+    if right_iter and right_iter.matches_range(out_iter):
+        right_advance = False
+        right_state = out_state
+
     shapelen = len(shape)
     while not out_iter.done(out_state):
-        call2_driver.jit_merge_point(shapelen=shapelen, func=func,
-                                     calc_dtype=calc_dtype, 
res_dtype=res_dtype)
+        call2_driver.jit_merge_point(shapelen=shapelen, 
left_advance=left_advance, right_advance=right_advance,
+                                     func=func, calc_dtype=calc_dtype, 
res_dtype=res_dtype)
         if left_iter:
             w_left = left_iter.getitem(left_state).convert_to(space, 
calc_dtype)
-            left_state = left_iter.next(left_state)
+            if left_advance:
+                left_state = left_iter.next(left_state)
         if right_iter:
             w_right = right_iter.getitem(right_state).convert_to(space, 
calc_dtype)
-            right_state = right_iter.next(right_state)
+            if right_advance:
+                right_state = right_iter.next(right_state)
         out_iter.setitem(out_state, func(calc_dtype, w_left, 
w_right).convert_to(
             space, res_dtype))
         out_state = out_iter.next(out_state)
+        if not left_advance:
+            left_state = out_state
+        if not right_advance:
+            right_state = out_state
+
     return out
 
 call1_driver = jit.JitDriver(
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to