Author: Matti Picus <matti.pi...@gmail.com>
Branch: ndarray-subtype
Changeset: r65176:97487dbdf597
Date: 2013-07-03 22:21 +0300
http://bitbucket.org/pypy/pypy/changeset/97487dbdf597/

Log:    pass existing tests

diff --git a/pypy/module/micronumpy/base.py b/pypy/module/micronumpy/base.py
--- a/pypy/module/micronumpy/base.py
+++ b/pypy/module/micronumpy/base.py
@@ -53,7 +53,6 @@
             impl = concrete.ConcreteArrayNotOwning(shape, dtype, order, 
strides,
                                                 backstrides, storage)
         if subtype_and_space[0]:
-            print 'creating subclass',subtype_and_space
             space = subtype_and_space[1]
             subtype = subtype_and_space[0]
             ret = space.allocate_instance(W_NDimArray, subtype)
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
@@ -619,9 +619,9 @@
             "trace not implemented yet"))
 
     def descr_view(self, space, w_dtype=None, w_type=None) :
-        if w_type is not None:
-            raise OperationError(space.w_NotImplementedError, space.wrap(
-                "view(... type=<class>) not implemented yet"))
+        if not w_type and w_dtype and 
w_dtype.issubtype(space.gettypefor(W_NDimArray)):
+            w_type = w_dtype
+            w_dtype = None
         if w_dtype:
             dtype = space.interp_w(interp_dtype.W_Dtype,
                 space.call_function(space.gettypefor(interp_dtype.W_Dtype),
@@ -651,7 +651,12 @@
                     raise OperationError(space.w_ValueError, space.wrap(
                         "new type not compatible with array."))
                 new_shape[-1] = new_shape[-1] * old_itemsize / new_itemsize
-        return W_NDimArray(impl.get_view(self, dtype, new_shape))
+        v = impl.get_view(self, dtype, new_shape)
+        if w_type is not None:
+            ret = space.allocate_instance(W_NDimArray, w_type)
+            W_NDimArray.__init__(ret, v)
+            return ret
+        return W_NDimArray(v)
 
 
     # --------------------- operations ----------------------------
@@ -887,20 +892,22 @@
         self.implementation = 
W_NDimArray.from_shape_and_storage([space.int_w(i) for i in 
space.listview(shape)], rffi.str2charp(space.str_w(storage), 
track_allocation=False), dtype, owning=True).implementation
 
 
-@unwrap_spec(offset=int)
+@unwrap_spec(offset=int, order=str)
 def descr_new_array(space, w_subtype, w_shape, w_dtype=None, w_buffer=None,
-                    offset=0, w_strides=None, w_order=None):
+                    offset=0, w_strides=None, order='C'):
     if (offset != 0 or not space.is_none(w_strides) or
-        not space.is_none(w_order) or
         not space.is_none(w_buffer)):
         raise OperationError(space.w_NotImplementedError,
                              space.wrap("unsupported param"))
     dtype = space.interp_w(interp_dtype.W_Dtype,
           space.call_function(space.gettypefor(interp_dtype.W_Dtype), w_dtype))
     shape = _find_shape(space, w_shape, dtype)
+    print 'desc_new_array(space,',w_subtype,',',shape,',',dtype,'...)'
     if not shape:
         return W_NDimArray.new_scalar(space, dtype)
-    return W_NDimArray.from_shape(shape, dtype)
+    if space.is_w(w_subtype, space.gettypefor(W_NDimArray)):
+        return W_NDimArray.from_shape(shape, dtype, order)
+    return W_NDimArray.from_shape(shape, dtype, order, (w_subtype, space))
 
 @unwrap_spec(addr=int)
 def descr__from_shape_and_storage(space, w_cls, w_shape, addr, w_dtype, 
w_subclass=None):
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
@@ -1458,20 +1458,32 @@
         skip('not implemented yet')
         assert s.view('double') < 7e-323
 
-    def test_subclass_view(self):
+    def test_subtype_view(self):
         from numpypy import ndarray, array
         class matrix(ndarray):
             def __new__(subtype, data, dtype=None, copy=True):
-                print 'matix.__new__(',subtype,',',data,'...)'
                 if isinstance(data, matrix):
                     return data
                 return data.view(subtype)
         a = array(range(5))
         b = matrix(a)
-        print type(b),b
-        assert False
+        assert isinstance(b, matrix)
         assert (b == a).all()
 
+    def test_subtype_base(self):
+        from numpypy import ndarray, dtype
+        class C(ndarray):
+            def __new__(subtype, shape, dtype):
+                self = ndarray.__new__(subtype, shape, dtype)
+                self.id = 'subtype'
+                return self
+        a = C([2, 2], int)
+        assert isinstance(a, C)
+        assert isinstance(a, ndarray)
+        assert a.shape == (2, 2)
+        assert a.dtype is dtype(int)
+        assert a.id == 'subtype'
+
     def test_tolist_scalar(self):
         from numpypy import int32, bool_
         x = int32(23)
@@ -2905,7 +2917,7 @@
 class AppTestLongDoubleDtypes(BaseNumpyAppTest):
     def setup_class(cls):
         from pypy.module.micronumpy import Module
-        print dir(Module.interpleveldefs)
+        #print dir(Module.interpleveldefs)
         if not Module.interpleveldefs.get('longfloat', None):
             py.test.skip('no longdouble types yet')
         BaseNumpyAppTest.setup_class.im_func(cls)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to