Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport] Fix overloading ambiguity in ndimage filters #6242

Merged
merged 1 commit into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cupyx/scipy/ndimage/_filters_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def _generate_nd_kernel(name, pre, found, post, mode, w_shape, int_type,
format(j=j, type=int_type))
else:
boundary = _util._generate_boundary_condition_ops(
mode, 'ix_{}'.format(j), 'xsize_{}'.format(j))
mode, 'ix_{}'.format(j), 'xsize_{}'.format(j), int_type)
# CArray: last line of string becomes inds[{j}] = ix_{j};
loops.append('''
for (int iw_{j} = 0; iw_{j} < {wsize}; iw_{j}++)
Expand Down
7 changes: 5 additions & 2 deletions cupyx/scipy/ndimage/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ def _generate_boundary_condition_ops(mode, ix, xsize, int_t="int",
}}'''.format(ix=ix, xsize=xsize, min=min_func)
elif mode == 'nearest':
ops = '''
{ix} = {min}({max}({ix}, 0), {xsize} - 1);'''.format(
ix=ix, xsize=xsize, min=min_func, max=max_func)
{ix} = {min}({max}(({T}){ix}, ({T})0), ({T})({xsize} - 1));'''.format(
ix=ix, xsize=xsize, min=min_func, max=max_func,
# force using 64-bit signed integer for ptrdiff_t,
# see cupy/cupy#6048
T=('int' if int_t == 'int' else 'long long'))
elif mode == 'grid-wrap':
ops = '''
{ix} %= {xsize};
Expand Down
11 changes: 11 additions & 0 deletions tests/cupyx_tests/scipy_tests/ndimage_tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ def test_filter(self, xp, scp):
return self._filter(xp, scp)


@testing.with_requires('scipy')
class TestNearestFilterEdgeCase:

@testing.numpy_cupy_allclose(atol=1e-5, rtol=1e-5, scipy_name='scp')
def test_filter(self, xp, scp):
# Use a large input to check any compilation error, see cupy/cupy#6048
return scp.ndimage.gaussian_filter(
testing.shaped_random((26, 3, 52, 70, 50), xp, xp.float32),
[1, 1, 1, 1, 1], mode='nearest')


def dummy_deriv_func(input, axis, output, mode, cval, *args, **kwargs):
# For testing generic_laplace and generic_gradient_magnitude. Doesn't test
# mode, cval, or extra argument but those are tested indirectly with
Expand Down