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

Update vendored ndimage code with axes support #813

Open
wants to merge 10 commits into
base: branch-25.02
Choose a base branch
from

Conversation

grlee77
Copy link
Contributor

@grlee77 grlee77 commented Jan 18, 2025

I contributed user-specified axes support to the scipy.ndimage API (for filtering and morphology functions). SciPy 0.15 is the first public release with these changes.

I originally developed this GPU port of the code in a local cuCIM branch, but submitted it upstream to CuPy and got it merged there before opening this MR. See cupy/cupy#8858 (will first appear in CuPy 14.0).

The test cases here were created before I created the CuPy MR and were later updated/integrated into CuPy's existing style in the MR there. I think we may as well keep the extra tests here as a sanity check that the vendored code continues to work as expected.

Additional testing

A few miscellaneous other updates were copied over from CuPy so that the full cupyx.scipy.ndimage test suite patches with the vendored ndimage from cuCIM when applying the following patch to CuPy's test suite (monkey-patches the module to use the one from cuCIM)

diff --git a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_distance_transform.py b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_distance_transform.py
index 97b041c0c..92abce3cb 100644
--- a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_distance_transform.py
+++ b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_distance_transform.py
@@ -6,6 +6,8 @@ import pytest
 import cupy
 from cupy import testing
 import cupyx.scipy.ndimage  # NOQA
+from cucim.skimage._vendored import ndimage as ndi
+cupyx.scipy.ndimage = ndi
 
 try:
     import scipy.ndimage  # NOQA
diff --git a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_filters.py b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_filters.py
index 78cb7c4d0..24726965f 100644
--- a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_filters.py
+++ b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_filters.py
@@ -8,6 +8,8 @@ from cupy.cuda import runtime
 from cupy import testing
 from cupy.exceptions import AxisError
 import cupyx.scipy.ndimage  # NOQA
+from cucim.skimage._vendored import ndimage as ndi
+cupyx.scipy.ndimage = ndi
 
 try:
     import scipy.ndimage  # NOQA
diff --git a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_fourier.py b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_fourier.py
index 5a897a4b8..361b612bb 100644
--- a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_fourier.py
+++ b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_fourier.py
@@ -8,6 +8,8 @@ from cupy.exceptions import AxisError
 import cupyx.scipy.fft  # NOQA
 import cupyx.scipy.fftpack  # NOQA
 import cupyx.scipy.ndimage  # NOQA
+from cucim.skimage._vendored import ndimage as ndi
+cupyx.scipy.ndimage = ndi
 
 try:
     # scipy.fft only available since SciPy 1.4.0
diff --git a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_interpolation.py b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_interpolation.py
index 3308b28c4..16668c53b 100644
--- a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_interpolation.py
+++ b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_interpolation.py
@@ -6,6 +6,8 @@ from cupy.cuda import runtime
 from cupy import testing
 import cupyx.scipy.ndimage
 from cupyx.scipy.ndimage import _util
+from cucim.skimage._vendored import ndimage as ndi
+cupyx.scipy.ndimage = ndi
 
 try:
     import scipy
diff --git a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_measurements.py b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_measurements.py
index e1c06db15..203c3fc29 100644
--- a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_measurements.py
+++ b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_measurements.py
@@ -10,6 +10,8 @@ from cupy import testing
 from cupy import _util
 from cupy._core import _accelerator
 import cupyx.scipy.ndimage  # NOQA
+from cucim.skimage._vendored import ndimage as ndi
+cupyx.scipy.ndimage = ndi
 
 try:
     import scipy
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 8bbcc63d8..6ee5ec86c 100644
--- a/tests/cupyx_tests/scipy_tests/ndimage_tests/test_morphology.py
+++ b/tests/cupyx_tests/scipy_tests/ndimage_tests/test_morphology.py
@@ -4,6 +4,8 @@ import pytest
 
 from cupy import testing
 import cupyx.scipy.ndimage  # NOQA
+from cucim.skimage._vendored import ndimage as ndi
+cupyx.scipy.ndimage = ndi
 
 try:
     import scipy.ndimage  # NOQA

@grlee77 grlee77 added improvement Improves an existing functionality non-breaking Introduces a non-breaking change labels Jan 18, 2025
@grlee77 grlee77 added this to the v25.02.00 milestone Jan 18, 2025
@grlee77 grlee77 requested a review from a team as a code owner January 18, 2025 21:26
behavior does not match elementwise kernel in this edge case
@grlee77 grlee77 force-pushed the grelee/vendored-ndimage-axes-support branch from b74d3d6 to af2fce4 Compare January 19, 2025 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improves an existing functionality non-breaking Introduces a non-breaking change
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant