summaryrefslogtreecommitdiff
path: root/numpy/f2py/tests/test_array_from_pyobj.py
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2021-02-07 21:54:48 +0200
committerPearu Peterson <pearu.peterson@gmail.com>2021-02-07 22:25:27 +0200
commit4874af99fcb9c9af869536a2bd390e9e94d07b8a (patch)
treefb2dabeeefb741df176d21059b929a4ab905b454 /numpy/f2py/tests/test_array_from_pyobj.py
parentea557b2c6c681f029cfee1ea3ddf0b6e87f2dab5 (diff)
downloadnumpy-4874af99fcb9c9af869536a2bd390e9e94d07b8a.tar.gz
ENH: Share memory of read-only intent(in) arrays. Closes #16347
Diffstat (limited to 'numpy/f2py/tests/test_array_from_pyobj.py')
-rw-r--r--numpy/f2py/tests/test_array_from_pyobj.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/numpy/f2py/tests/test_array_from_pyobj.py b/numpy/f2py/tests/test_array_from_pyobj.py
index 0524da342..77149e4e7 100644
--- a/numpy/f2py/tests/test_array_from_pyobj.py
+++ b/numpy/f2py/tests/test_array_from_pyobj.py
@@ -233,6 +233,7 @@ class Array:
order=self.intent.is_intent('c') and 'C' or 'F')
assert_(self.pyarr.dtype == typ,
repr((self.pyarr.dtype, typ)))
+ self.pyarr.setflags(write=self.arr.flags['WRITEABLE'])
assert_(self.pyarr.flags['OWNDATA'], (obj, intent))
self.pyarr_attr = wrap.array_attrs(self.pyarr)
@@ -326,6 +327,18 @@ class TestSharedMemory:
else:
assert_(not a.has_shared_memory(), repr(t.dtype))
+ @pytest.mark.parametrize('write', ['w', 'ro'])
+ @pytest.mark.parametrize('order', ['C', 'F'])
+ @pytest.mark.parametrize('inp', ['2seq', '23seq'])
+ def test_in_nocopy(self, write, order, inp):
+ """Test if intent(in) array can be passed without copies
+ """
+ seq = getattr(self, 'num' + inp)
+ obj = np.array(seq, dtype=self.type.dtype, order=order)
+ obj.setflags(write=(write == 'w'))
+ a = self.array(obj.shape, ((order=='C' and intent.in_.c) or intent.in_), obj)
+ assert a.has_shared_memory()
+
def test_inout_2seq(self):
obj = np.array(self.num2seq, dtype=self.type.dtype)
a = self.array([len(self.num2seq)], intent.inout, obj)