[pypy-commit] pypy default: eliminate a few more ops in dot

bdkearns noreply at buildbot.pypy.org
Fri Feb 28 17:24:21 CET 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r69560:fb2dae86f26e
Date: 2014-02-28 11:23 -0500
http://bitbucket.org/pypy/pypy/changeset/fb2dae86f26e/

Log:	eliminate a few more ops in dot

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
@@ -79,30 +79,31 @@
 
 
 class ArrayIter(object):
-    _immutable_fields_ = ['array', 'size', 'indices', 'shape_m1[*]',
-                          'strides[*]', 'backstrides[*]']
+    _immutable_fields_ = ['array', 'size', 'ndim_m1', 'shape_m1[*]',
+                          'strides[*]', 'backstrides[*]', 'indices']
 
     def __init__(self, array, size, shape, strides, backstrides):
         assert len(shape) == len(strides) == len(backstrides)
         self.array = array
         self.size = size
-        self.indices = [0] * len(shape)
+        self.ndim_m1 = len(shape) - 1
         self.shape_m1 = [s - 1 for s in shape]
         self.strides = strides
         self.backstrides = backstrides
+        self.indices = [0] * len(shape)
         self.reset()
 
     @jit.unroll_safe
     def reset(self):
         self.index = 0
-        for i in xrange(len(self.shape_m1)):
+        for i in xrange(self.ndim_m1, -1, -1):
             self.indices[i] = 0
         self.offset = self.array.start
 
     @jit.unroll_safe
     def next(self):
         self.index += 1
-        for i in xrange(len(self.shape_m1) - 1, -1, -1):
+        for i in xrange(self.ndim_m1, -1, -1):
             if self.indices[i] < self.shape_m1[i]:
                 self.indices[i] += 1
                 self.offset += self.strides[i]
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
@@ -517,13 +517,12 @@
                                 'int_lt': 1,
                                 'jump': 1,
                                 'raw_load': 2})
-        self.check_resops({'arraylen_gc': 4,
-                           'float_add': 2,
+        self.check_resops({'float_add': 2,
                            'float_mul': 2,
                            'getarrayitem_gc': 11,
                            'getarrayitem_gc_pure': 15,
                            'getfield_gc': 30,
-                           'getfield_gc_pure': 40,
+                           'getfield_gc_pure': 44,
                            'guard_class': 4,
                            'guard_false': 14,
                            'guard_nonnull': 8,
@@ -535,7 +534,7 @@
                            'int_ge': 4,
                            'int_le': 8,
                            'int_lt': 11,
-                           'int_sub': 8,
+                           'int_sub': 4,
                            'jump': 3,
                            'raw_load': 6,
                            'raw_store': 1,


More information about the pypy-commit mailing list