[pypy-commit] pypy buffer-interface: modifying ctor.py, might as well add a test for pypy/numpy issues #52, #53

mattip pypy.commits at gmail.com
Thu Sep 1 01:49:37 EDT 2016


Author: Matti Picus <matti.picus at gmail.com>
Branch: buffer-interface
Changeset: r86808:3b99b5a021ee
Date: 2016-09-01 08:48 +0300
http://bitbucket.org/pypy/pypy/changeset/3b99b5a021ee/

Log:	modifying ctor.py, might as well add a test for pypy/numpy issues
	#52, #53

diff --git a/pypy/module/micronumpy/test/test_subtype.py b/pypy/module/micronumpy/test/test_subtype.py
--- a/pypy/module/micronumpy/test/test_subtype.py
+++ b/pypy/module/micronumpy/test/test_subtype.py
@@ -702,3 +702,32 @@
         ret = obj.sum()
         print type(ret)
         assert ret.info == 'spam'
+
+    def test_ndarray_subclass_assigns_base(self):
+        import numpy as np
+        init_called = []
+        class _DummyArray(object):
+            """ Dummy object that just exists to hang __array_interface__ dictionaries
+            and possibly keep alive a reference to a base array.
+            """
+            def __init__(self, interface, base=None):
+                self.__array_interface__ = interface
+                init_called.append(1)
+                self.base = base
+
+        x = np.zeros(10)
+        d = _DummyArray(x.__array_interface__, base=x)
+        y = np.array(d, copy=False)
+        assert sum(init_called) == 1
+        assert y.base is d
+
+        x = np.zeros((0,), dtype='float32')
+        intf = x.__array_interface__.copy()
+        intf["strides"] = x.strides
+        x.__array_interface__["strides"] = x.strides
+        d = _DummyArray(x.__array_interface__, base=x)
+        y = np.array(d, copy=False)
+        assert sum(init_called) == 2
+        assert y.base is d
+
+


More information about the pypy-commit mailing list