-
Notifications
You must be signed in to change notification settings - Fork 61
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
Remove int-type bug on Windows in skimage.measure.label #72
Merged
rapids-bot
merged 1 commit into
rapidsai:branch-21.08
from
grlee77:fix-label-windows-int
Jul 28, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
) | ||
Comment on lines
-29
to
-31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here |
||
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) | ||
|
@@ -184,11 +172,3 @@ def _kernel_finalize(): | |
""", | ||
"cucim_nd_label_finalize", | ||
) | ||
|
||
|
||
int_types = { | ||
"i": "int", | ||
"H": "unsigned short", | ||
"I": "unsigned int", | ||
"L": "unsigned long long", | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am curious why this exception is no longer needed. What happens if we don't raise this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a private function that is only called here with an input that is hard-coded to
np.int32
.cucim/python/cucim/src/cucim/skimage/measure/_label.py
Lines 120 to 121 in 1aa5802
The kernels in this file originate from CuPy, but have minor modifications here to match
scipy.skimage.measure.label
behavior rather thanscipy.ndimage.label
. The int checking stuff is not in upstream CuPy, I think I had originally added these so we could switch to int64 if needed, but I'm not sure there is a real use case for > 2 billion labels?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what happens if a user does pass in an
int64
array?Should add this most likely would happen just because a user requested a
dtype
ofint
, which would be handled asint64
. Not so much because they need more labels.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will get the following compilation error:
I can add a check in
_label
thatnp.dtype(input) == np.float32
with a message like the old one if you like. That can only happen if users are calling that (private)_label
function directly, though!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. In that case would it make sense to raise in
label
? Also do we want to update this todo?cucim/python/cucim/src/cucim/skimage/measure/_label.py
Lines 16 to 17 in 00cd5d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no restriction on the type of
input
here which is the only parameter passed on to_label
that comes from the user. Thestructure
andlabels
array inputs to_label
are generated internally, not provided by the user.The only way the user can encounter the error cited here #72 (comment) would be if they were to import the private
_label
function fromcucim.skimage.measure._label_kernels
.