Skip to content

Commit

Permalink
BUG: Filters avoid extra copies when operating on NumPy arrays
Browse files Browse the repository at this point in the history
Following #1774, it is safe to return a NumPy array view of the output
itk.Image. This prevents an extra memory allocation and copy.
  • Loading branch information
thewtex committed Apr 22, 2020
1 parent 2de029c commit 8a8dfe5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Wrapping/Generators/Python/itkHelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def image_filter_wrapper(*args, **kwargs):
data_array = itk.xarray_from_image(value)
output_list[index] = data_array
else:
array = itk.array_from_image(value)
array = itk.array_view_from_image(value)
output_list[index] = array
return tuple(output_list)
else:
if isinstance(output, itk.Image):
if have_xarray_input:
output = itk.xarray_from_image(output)
else:
output = itk.array_from_image(output)
output = itk.array_view_from_image(output)
return output
else:
return image_filter(*args, **kwargs)
Expand Down

0 comments on commit 8a8dfe5

Please sign in to comment.