# Buggy code
def _min_or_max_filter(
    input, size, ftprnt, structure, output, mode, cval, origin, func
):
    # structure is used by morphology.grey_erosion() and grey_dilation()
    # and not by the regular min/max filters

    sizes, ftprnt, structure = _filters_core._check_size_footprint_structure(
        input.ndim, size, ftprnt, structure
    )

    if sizes is not None:
        # Seperable filter, run as a series of 1D filters
        fltr = minimum_filter1d if func == "min" else maximum_filter1d
        return _filters_core._run_1d_filters(
            [fltr if size > 1 else None for size in sizes],
            input,
            sizes,
            output,
            mode,
            cval,
            origin,
        )

    origins, int_type = _filters_core._check_nd_args(
        input, ftprnt, mode, origin, "footprint"
    )
    if structure is not None and structure.ndim != input.ndim:
        raise RuntimeError("structure array has incorrect shape")

    if ftprnt.size == 0:
        return cupy.zeros_like(input)
    offsets = _filters_core._origins_to_offsets(origins, ftprnt.shape)
    kernel = _get_min_or_max_kernel(
        mode,
        ftprnt.shape,
        func,
        offsets,
        float(cval),
        int_type,
        has_structure=structure is not None,
        has_central_value=bool(ftprnt[offsets]),
    )
    return _filters_core._call_kernel(
        kernel, input, ftprnt, output, structure, weights_dtype=bool
    )


# Traceback (cupy_backends.cuda.libs.nvrtc.NVRTCError)
/home/croat/.local/share/virtualenvs/starmap-T47byR32/lib/python3.8/site-packages/cupyx/scipy/ndimage/interpolation.py:15: UserWarning: In the current feature the default order of shift is 1. It is different from scipy.ndimage and can change in the future.
warnings.warn('In the current feature the default order of {} is 1. '
Traceback (most recent call last):
File "/home/croat/.local/share/virtualenvs/starmap-T47byR32/lib/python3.8/site-packages/cupy/cuda/compiler.py", line 516, in compile
nvrtc.compileProgram(self.ptr, options)
File "cupy_backends/cuda/libs/nvrtc.pyx", line 108, in cupy_backends.cuda.libs.nvrtc.compileProgram
File "cupy_backends/cuda/libs/nvrtc.pyx", line 120, in cupy_backends.cuda.libs.nvrtc.compileProgram
File "cupy_backends/cuda/libs/nvrtc.pyx", line 58, in cupy_backends.cuda.libs.nvrtc.check_status
cupy_backends.cuda.libs.nvrtc.NVRTCError: NVRTC_ERROR_COMPILATION (6)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/croat/.local/share/virtualenvs/starmap-T47byR32/lib/python3.8/site-packages/cupyx/scipy/ndimage/interpolation.py", line 379, in shift
kern(input, shift, output)
File "cupy/core/_kernel.pyx", line 821, in cupy.core._kernel.ElementwiseKernel.__call__
File "cupy/core/_kernel.pyx", line 846, in cupy.core._kernel.ElementwiseKernel._get_elementwise_kernel
File "cupy/_util.pyx", line 103, in cupy._util.memoize.decorator.ret
File "cupy/core/_kernel.pyx", line 639, in cupy.core._kernel._get_elementwise_kernel
File "cupy/core/_kernel.pyx", line 37, in cupy.core._kernel._get_simple_elementwise_kernel
File "cupy/core/_kernel.pyx", line 60, in cupy.core._kernel._get_simple_elementwise_kernel
File "cupy/core/core.pyx", line 1937, in cupy.core.core.compile_with_cache
File "/home/croat/.local/share/virtualenvs/starmap-T47byR32/lib/python3.8/site-packages/cupy/cuda/compiler.py", line 335, in compile_with_cache
return _compile_with_cache_cuda(
File "/home/croat/.local/share/virtualenvs/starmap-T47byR32/lib/python3.8/site-packages/cupy/cuda/compiler.py", line 402, in _compile_with_cache_cuda
ptx, mapping = compile_using_nvrtc(
File "/home/croat/.local/share/virtualenvs/starmap-T47byR32/lib/python3.8/site-packages/cupy/cuda/compiler.py", line 173, in compile_using_nvrtc
return _compile(source, options, cu_path,
File "/home/croat/.local/share/virtualenvs/starmap-T47byR32/lib/python3.8/site-packages/cupy/cuda/compiler.py", line 157, in _compile
ptx, mapping = prog.compile(options, log_stream)
File "/home/croat/.local/share/virtualenvs/starmap-T47byR32/lib/python3.8/site-packages/cupy/cuda/compiler.py", line 527, in compile
raise CompileException(log, self.src, self.name, options,
cupy.cuda.compiler.CompileException: /tmp/tmpbp6idobr/064ead033e63783c4dfe62433771dbed_2.cubin.cu(28): error: invalid type conversion

/tmp/tmpbp6idobr/064ead033e63783c4dfe62433771dbed_2.cubin.cu(20): warning: variable "s" was declared but never referenced

/tmp/tmpbp6idobr/064ead033e63783c4dfe62433771dbed_2.cubin.cu(20): warning: variable "t" was declared but never referenced

1 error detected in the compilation of "/tmp/tmpbp6idobr/064ead033e63783c4dfe62433771dbed_2.cubin.cu".

# Fixed code
def _min_or_max_filter(
    input, size, ftprnt, structure, output, mode, cval, origin, func
):
    # structure is used by morphology.grey_erosion() and grey_dilation()
    # and not by the regular min/max filters

    sizes, ftprnt, structure = _filters_core._check_size_footprint_structure(
        input.ndim, size, ftprnt, structure
    )
    if cval is cupy.nan:
        raise NotImplementedError("NaN cval is unsupported")

    if sizes is not None:
        # Seperable filter, run as a series of 1D filters
        fltr = minimum_filter1d if func == "min" else maximum_filter1d
        return _filters_core._run_1d_filters(
            [fltr if size > 1 else None for size in sizes],
            input,
            sizes,
            output,
            mode,
            cval,
            origin,
        )

    origins, int_type = _filters_core._check_nd_args(
        input, ftprnt, mode, origin, "footprint"
    )
    if structure is not None and structure.ndim != input.ndim:
        raise RuntimeError("structure array has incorrect shape")

    if ftprnt.size == 0:
        return cupy.zeros_like(input)
    offsets = _filters_core._origins_to_offsets(origins, ftprnt.shape)
    kernel = _get_min_or_max_kernel(
        mode,
        ftprnt.shape,
        func,
        offsets,
        float(cval),
        int_type,
        has_structure=structure is not None,
        has_central_value=bool(ftprnt[offsets]),
    )
    return _filters_core._call_kernel(
        kernel, input, ftprnt, output, structure, weights_dtype=bool
    )