Commit e7957560 authored by Marcelo Duarte Trevisani's avatar Marcelo Duarte Trevisani
Browse files

Add: numpy_to_vtk keeps the numpy reference in memory

parent 43a556f4
......@@ -124,6 +124,19 @@ class TestNumpySupport(Testing.vtkTest):
self.assertEqual(vtk_array.GetTuple3(0), (1., 3., 5.))
self.assertEqual(vtk_array.GetTuple3(1), (13., 15., 17.))
def testNumpyReferenceWhenDelete(self):
"Test if the vtk array keeps the numpy reference in memory"
np_array = numpy.array([[1., 3., 5.], [13., 15., 17.]], 'd')
vtk_array = numpy_to_vtk(np_array)
del np_array
np_array = numpy.array([])
import gc
gc.collect()
self.assertEqual(vtk_array.GetTuple3(0), (1., 3., 5.))
self.assertEqual(vtk_array.GetTuple3(1), (13., 15., 17.))
def testNumpyReduce(self):
"Test that reducing methods return scalars."
vtk_array = vtk.vtkLongArray()
......
......@@ -179,6 +179,8 @@ def numpy_to_vtk(num_array, deep=0, array_type=None):
copy = result_array.NewInstance()
copy.DeepCopy(result_array)
result_array = copy
else:
result_array._numpy_reference = z
return result_array
def numpy_to_vtkIdTypeArray(num_array, deep=0):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment