[pypy-commit] pypy numpypy-axisops: assert for translation, small cleanups

mattip noreply at buildbot.pypy.org
Fri Dec 30 13:51:48 CET 2011


Author: mattip
Branch: numpypy-axisops
Changeset: r50953:911002e026f2
Date: 2011-12-30 13:40 +0200
http://bitbucket.org/pypy/pypy/changeset/911002e026f2/

Log:	assert for translation, small cleanups

diff --git a/pypy/module/micronumpy/interp_iter.py b/pypy/module/micronumpy/interp_iter.py
--- a/pypy/module/micronumpy/interp_iter.py
+++ b/pypy/module/micronumpy/interp_iter.py
@@ -103,15 +103,21 @@
     def next(self, shapelen):
         return self
 
-def axis_iter_from_arr(arr, dim=-1, start=[]):
+def axis_iter_from_arr(arr, dim=-1, start=None):
+    if start is None:
+        start = []
+    # The assert is needed for zjit tests
+    from pypy.module.micronumpy.interp_numarray import ConcreteArray
+    assert isinstance(arr, ConcreteArray)
     return AxisIterator(arr.start, arr.strides, arr.backstrides, arr.shape,
                         dim, start)
 
 class AxisIterator(object):
     """ This object will return offsets of each start of a stride on the 
-        desired dimension, starting at the desired index
+        desired dimension, starting at "start" which is an index along 
+        each axis
     """
-    def __init__(self, arr_start, strides, backstrides, shape, dim=-1, slice_start=[]):
+    def __init__(self, arr_start, strides, backstrides, shape, dim, start):
         self.shape = shape
         self.shapelen = len(shape)
         self.indices = [0] * len(shape)
@@ -123,8 +129,8 @@
         if dim >= 0:
             self.dim = dim
         if len(slice_start) == len(shape):
-            for i in range(len(slice_start)):
-                self.offset += strides[i] * slice_start[i]
+            for i in range(len(start)):
+                self.offset += strides[i] * start[i]
     def next(self, shapelen):
         #shapelen will always be one less than self.shapelen
         offset = self.offset
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
@@ -281,8 +281,8 @@
     descr_rdiv = _binop_right_impl("divide")
     descr_rpow = _binop_right_impl("power")
     descr_rmod = _binop_right_impl("mod")
-    
-    def _reduce_ufunc_impl(ufunc_name, promote_to_largest = False):
+
+    def _reduce_ufunc_impl(ufunc_name, promote_to_largest=False):
         def impl(self, space, w_dim=-1):
             if isinstance(w_dim,int):
                 w_dim = space.wrap(w_dim)
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
@@ -119,8 +119,8 @@
         dtype = find_unaryop_result_dtype(
             space, obj.find_dtype(),
             promote_to_float=self.promote_to_float,
-            promote_to_largest = promote_to_largest,
-            promote_bools = True
+            promote_to_largest=promote_to_largest,
+            promote_bools=True
         )
         shapelen = len(obj.shape)
         if self.identity is None and size == 0:


More information about the pypy-commit mailing list