From d9090eeb64462d172a061fab14235d2cd41bd5da Mon Sep 17 00:00:00 2001 From: Alejandro Saucedo Date: Fri, 7 May 2021 16:59:21 +0100 Subject: [PATCH] Added test to ensure ownership by numpy array --- python/test/test_tensor_types.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/python/test/test_tensor_types.py b/python/test/test_tensor_types.py index fb11083fd..ee645d850 100644 --- a/python/test/test_tensor_types.py +++ b/python/test/test_tensor_types.py @@ -207,3 +207,26 @@ def test_type_unsigned_int(): assert np.all(tensor_out.data() == arr_in_a * arr_in_b) +def test_tensor_numpy_ownership(): + + arr_in = np.array([1, 2, 3]) + + m = kp.Manager() + + t = m.tensor(arr_in) + + # This should increment refcount for tensor sharedptr + td = t.data() + + assert td.base.is_init() == True + assert np.all(td == arr_in) + + del t + + assert td.base.is_init() == True + assert np.all(td == arr_in) + + m.destroy() + + assert td.base.is_init() == False +