Commits

Maciej Fijalkowski  committed eb5dcdf

Start working towards ravel and applevel array_string, nothing works!

  • Participants
  • Parent commits 616ba3d
  • Branches numpy-back-to-applevel

Comments (0)

Files changed (5)

File lib_pypy/numpypy/core/fromnumeric.py

     array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
 
     """
-    raise NotImplementedError('Waiting on interp level method')
-
+    if not hasattr(a, 'ravel'):
+        a = numpypy.array(a)
+    return a.ravel(order=order)
 
 def nonzero(a):
     """

File pypy/module/micronumpy/interp_numarray.py

             "len() of unsized object"))
 
     def descr_repr(self, space):
+        cache = get_appbridge_cache(space)
+        if cache.w_array_repr is None:
+            return space.wrap(self.dump_data())
+        return space.call_function(cache.w_array_repr, self)
+
         res = StringBuilder()
         res.append("array(")
         concrete = self.get_concrete_or_scalar()
         res.append(")")
         return space.wrap(res.build())
 
+    def dump_data(self):
+        concr = self.get_concrete()
+        i = concr.create_iter()
+        first = True
+        s = StringBuilder()
+        s.append('array([')
+        while not i.done():
+            if first:
+                first = False
+            else:
+                s.append(', ')
+            s.append(concr.dtype.itemtype.str_format(concr.getitem(i.offset)))
+            i = i.next(len(concr.shape))
+        s.append('])')
+        return s.build()
+
     def descr_str(self, space):
         cache = get_appbridge_cache(space)
         if cache.w_array_str is None:
-            raise OperationError(space.w_RuntimeError, space.wrap(
-                "str function not set"))
+            return space.wrap(self.dump_data())
         return space.call_function(cache.w_array_str, self)
         
         ret = StringBuilder()
         return space.wrap(W_NDimSlice(concrete.start, strides,
                                       backstrides, shape, concrete))
 
+    def descr_ravel(self, space, w_order=None):
+        if not space.is_w(w_order, space.w_None):
+            raise OperationError(space.w_NotImplementedError, space.wrap(
+                "order not implemented"))
+        return self.descr_reshape(space, [space.wrap(-1)])
+
     def descr_get_flatiter(self, space):
         return space.wrap(W_FlatIterator(self))
 
 
     T = GetSetProperty(BaseArray.descr_get_transpose),
     flat = GetSetProperty(BaseArray.descr_get_flatiter),
+    ravel = interp2app(BaseArray.descr_ravel),
 
     mean = interp2app(BaseArray.descr_mean),
     sum = interp2app(BaseArray.descr_sum),

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

         assert array(x, copy=False) is x
         assert array(x, copy=True) is not x
 
+    def test_ravel(self):
+        from _numpypy import arange
+        assert (arange(3).ravel() == arange(3)).all()
+        assert (arange(6).reshape(2, 3).ravel() == arange(6)).all()
+        print arange(6).reshape(2, 3).T.ravel()
+        assert (arange(6).reshape(2, 3).T.ravel() == [0, 3, 1, 4, 2, 5]).all()
+        
+
 class AppTestSupport(BaseNumpyAppTest):
     def setup_class(cls):
         import struct

File pypy/module/test_lib_pypy/numpypy/core/test_fromnumeric.py

         # x = ones((1, 2, 3))
         # assert transpose(x, (1, 0, 2)).shape == (2, 1, 3)
 
+    def test_ravel(self):
+        from numpypy import ravel
+        

File pypy/module/test_lib_pypy/numpypy/core/test_numeric.py

         assert base_repr(-12, 10) == '-12'
         assert base_repr(-12, 10, 4) == '-000012'
         assert base_repr(-12, 4) == '-30'
+
+class AppTestRepr(BaseNumpyAppTest):
+    def test_repr(self):
+        from numpypy import array
+        assert repr(array([1, 2, 3, 4])) == 'array([1, 2, 3, 4])'