Skip to content

Commit

Permalink
Merge pull request #688 from rapidsai/branch-24.02
Browse files Browse the repository at this point in the history
Forward-merge branch-24.02 to branch-24.04
  • Loading branch information
GPUtester authored Jan 29, 2024
2 parents 2654a7a + caade43 commit baabda6
Show file tree
Hide file tree
Showing 40 changed files with 444 additions and 369 deletions.
5 changes: 3 additions & 2 deletions conda/environments/all_cuda-118_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies:
- nbsphinx
- ninja
- numpy>=1.21.3
- numpydoc
- numpydoc>=1.5
- nvcc_linux-64=11.8
- openslide-python>=1.3.0
- pip
Expand All @@ -41,8 +41,9 @@ dependencies:
- pytest-xdist
- pytest>=6.2.4
- python>=3.8,<3.11
- pywavelets>=1.0
- recommonmark
- scikit-image>=0.19.0,<0.22.0a0
- scikit-image>=0.19.0,<0.23.0a0
- scipy
- sphinx<6
- sysroot_linux-64==2.17
Expand Down
5 changes: 3 additions & 2 deletions conda/environments/all_cuda-120_arch-x86_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies:
- nbsphinx
- ninja
- numpy>=1.21.3
- numpydoc
- numpydoc>=1.5
- openslide-python>=1.3.0
- pip
- pooch>=1.6.0
Expand All @@ -40,8 +40,9 @@ dependencies:
- pytest-xdist
- pytest>=6.2.4
- python>=3.8,<3.11
- pywavelets>=1.0
- recommonmark
- scikit-image>=0.19.0,<0.22.0a0
- scikit-image>=0.19.0,<0.23.0a0
- scipy
- sphinx<6
- sysroot_linux-64==2.17
Expand Down
4 changes: 2 additions & 2 deletions conda/recipes/cucim/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ requirements:
- libcucim ={{ version }}
- numpy 1.21
- python
- scikit-image >=0.19.0,<0.22.0a0
- scikit-image >=0.19.0,<0.23.0a0
- scipy
run:
- {{ pin_compatible('cuda-version', max_pin='x', min_pin='x') }}
Expand All @@ -69,7 +69,7 @@ requirements:
- lazy_loader >=0.1
- libcucim ={{ version }}
- python
- scikit-image >=0.19.0,<0.22.0a0
- scikit-image >=0.19.0,<0.23.0a0
- scipy
run_constrained:
- openslide-python >=1.3.0
Expand Down
9 changes: 7 additions & 2 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ dependencies:
packages:
- ipython
- nbsphinx
- numpydoc
- numpydoc>=1.5
- pydata-sphinx-theme
- recommonmark
# TODO: sphinx upper version limit can likely be removed after pydata 0.13
Expand Down Expand Up @@ -223,7 +223,7 @@ dependencies:
- output_types: [conda, requirements, pyproject]
packages:
- lazy_loader>=0.1
- scikit-image>=0.19.0,<0.22.0a0
- scikit-image>=0.19.0,<0.23.0a0
- scipy
- output_types: conda
packages:
Expand Down Expand Up @@ -260,6 +260,7 @@ dependencies:
- pytest-xdist
- tifffile>=2022.7.28
- pooch>=1.6.0 # needed to download scikit-image sample data
- pywavelets>=1.0
- output_types: [conda]
packages:
- imagecodecs>=2021.6.8
Expand All @@ -276,3 +277,7 @@ dependencies:
- matplotlib
- opencv-python-headless>=4.6
- click
- output_types: [pyproject]
packages:
# Already added to requirements via docs. This is for tests.
- numpydoc>=1.5
6 changes: 4 additions & 2 deletions python/cucim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies = [
"cupy-cuda11x>=12.0.0",
"lazy_loader>=0.1",
"numpy",
"scikit-image>=0.19.0,<0.22.0a0",
"scikit-image>=0.19.0,<0.23.0a0",
"scipy",
] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`.
classifiers = [
Expand Down Expand Up @@ -64,6 +64,7 @@ test = [
"click",
"imagecodecs>=2021.6.8; platform_machine=='x86_64'",
"matplotlib",
"numpydoc>=1.5",
"opencv-python-headless>=4.6",
"openslide-python>=1.3.0; platform_machine=='x86_64'",
"pooch>=1.6.0",
Expand All @@ -72,6 +73,7 @@ test = [
"pytest-lazy-fixture>=0.6.3",
"pytest-xdist",
"pytest>=6.2.4",
"pywavelets>=1.0",
"tifffile>=2022.7.28",
] # This list was generated by `rapids-dependency-file-generator`. To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`.
developer = [
Expand All @@ -83,7 +85,7 @@ developer = [
docs = [
"ipython",
"nbsphinx",
"numpydoc",
"numpydoc>=1.5",
"pydata-sphinx-theme",
"recommonmark",
"sphinx<6",
Expand Down
Empty file added python/cucim/src/cucim/py.typed
Empty file.
47 changes: 6 additions & 41 deletions python/cucim/src/cucim/skimage/_shared/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,7 @@

import cucim.skimage._vendored.ndimage as ndi

from .._shared.utils import _supported_float_type, convert_to_float, warn


class _PatchClassRepr(type):
"""Control class representations in rendered signatures."""

def __repr__(cls):
return f"<{cls.__name__}>"


class ChannelAxisNotSet(metaclass=_PatchClassRepr):
"""Signal that the `channel_axis` parameter is not set.
This is a proxy object, used to signal to `skimage.filters.gaussian` that
the `channel_axis` parameter has not been set, in which case the function
will determine whether a color channel is present. We cannot use ``None``
for this purpose as it has its own meaning which indicates that the given
image is grayscale.
This automatic behavior was broken in v0.19, recovered but deprecated in
v0.20 and will be removed in v0.21.
"""
from .._shared.utils import _supported_float_type, convert_to_float


def gaussian(
Expand All @@ -41,7 +22,7 @@ def gaussian(
preserve_range=False,
truncate=4.0,
*,
channel_axis=ChannelAxisNotSet,
channel_axis=None,
):
"""Multi-dimensional Gaussian filter.
Expand Down Expand Up @@ -77,12 +58,10 @@ def gaussian(
to channels.
.. warning::
Automatic detection of the color channel based on the old deprecated
``multichannel=None`` was broken in version 0.19. In 0.20 this
behavior is recovered. The last axis of an `image` with dimensions
(M, N, 3) is interpreted as a color channel if `channel_axis` is
not set. Starting with release 23.04.02, ``channel_axis=None`` will
be used as the new default value.
In versions prior to 24.02, the last axis of an `image` with
dimensions (M, N, 3) was interpreted as a color channel if
`channel_axis` was not set. Starting with release 24.02,
``channel_axis=None`` will be used as the new default value.
Returns
-------
Expand Down Expand Up @@ -133,21 +112,7 @@ def gaussian(
>>> from skimage.data import astronaut
>>> image = cp.array(astronaut())
>>> filtered_img = gaussian(image, sigma=1, channel_axis=-1)
"""
if channel_axis is ChannelAxisNotSet:
if image.ndim == 3 and image.shape[-1] == 3:
warn(
"Automatic detection of the color channel was deprecated in "
"v0.19, and `channel_axis=None` will be the new default in "
"v0.21. Set `channel_axis=-1` explicitly to silence this "
"warning.",
FutureWarning,
stacklevel=2,
)
channel_axis = -1
else:
channel_axis = None

# CuPy Backend: refactor to avoid overhead of cp.any(cp.asarray(sigma))
sigma_msg = "Sigma values less than zero are not valid"
Expand Down
11 changes: 9 additions & 2 deletions python/cucim/src/cucim/skimage/_vendored/_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
from operator import mul

import cupy
import numpy

# TODO: when minimum numpy dependency is 1.25 use:
# np.exceptions.AxisError instead of AxisError
# and remove this try-except
try:
from numpy import AxisError
except ImportError:
from numpy.exceptions import AxisError

try:
# try importing Cython-based private axis handling functions from CuPy
Expand Down Expand Up @@ -37,7 +44,7 @@ def _normalize_axis_index(axis, ndim): # NOQA
if axis < 0:
axis += ndim
if not (0 <= axis < ndim):
raise numpy.AxisError("axis out of bounds")
raise AxisError("axis out of bounds")
return axis

def _normalize_axis_indices(axes, ndim): # NOQA
Expand Down
10 changes: 9 additions & 1 deletion python/cucim/src/cucim/skimage/color/colorconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
)
from ..util import dtype, dtype_limits

# TODO: when minimum numpy dependency is 1.25 use:
# np.exceptions.AxisError instead of AxisError
# and remove this try-except
try:
from numpy import AxisError
except ImportError:
from numpy.exceptions import AxisError


def convert_colorspace(arr, fromspace, tospace, *, channel_axis=-1):
"""Convert an image array to a new color space.
Expand Down Expand Up @@ -173,7 +181,7 @@ def _validate_channel_axis(channel_axis, ndim):
if not isinstance(channel_axis, int):
raise TypeError("channel_axis must be an integer")
if channel_axis < -ndim or channel_axis >= ndim:
raise np.AxisError("channel_axis exceeds array dimensions")
raise AxisError("channel_axis exceeds array dimensions")


@cp.memoize(for_each_device=True)
Expand Down
10 changes: 9 additions & 1 deletion python/cucim/src/cucim/skimage/color/tests/test_colorconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
)
from cucim.skimage.util import img_as_float, img_as_float32, img_as_ubyte

# TODO: when minimum numpy dependency is 1.25 use:
# np.exceptions.AxisError instead of AxisError
# and remove this try-except
try:
from numpy import AxisError
except ImportError:
from numpy.exceptions import AxisError

data_dir = os.path.join(os.path.dirname(__file__), "data")


Expand Down Expand Up @@ -133,7 +141,7 @@ def test_rgba2rgb_error_channel_axis_invalid(self, channel_axis):

@pytest.mark.parametrize("channel_axis", [-4, 3])
def test_rgba2rgb_error_channel_axis_out_of_range(self, channel_axis):
with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
rgba2rgb(self.img_rgba, channel_axis=channel_axis)

def test_rgba2rgb_error_rgb(self):
Expand Down
49 changes: 2 additions & 47 deletions python/cucim/src/cucim/skimage/feature/__init__.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,3 @@
from ._basic_features import multiscale_basic_features
from ._canny import canny
from ._daisy import daisy
from .blob import blob_dog, blob_doh, blob_log
from .corner import (
corner_foerstner,
corner_harris,
corner_kitchen_rosenfeld,
corner_peaks,
corner_shi_tomasi,
hessian_matrix,
hessian_matrix_det,
hessian_matrix_eigvals,
shape_index,
structure_tensor,
structure_tensor_eigenvalues,
)
from .match import match_descriptors
from .peak import peak_local_max
from .template import match_template
import lazy_loader as lazy

__all__ = [
"canny",
"daisy",
"multiscale_basic_features",
"peak_local_max",
"structure_tensor",
"structure_tensor_eigenvalues",
"structure_tensor_eigvals",
"hessian_matrix",
"hessian_matrix_det",
"hessian_matrix_eigvals",
"shape_index",
"corner_kitchen_rosenfeld",
"corner_harris",
"corner_shi_tomasi",
"corner_foerstner",
# 'corner_subpix',
"corner_peaks",
# 'corner_moravec',
# 'corner_fast',
# 'corner_orientations',
"match_template",
"match_descriptors",
"blob_dog",
"blob_log",
"blob_doh",
]
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)
47 changes: 47 additions & 0 deletions python/cucim/src/cucim/skimage/feature/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Explicitly setting `__all__` is necessary for type inference engines
# to know which symbols are exported. See
# https://peps.python.org/pep-0484/#stub-files

__all__ = [
"canny",
"daisy",
"peak_local_max",
"structure_tensor",
"structure_tensor_eigenvalues",
"hessian_matrix",
"hessian_matrix_det",
"hessian_matrix_eigvals",
"shape_index",
"corner_kitchen_rosenfeld",
"corner_harris",
"corner_shi_tomasi",
"corner_foerstner",
"corner_peaks",
"match_template",
"match_descriptors",
"blob_dog",
"blob_doh",
"blob_log",
"multiscale_basic_features",
]

from ._basic_features import multiscale_basic_features
from ._canny import canny
from ._daisy import daisy
from .blob import blob_dog, blob_doh, blob_log
from .corner import (
corner_foerstner,
corner_harris,
corner_kitchen_rosenfeld,
corner_peaks,
corner_shi_tomasi,
hessian_matrix,
hessian_matrix_det,
hessian_matrix_eigvals,
shape_index,
structure_tensor,
structure_tensor_eigenvalues,
)
from .match import match_descriptors
from .peak import peak_local_max
from .template import match_template
2 changes: 1 addition & 1 deletion python/cucim/src/cucim/skimage/feature/peak.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _get_high_intensity_peaks(image, mask, num_peaks, min_distance, p_norm):
coord = cp.nonzero(mask)
intensities = image[coord]
# Highest peak first
idx_maxsort = cp.argsort(-intensities)
idx_maxsort = cp.argsort(-intensities, kind="stable")
coord = cp.column_stack(coord)[idx_maxsort]

if np.isfinite(num_peaks):
Expand Down
Loading

0 comments on commit baabda6

Please sign in to comment.