From adcb217de766dd6fef99895ed1a33bf78a97d14b Mon Sep 17 00:00:00 2001 From: Genevieve Buckley <30920819+GenevieveBuckley@users.noreply.github.com> Date: Wed, 21 Apr 2021 17:38:14 +1000 Subject: [PATCH] Fix meta type and dtype for ndmorph functions (#206) --- dask_image/ndmorph/__init__.py | 4 ++++ tests/test_dask_image/test_ndmorph/test_cupy_ndmorph.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dask_image/ndmorph/__init__.py b/dask_image/ndmorph/__init__.py index fa2e1526..774a8c22 100644 --- a/dask_image/ndmorph/__init__.py +++ b/dask_image/ndmorph/__init__.py @@ -38,6 +38,7 @@ def binary_closing(image, result = binary_erosion( result, structure=structure, iterations=iterations, origin=origin ) + result._meta = image._meta.astype(bool) return result @@ -62,6 +63,7 @@ def binary_dilation(image, brute_force=brute_force, border_value=border_value ) + result._meta = image._meta.astype(bool) return result @@ -86,6 +88,7 @@ def binary_erosion(image, brute_force=brute_force, border_value=border_value ) + result._meta = image._meta.astype(bool) return result @@ -108,5 +111,6 @@ def binary_opening(image, result = binary_dilation( result, structure=structure, iterations=iterations, origin=origin ) + result._meta = image._meta.astype(bool) return result diff --git a/tests/test_dask_image/test_ndmorph/test_cupy_ndmorph.py b/tests/test_dask_image/test_ndmorph/test_cupy_ndmorph.py index 22fec6d6..3c6f6984 100644 --- a/tests/test_dask_image/test_ndmorph/test_cupy_ndmorph.py +++ b/tests/test_dask_image/test_ndmorph/test_cupy_ndmorph.py @@ -28,4 +28,9 @@ def array(): def test_cupy_ndmorph(array, func): """Test convolve & correlate filters with cupy input arrays.""" result = func(array) - result.compute() + assert result.dtype == bool + assert result._meta.dtype == bool + assert isinstance(result._meta, cupy.ndarray) + computed = result.compute() + assert computed.dtype == bool + assert isinstance(computed, cupy.ndarray)