[pypy-commit] pypy ndarray-view: test scalars and ndarray, start to implement

mattip noreply at buildbot.pypy.org
Fri Jun 28 14:40:39 CEST 2013


Author: Matti Picus <matti.picus at gmail.com>
Branch: ndarray-view
Changeset: r65057:78f0fb200c25
Date: 2013-06-28 13:05 +0300
http://bitbucket.org/pypy/pypy/changeset/78f0fb200c25/

Log:	test scalars and ndarray, start to implement

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
@@ -618,8 +618,17 @@
             "trace not implemented yet"))
 
     def descr_view(self, space, w_dtype=None, w_type=None) :
-        raise OperationError(space.w_NotImplementedError, space.wrap(
-            "view not implemented yet"))
+        if w_type is not None:
+            raise OperationError(space.w_NotImplementedError, space.wrap(
+                "view(... type=<class>) not implemented yet"))
+        if w_dtype:
+            dtype = space.interp_w(interp_dtype.W_Dtype,
+                space.call_function(space.gettypefor(interp_dtype.W_Dtype),
+                                                                   w_dtype))
+        else:
+            dtype = self.get_dtype()
+        return W_NDimArray(self.implementation.get_view(self, dtype))
+
 
     # --------------------- operations ----------------------------
 
@@ -996,6 +1005,7 @@
     round    = interp2app(W_NDimArray.descr_round),
     data     = GetSetProperty(W_NDimArray.descr_get_data),
     diagonal = interp2app(W_NDimArray.descr_diagonal),
+    view = interp2app(W_NDimArray.descr_view),
 
     ctypes = GetSetProperty(W_NDimArray.descr_get_ctypes), # XXX unimplemented
     __array_interface__ = GetSetProperty(W_NDimArray.descr_array_iface),
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
@@ -1412,7 +1412,7 @@
         assert a[2].imag == -5
 
     def test_ndarray_view(self):
-        from numpypy import array, int8, int16, dtype
+        from numpypy import array, int8, int16, dtype, int64
         x = array([(1, 2)], dtype=[('a', int8), ('b', int8)])
         y = x.view(dtype=int16)
         assert y[0] == 513
@@ -1420,6 +1420,14 @@
         y[0] = 670
         assert x['a'] == -98
         assert x['b'] == 2
+        f = array([1000, -1234], dtype='i')
+        nnp = self.non_native_prefix
+        d = f.view(dtype=nnp + 'i')
+        assert (d == [-402456576,  788267007]).all()
+        s = int64(12)
+        exc = raises(TypeError, s.view, dtype='int8')
+        assert exc.value[0] == "view() takes no keyword arguments"
+        assert s.view('double') < 7e-323
 
     def test_tolist_scalar(self):
         from numpypy import int32, bool_


More information about the pypy-commit mailing list