Commits

mattip committed ecda1fa

start to pass tests

  • Participants
  • Parent commits 564700d
  • Branches numpypy-nditer

Comments (0)

Files changed (3)

File pypy/module/micronumpy/interp_nditer.py

         backstrides = imp.backstrides
     r = calculate_broadcast_strides(strides, backstrides, imp.shape,
                                     shape, backward)
-    return ArrayIter(imp, shape, r[0], r[1])
+    return ArrayIter(imp, imp.get_size(), shape, r[0], r[1])
 
 def is_backward(imp, order):
     if order == 'K' or (order == 'C' and imp.order == 'C'):
         parse_func_flags(space, self, w_flags)
         self.op_flags = parse_op_arg(space, 'op_flags', w_op_flags,
                                      len(self.seq), parse_op_flag)
-        self.set_op_axes(space, w_op_axes)
+        if not space.is_none(w_op_axes):
+            self.set_op_axes(space, w_op_axes)
         self.iters=[]
         self.shape = iter_shape = shape_agreement_multiple(space, self.seq)
         if self.tracked_index != "":

File pypy/module/micronumpy/iterators.py

 """
 from rpython.rlib import jit
 from pypy.module.micronumpy import support
+from pypy.module.micronumpy.strides import calc_strides
 from pypy.module.micronumpy.base import W_NDimArray
 
 
             dtype = arr.implementation.dtype
         if backward:
             self.slicesize = shape[0]
-            self.gap = [support.product(shape[1:]) * dtype.get_size()]
+            self.gap = [support.product(shape[1:]) * dtype.elsize]
             self.strides = strides[1:]
             self.backstrides = backstrides[1:]
             self.shape = shape[1:]
             self.shape.reverse()
             self.shapelen = len(self.shape)
         else:
-            shape = [support.product(shape)]
-            self.strides, self.backstrides = support.calc_strides(shape,
-                                                           dtype, order)
+            self.shape = [support.product(shape)]
+            self.strides, self.backstrides = calc_strides(shape, dtype, order)
             self.slicesize = support.product(shape)
             self.shapelen = 0
             self.gap = self.strides
         self.offset = offset
 
     def getslice(self):
-        from pypy.module.micronumpy.arrayimpl.concrete import SliceArray
-        return SliceArray(self.offset, self.gap, self.backstrides,
+        from pypy.module.micronumpy.concrete import SliceArray
+        retVal = SliceArray(self.offset, self.gap, self.backstrides,
         [self.slicesize], self.arr.implementation, self.arr, self.dtype)
+        return retVal
 
 def AxisIter(array, shape, axis, cumulative):
     strides = array.get_strides()

File pypy/module/micronumpy/test/test_nditer.py

         BaseNumpyAppTest.setup_class.im_func(cls)
 
     def test_basic(self):
-        from numpypy import arange, nditer
+        from numpy import arange, nditer
         a = arange(6).reshape(2,3)
         r = []
         for x in nditer(a):
         assert r == [0, 1, 2, 3, 4, 5]
 
     def test_order(self):
-        from numpypy import arange, nditer
+        from numpy import arange, nditer
         a = arange(6).reshape(2,3)
         r = []
         for x in nditer(a, order='C'):
         assert r == [0, 3, 1, 4, 2, 5]
 
     def test_readwrite(self):
-        from numpypy import arange, nditer
+        from numpy import arange, nditer
         a = arange(6).reshape(2,3)
         for x in nditer(a, op_flags=['readwrite']):
             x[...] = 2 * x
         assert (a == [[0, 2, 4], [6, 8, 10]]).all()
 
     def test_external_loop(self):
-        from numpypy import arange, nditer, array
+        from numpy import arange, nditer, array
         a = arange(24).reshape(2, 3, 4)
         r = []
         n = 0
         assert e
 
     def test_index(self):
-        from numpypy import arange, nditer, zeros
+        from numpy import arange, nditer
         a = arange(6).reshape(2,3)
 
         r = []
 
     @py.test.mark.xfail(reason="Fortran order not implemented")
     def test_iters_with_different_order(self):
-        from numpypy import nditer, array
+        from numpy import nditer, array
 
         a = array([[1, 2], [3, 4]], order="C")
         b = array([[1, 2], [3, 4]], order="F")
         assert list(it) == zip(range(1, 5), range(1, 5))
 
     def test_interface(self):
-        from numpypy import arange, nditer, zeros
+        from numpy import arange, nditer, zeros
         a = arange(6).reshape(2,3)
         r = []
         it = nditer(a, flags=['f_index'])
         assert str(exc.value).startswith("Iterator flag EXTERNAL_LOOP cannot")
 
     def test_buffered(self):
-        from numpypy import arange, nditer, array
+        from numpy import arange, nditer, array
         a = arange(6).reshape(2,3)
         r = []
         for x in nditer(a, flags=['external_loop', 'buffered'], order='F'):
         assert (array(r) == [0, 3, 1, 4, 2, 5]).all()
 
     def test_op_dtype(self):
-        from numpypy import arange, nditer, sqrt, array
+        from numpy import arange, nditer, sqrt, array
         a = arange(6).reshape(2,3) - 3
         exc = raises(nditer, a, op_dtypes=['complex'])
         assert str(exc.value).startswith("Iterator operand required copying or buffering")
                             1+0j, 1.41421356237+0j]).sum()) < 1e-5
 
     def test_casting(self):
-        from numpypy import arange, nditer
+        from numpy import arange, nditer
         a = arange(6.)
-        exc = raises(nditer, a, flags=['buffered'], op_dtypes=['float32'])
+        exc = raises(ValueError, nditer, a, flags=['buffered'], op_dtypes=['float32'])
         assert str(exc.value).startswith("Iterator operand 0 dtype could not be cast")
         r = []
         for x in nditer(a, flags=['buffered'], op_dtypes=['float32'],
                                 casting='same_kind'):
             r.append(x)
         assert r == [0., 1., 2., 3., 4., 5.]
-        exc = raises(nditer, a, flags=['buffered'],
+        exc = raises(ValueError, nditer, a, flags=['buffered'],
                         op_dtypes=['int32'], casting='same_kind')
         assert str(exc.value).startswith("Iterator operand 0 dtype could not be cast")
         r = []
         b = arange(6)
-        exc = raises(nditer, b, flags=['buffered'], op_dtypes=['float64'],
+        exc = raises(ValueError, nditer, b, flags=['buffered'], op_dtypes=['float64'],
                                 op_flags=['readwrite'], casting='same_kind')
         assert str(exc.value).startswith("Iterator requested dtype could not be cast")
 
     def test_broadcast(self):
-        from numpypy import arange, nditer
+        from numpy import arange, nditer
         a = arange(3)
         b = arange(6).reshape(2,3)
         r = []
             r.append((x, y))
         assert r == [(0, 0), (1, 1), (2, 2), (0, 3), (1, 4), (2, 5)]
         a = arange(2)
-        exc = raises(nditer, [a, b])
+        exc = raises(ValueError, nditer, [a, b])
         assert str(exc.value).find('shapes (2) (2,3)') > 0
 
     def test_outarg(self):
-        from numpypy import nditer, zeros, arange
+        from numpy import nditer, zeros, arange
 
         def square1(a):
             it = nditer([a, None])
         assert str(exc.value).startswith('non-broadcastable output')
 
     def test_outer_product(self):
-        from numpypy import nditer, arange
+        from numpy import nditer, arange
         a = arange(3)
         b = arange(8).reshape(2,4)
         it = nditer([a, b, None], flags=['external_loop'],
             assert (it.operands[2][i] == a[i]*b).all()
 
     def test_reduction(self):
-        from numpypy import nditer, arange, array
+        from numpy import nditer, arange, array
         a = arange(24).reshape(2, 3, 4)
         b = array(0)
         #reduction operands must be readwrite
         assert (it.operands[1] == a.sum(axis=2)).all()
 
     def test_get_dtypes(self):
-        from numpypy import array, dtype, nditer
+        from numpy import array, dtype, nditer
         x = array([1, 2])
         y = array([1.0, 2.0])
         assert nditer([x, y]).dtypes == (dtype("int64"), dtype("float64"))
 
     def test_multi_index(self):
-        import numpypy as np
+        import numpy as np
 
         a = np.arange(6).reshape(2, 3)