Skip to content

Commit

Permalink
Remove int-type bug on Windows in skimage.measure.label (#72)
Browse files Browse the repository at this point in the history
A windows user reported an issue with `skimage.measure.label` in the older `cupyimg` repository: mritools/cupyimg#21.

It seems the same issue is present here, but should be resolved by this PR. I don't think we can easily add a test case on our current linux-based CI as the issue has to do with the NumPy dtype character used to represent the `numpy.int32` dtype. We may want to wait on merging until the fix is confirmed in mritools/cupyimg#21

I think I originally introduced this `int_types` dict with the intention of also supporting >32-bit integers, but it was incomplete and still used `int32` in the actual implementation. This PR just removes this dict altogether and we can revisit the function if we get a request for int64 support.

Authors:
  - Gregory R. Lee (https://github.com/grlee77)

Approvers:
  - https://github.com/jakirkham

URL: #72
  • Loading branch information
grlee77 authored Jul 28, 2021
1 parent ece3977 commit f421e79
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions python/cucim/src/cucim/skimage/measure/_label_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,10 @@ def _label(x, structure, y, greyscale_mode=False):
y_shape = cupy.array(y.shape, dtype=numpy.int32)
count = cupy.zeros(2, dtype=numpy.int32)
_kernel_init()(x, y)
try:
int_t = int_types[y.dtype.char]
except KeyError:
raise ValueError("y must have int32, uint16, uint32 or uint64 dtype")
if int_t != "int":
raise NotImplementedError(
"Currently only 32-bit integer case is implemented"
)
if greyscale_mode:
_kernel_connect(True, int_t)(
x, y_shape, dirs, ndirs, x.ndim, y, size=y.size
)
_kernel_connect(True)(x, y_shape, dirs, ndirs, x.ndim, y, size=y.size)
else:
_kernel_connect(False, int_t)(
y_shape, dirs, ndirs, x.ndim, y, size=y.size
)
_kernel_connect(False)(y_shape, dirs, ndirs, x.ndim, y, size=y.size)
_kernel_count()(y, count, size=y.size)
maxlabel = int(count[0]) # synchronize
labels = cupy.empty(maxlabel, dtype=numpy.int32)
Expand Down Expand Up @@ -184,11 +172,3 @@ def _kernel_finalize():
""",
"cucim_skimage_measure_label_finalize",
)


int_types = {
"i": "int",
"H": "unsigned short",
"I": "unsigned int",
"L": "unsigned long long",
}

0 comments on commit f421e79

Please sign in to comment.