[pypy-commit] pypy numpy-multidim: testing

mattip noreply at buildbot.pypy.org
Sun Oct 30 23:19:03 CET 2011


Author: mattip
Branch: numpy-multidim
Changeset: r48615:0d9e53f59c5d
Date: 2011-10-31 00:17 +0200
http://bitbucket.org/pypy/pypy/changeset/0d9e53f59c5d/

Log:	testing

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
@@ -249,7 +249,7 @@
         new_sig = signature.Signature.find_sig([
             NDimSlice.signature, self.signature
         ])
-        res = "array(" + NDimSlice(concrete, new_sig, [], self.shape[:]).tostr(True)
+        res = "array(" + NDimSlice(concrete, new_sig, [], self.shape[:]).tostr(True, indent='       ')
         dtype = concrete.find_dtype()
         if (dtype is not space.fromcache(interp_dtype.W_Float64Dtype) and
             dtype is not space.fromcache(interp_dtype.W_Int64Dtype)) or not self.find_size():
@@ -588,7 +588,6 @@
     _immutable_fields_ = ['shape[*]', 'chunks[*]']
 
     def __init__(self, parent, signature, chunks, shape):
-        print 'NDimSlice.__init__(...,',chunks,',',shape,')'
         ViewArray.__init__(self, parent, signature, shape)
         self.chunks = chunks
         self.shape_reduction = 0
@@ -662,21 +661,17 @@
             if k != 0:
                 item *= shape[k]
             k += 1
-            try:
-                item += index[i]
-            except:
-               import pdb;pdb.set_trace()
+            item += index[i]
             i += 1
         return item
-    def tostr(self, comma):
+    def tostr(self, comma,indent=' '):
         ret = ''
         dtype = self.find_dtype()
         ndims = len(self.shape)#-self.shape_reduction
         if ndims>2:
             ret += '['
             for i in range(self.shape[0]):
-                res = NDimSlice(self.parent, self.signature, [(i,0,0,1)], self.shape[1:]).tostr(comma)
-                ret += '\n '.join(res.split('\n'))
+                ret += NDimSlice(self.parent, self.signature, [(i,0,0,1)], self.shape[1:]).tostr(commai,indent=indent+' ')
                 if i+1<self.shape[0]:
                     ret += ',\n\n'
             ret += ']'
@@ -688,7 +683,7 @@
                                                     for j in range(self.shape[1])])
                 ret += ']'
                 if i+1< self.shape[0]:
-                    ret += ',\n       '
+                    ret += ',\n' + indent
             ret += ']'
         elif ndims==1:
             ret += '['
@@ -703,7 +698,7 @@
                                                     for j in range(self.shape[0])])
             ret += ']'
         else:
-            ret += 'shape=%s, reduction=%s'%(str(self.shape), str(self.shape_reduction))
+            ret += '[]'
         return ret
 class NDimArray(BaseArray):
     def __init__(self, size, shape, dtype):
diff --git a/pypy/module/micronumpy/test/test_numarray.py b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -80,6 +80,9 @@
         a = zeros(2002)
         b = a[::2]
         assert repr(b) == "array([0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0])"
+        a = array((range(5),range(5,10)), dtype="int16")
+        b=a[1,2:]
+        assert repr(b) == "array([7, 8, 9], dtype=int16)"
 
     def test_str(self):
         from numpy import array, zeros
@@ -100,6 +103,9 @@
         a = array(range(5), dtype="int16")
         assert str(a) == "[0 1 2 3 4]"
 
+        a = array((range(5),range(5,10)), dtype="int16")
+        assert str(a) == "[[0 1 2 3 4],\n [5 6 7 8 9]]"
+
     def test_str_slice(self):
         from numpy import array, zeros
         a = array(range(5), float)
@@ -108,6 +114,9 @@
         a = zeros(2002)
         b = a[::2]
         assert str(b) == "[0.0 0.0 0.0 ..., 0.0 0.0 0.0]"
+        a = array((range(5),range(5,10)), dtype="int16")
+        b=a[1,2:]
+        assert str(b) == "[7 8 9]"
 
     def test_getitem(self):
         from numpy import array


More information about the pypy-commit mailing list