Commits

Alex Gaynor committed 2483076

Some cleanup: remove parameters that's never used, rename class, delete some more setshape code, fix a case of arange with bools.

Comments (0)

Files changed (4)

pypy/module/micronumpy/__init__.py

         'empty': 'interp_numarray.zeros',
         'ones': 'interp_numarray.ones',
         'fromstring': 'interp_support.fromstring',
-        'flatiter': 'interp_numarray.FlatIterator',
+        'flatiter': 'interp_numarray.W_FlatIterator',
 
         'True_': 'space.w_True',
         'False_': 'space.w_False',

pypy/module/micronumpy/app_numpy.py

     return a.mean()
 
 
-def arange(start, stop=None, step=1, dtype=None, maskna=False):
-    '''arange([start], stop[, step], dtype=None, maskna=False)
+def arange(start, stop=None, step=1, dtype=None):
+    '''arange([start], stop[, step], dtype=None)
     Generate values in the half-interval [start, stop).
     '''
     if stop is None:
         stop = start
         start = 0
-    if maskna is not False:
-        raise ValueError('Not Implemented')
     if dtype is None:
-        test = numpypy.array([start, stop, step])
+        test = numpypy.array([start, stop, step, 0])
         dtype = test.dtype
     arr = numpypy.zeros(int(math.ceil((stop - start) / step)), dtype=dtype)
     i = start

pypy/module/micronumpy/interp_numarray.py

 
     def descr_get_shape(self, space):
         return space.newtuple([space.wrap(i) for i in self.shape])
-            
+
     def descr_get_size(self, space):
         return space.wrap(self.find_size())
 
                            backstrides[:], shape[:]))
 
     def descr_get_flatiter(self, space):
-        return space.wrap(FlatIterator(self))
+        return space.wrap(W_FlatIterator(self))
 
     def getitem(self, item):
         raise NotImplementedError
             return space.wrap(self.shape[0])
         return space.wrap(1)
 
-    def setshape(self, space, new_shape):
-        if len(self.shape) < 1:
-            return
-        elif len(self.shape) < 2:
-            #REVIEWER: this code could be refactored into calc_strides
-            #but then calc_strides would have to accept a factor of the
-            #current stride
-            strides = []
-            backstrides = []
-            self.shape = new_shape[:]
-            s = self.strides[0]
-            if self.order == 'C':
-                new_shape.reverse()
-            for sh in new_shape:
-                strides.append(s)
-                backstrides.append(s * (sh - 1))
-                s *= sh
-            if self.order == 'C':
-                strides.reverse()
-                backstrides.reverse()
-            self.strides = strides[:]
-            self.backstrides = backstrides[:]
-            return
-        #REVIEWER: wordy comment to explain what the intention was. Please
-        #edit or remove.
-        #We know that the product of new_shape is correct.
-        #Now we must check that the new shape does not create stepping conflicts
-        # for the strides It works like this:
-        # - Determine the right-to-lef tor left-to-right fastest iterating 
-        #   dimension. Note it is not enough just to check self.order, since a
-        #   transpose reverses everything.
-        # - Start recalculating the strides, by each dimension. Keep a running 
-        #   cumprod of the old shape up to this dimension vs. the new shape up 
-        #   to this dimension. Every time the products match, update the stride
-        #   currently in use.
-        # - The strides for each of the matching pieces must also match, 
-        # - The stride will always be based on the old stride of the lowest
-        #   dimension in the chunk, since 
-        new_dims = range(len(new_shape)) 
-        old_dims = range(len(self.shape))
-        if self.strides[0]> self.strides[-1]:
-            #This is the normal thing to do
-            new_dims.reverse()
-            old_dims.reverse()
-        nd = 0
-        od = 0
-        prod_old = 1
-        prod_new = self.strides[old_dims[od]]
-        cur_old_stride = self.strides[old_dims[od]]
-        new_strides = [0]*len(new_shape)
-        while nd < len(new_dims):
-            new_strides[new_dims[nd]] = cur_old_stride
-            prod_new *= new_shape[nd]
-            while prod_new >= prod_old:
-                if prod_new == prod_old:
-                    #Finished an old dim on a match. All is good
-                    od += 1
-                    prod_old *= self.shape[old_dims[od]]
-                    cur_old_stride = self.strides[old_dims[od]]
-                elif prod_new > prod_old:
-                    #Crossed over onto a different old_dim. 
-                    #Strides must be "equal" as per steps
-                    od += 1
-                    if self.strides[old_dims[od]] / self.shape[old_dims[od - 1]] \
-                               <>  self.strides[old_dims[od-1]]:
-                        raise OperationError(space.w_AttributeError, space.wrap(
-                          "incompatible shape for a non-contiguous array"))
-                    prod_old *= self.shape[old_dims[od]]
-            nd += 1 
-        new_backstrides = [0]*len(new_shape)
-        for nd in range(len(new_shape)):
-            new_backstrides[nd] = (new_shape[nd] - 1) * new_strides[nd]
-        self.strides = new_strides
-        self.backstrides = new_backstrides
-        self.shape = new_shape
-        
+
 class VirtualView(VirtualArray):
     pass
 
         self.invalidated()
         self.dtype.setitem(self.storage, item, value)
 
-    def setshape(self, space, new_shape):
-        self.shape = new_shape
-        self.calc_strides(new_shape)
-
     def start_iter(self, res_shape=None):
         if self.order == 'C':
             if res_shape is not None and res_shape != self.shape:
 )
 
 
-class FlatIterator(Wrappable):
+class W_FlatIterator(Wrappable):
     _immutable_fields_ = ['shapelen', 'arr']
 
     def __init__(self, arr):
     def descr_next(self, space):
         if self.iter.done():
             raise OperationError(space.w_StopIteration, space.wrap(''))
-        retVal = self.arr.eval(self.iter)
+        result = self.arr.eval(self.iter)
         self.iter = self.iter.next(self.shapelen)
-        return retVal.wrap(space)
+        return result.wrap(space)
 
 
-FlatIterator.typedef = TypeDef(
+W_FlatIterator.typedef = TypeDef(
     'flatiter',
-    next = interp2app(FlatIterator.descr_next),
+    next = interp2app(W_FlatIterator.descr_next),
 )

pypy/module/micronumpy/test/test_numarray.py

         from numpypy import array
         a = array(range(5))
         assert a[3] == 3
-        #Wrong on two counts: numpy does not allow assigning to Scalar,
-        # and Scalar.shape is not a test of iterator_init, is it?
-        #a = array(1)
-        #assert a[0] == 1
-        #assert a.shape == ()
 
     def test_getitem(self):
         from numpypy import array
         assert a.dtype is dtype(float)
         a = arange(0, 0.8, 0.1)
         assert len(a) == 8
+        assert arange(False, True, True).dtype is dtype(int)