diff --git a/cupyx/scipy/ndimage/morphology.py b/cupyx/scipy/ndimage/morphology.py index f9f14f5847c..14fea9dc91c 100644 --- a/cupyx/scipy/ndimage/morphology.py +++ b/cupyx/scipy/ndimage/morphology.py @@ -154,9 +154,6 @@ def _binary_erosion(input, structure, iterations, mask, output, border_value, except TypeError: raise TypeError('iterations parameter should be an integer') - if not input.flags.c_contiguous: - # TODO: grlee77: is C-contiguity required? - input = cupy.ascontiguousarray(input) if input.dtype.kind == 'c': raise TypeError('Complex type not supported') if structure is None: @@ -166,7 +163,6 @@ def _binary_erosion(input, structure, iterations, mask, output, border_value, if structure.ndim != input.ndim: raise RuntimeError('structure and input must have same dimensionality') if not structure.flags.c_contiguous: - # TODO: grlee77: is C-contiguity required? structure = cupy.ascontiguousarray(structure) if structure.size < 1: raise RuntimeError('structure must not be empty') @@ -175,8 +171,7 @@ def _binary_erosion(input, structure, iterations, mask, output, border_value, if mask.shape != input.shape: raise RuntimeError('mask and input must have equal sizes') if not mask.flags.c_contiguous: - # TODO: grlee77: current indexing requires C contiguous arrays. - mask = cupy.asacontiguousarray(mask) + mask = cupy.ascontiguousarray(mask) masked = True else: masked = False diff --git a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_morphology.py b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_morphology.py index 13010af7399..94f2d234ed2 100644 --- a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_morphology.py +++ b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_morphology.py @@ -349,6 +349,37 @@ def test_binary_erosion_and_dilation(self, xp, scp): return self._filter(xp, scp, x) +@testing.parameterize(*( + testing.product({ + 'x_dtype': [numpy.int8, numpy.float32], + 'shape': [(16, 24)], + 'filter': ['binary_erosion', 'binary_dilation'], + 'iterations': [1, 2], + 'contiguity': ['C', 'F', 'none']} + )) +) +@testing.gpu +@testing.with_requires('scipy') +class BinaryErosionAndDilationContiguity(unittest.TestCase): + def _filter(self, xp, scp, x): + filter = getattr(scp.ndimage, self.filter) + ndim = len(self.shape) + structure = scp.ndimage.generate_binary_structure(ndim, 1) + return filter(x, structure, iterations=self.iterations, mask=None, + output=None, border_value=0, origin=0, brute_force=True) + + @testing.numpy_cupy_array_equal(scipy_name='scp') + def test_binary_erosion_and_dilation_input_contiguity(self, xp, scp): + rstate = numpy.random.RandomState(5) + x = rstate.randn(*self.shape) > 0.3 + x = xp.asarray(x, dtype=self.x_dtype) + if self.contiguity == 'F': + x = xp.asfortranarray(x) + elif self.contiguity == 'none': + x = x[::2, ::3] + return self._filter(xp, scp, x) + + @testing.parameterize(*( testing.product({ 'shape': [(3, 4), (2, 3, 4), (1, 2, 3, 4)],