-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
MAINT Remove -Wsign-compare warnings when compiling sklearn.neighbors._quad_tree #25271
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
MAINT Remove -Wsign-compare warnings when compiling sklearn.neighbors._quad_tree #25271
Conversation
CC: @jjerphan , @glemaitre |
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.
A unique but potentially important remark.
@@ -575,7 +575,7 @@ cdef class _QuadTree: | ||
if capacity == self.capacity and self.cells != NULL: | ||
return 0 | ||
|
||
if capacity == SIZE_MAX: | ||
if <size_t> capacity == SIZE_MAX: |
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.
Another alternative which is:
if capacity == <SIZE_t> SIZE_MAX:
but I think what you chose brings a correct conversion: capacity
is SIZE_t
AKA cnp.npy_intp
AKA Py_intptr_t
AKA "an integer that is the size of a pointer on the platform" whilst, SIZE_MAX
is the maximum value for uint64
stored as a uint64
I suppose.
I find using SIZE_MAX
for this encoding weird. Would there be configuration for which this would break? Previously, was capacity
cast to a size_t
(likely a uint64
on most architecture nowadays) or was SIZE_MAX
cast to a Py_intptr_t
?
@OmarManzoor: can you provide the warning you get on your platform?
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.
This is the precise warning:
sklearn/neighbors/_quad_tree.c:8389:34: warning: comparison of integers of different signs: '__pyx_t_7sklearn_9neighbors_10_quad_tree_SIZE_t' (aka 'long') and 'unsigned long' [-Wsign-compare] __pyx_t_1 = ((__pyx_v_capacity == SIZE_MAX) != 0);
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.
LGTM, this change is safe to me.
Thank you @OmarManzoor.
LGTM. Thanks @OmarManzoor |
…._quad_tree (scikit-learn#25271) Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
…._quad_tree (scikit-learn#25271) Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Reference Issues/PRs
Towards #24875
What does this implement/fix? Explain your changes.
Any other comments?
None