Repository navigation
Add cupyx.scipy.ndimage.label - #3210
Conversation
|
Measured results on Quadro GV100 and CUDA 10.2
|
|
test script |
|
Thanks for adding this. Not surprisingly, I got a bit lower acceleration factors of between 12 and 33 for your test cases on a 1080 GTX Ti GPU. An edge case in the SciPy tests that currently fails here is for 0-dimensional arrays. SciPy has the following behavior: |
|
possibly add to the docstring ( I think handling 0-dim arrays as in SciPy would also require synchronization in that code path as it is necessary to check the value in the array to determine what to return. |
|
Thanks for your feedback, @grlee77 ! I added code and unit tests for 0-dim array cases and the warning about synchronization. |
grlee77
left a comment
There was a problem hiding this comment.
This looks good to me. I just left a couple of minor comments.
| input (cupy.ndarray): The input array. | ||
| structure (array_like or None): A structuring element that defines | ||
| feature connections. ```structure``` must be centersymmetric. If | ||
| None, structure is automatically generated with a squad |
There was a problem hiding this comment.
| None, structure is automatically generated with a squad | |
| None, structure is automatically generated with a squared |
|
|
||
| Args: | ||
| input (cupy.ndarray): The input array. | ||
| structure (array_like or None): A structuring element that defines |
There was a problem hiding this comment.
It is a little odd that this states "array-like" but a cupy.ndarray is not an acceptable array-like.
I see that there is NumPy-based manipulation of the structure in label which seems fine as such small array operations should be faster on the NumPy side. However, should a cupy.ndarray be allowed as input and it can be transfered to the host internally as needed?
There was a problem hiding this comment.
Agreed. I will make a cupy.ndarray available for structure.
|
pfnCI, test this please. |
|
Successfully created a job for commit 72df6d5: |
|
Jenkins CI test (for commit 72df6d5, target branch master) succeeded! |
takagi
left a comment
There was a problem hiding this comment.
Would you check some comments?
|
|
||
|
|
||
| def label(input, structure=None, output=None): | ||
| """Label features in an array |
There was a problem hiding this comment.
Just to follow CuPy's convention in docstrings.
| """Label features in an array | |
| """Labels features in an array. |
|
|
||
| .. seealso:: :func:`scipy.ndimage.label` | ||
| """ | ||
| assert isinstance(input, cupy.ndarray) |
There was a problem hiding this comment.
Would you raise TypeError instead of AssertionError for an user input?
| maxlabel = 0 | ||
| elif input.ndim == 0: | ||
| # 0-dim array | ||
| maxlabel = 0 if (input.item() == 0) else 1 |
There was a problem hiding this comment.
Would you remove the parenthesis here?
| maxlabel = 0 if (input.item() == 0) else 1 | |
| maxlabel = 0 if input.item() == 0 else 1 |
| maxlabel = 0 if (input.item() == 0) else 1 | ||
| output[...] = maxlabel | ||
| else: | ||
| if output.dtype is not numpy.int32: |
There was a problem hiding this comment.
I suppose != operator should be used here instead of is not operator as ndarray.dtype returns dtype object.
| if output.dtype is not numpy.int32: | |
| if output.dtype != numpy.int32: |
| else: | ||
| y = output | ||
| maxlabel = _label(input, structure, y) | ||
| if output.dtype is not numpy.int32: |
There was a problem hiding this comment.
ditto.
| if output.dtype is not numpy.int32: | |
| if output.dtype != numpy.int32: |
takagi
left a comment
There was a problem hiding this comment.
Would you check some comments?
|
Thanks for your review, @takagi . I added fixes based on your comment. Could you check it again? |
|
Thanks! pfnCI, test this please. |
|
Successfully created a job for commit dfba4f9: |
|
Jenkins CI test (for commit dfba4f9, target branch master) succeeded! |
close #3119