[pypy-commit] pypy default: add a writable __pypy_data__ attribute to ndarray: it will be useful to implement the numpy C API in pure python

antocuni noreply at buildbot.pypy.org
Fri Jan 18 18:10:50 CET 2013


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r60181:f62b43e0d1b5
Date: 2013-01-18 17:04 +0000
http://bitbucket.org/pypy/pypy/changeset/f62b43e0d1b5/

Log:	add a writable __pypy_data__ attribute to ndarray: it will be useful
	to implement the numpy C API in pure python

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
@@ -397,6 +397,16 @@
                                                        space.w_False]))
         return w_d
 
+    w_pypy_data = None
+    def fget___pypy_data__(self, space):
+        return self.w_pypy_data
+
+    def fset___pypy_data__(self, space, w_data):
+        self.w_pypy_data = w_data
+
+    def fdel___pypy_data__(self, space):
+        self.w_pypy_data = None
+
     # --------------------- operations ----------------------------
 
     def _unaryop_impl(ufunc_name):
@@ -675,7 +685,10 @@
                           W_NDimArray.descr_set_imag),
     __array_interface__ = GetSetProperty(W_NDimArray.descr_array_iface),
    _from_shape_and_storage = interp2app(descr__from_shape_and_storage,
-                                        as_classmethod=True)
+                                        as_classmethod=True),
+    __pypy_data__ = GetSetProperty(W_NDimArray.fget___pypy_data__,
+                                   W_NDimArray.fset___pypy_data__,
+                                   W_NDimArray.fdel___pypy_data__),
 )
 
 @unwrap_spec(ndmin=int, copy=bool, subok=bool)
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
@@ -2385,3 +2385,14 @@
         assert y[0, 1] == 2
         y[0, 1] = 42
         assert x[1] == 42
+
+    def test___pypy_data__(self):
+        from _numpypy import array
+        x = array([1, 2, 3, 4])
+        x.__pypy_data__ is None
+        obj = object()
+        x.__pypy_data__ = obj
+        assert x.__pypy_data__ is obj
+        del x.__pypy_data__
+        assert x.__pypy_data__ is None
+    


More information about the pypy-commit mailing list