Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged

Conversation

OmarManzoor
Copy link
Contributor

Reference Issues/PRs

Towards #24875

What does this implement/fix? Explain your changes.

  • Cast capacity to size_t when comparing with SIZE_MAX which is of type size_t

Any other comments?

None

@OmarManzoor
Copy link
Contributor Author

CC: @jjerphan , @glemaitre

Copy link
Member

@jjerphan jjerphan left a 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:
Copy link
Member

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?

Copy link
Contributor Author

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);

Copy link
Member

@jjerphan jjerphan left a 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.

@jjerphan jjerphan added Quick Review For PRs that are quick to review Waiting for Second Reviewer First reviewer is done, need a second one! labels Jan 12, 2023
@glemaitre glemaitre self-requested a review January 14, 2023 16:21
@glemaitre glemaitre merged commit d3811dc into scikit-learn:main Jan 14, 2023
@glemaitre
Copy link
Member

LGTM. Thanks @OmarManzoor

@OmarManzoor OmarManzoor deleted the cython_quad_tree_wsign_compare branch January 15, 2023 07:13
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 20, 2023
…._quad_tree (scikit-learn#25271)

Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
jjerphan pushed a commit to jjerphan/scikit-learn that referenced this pull request Jan 20, 2023
…._quad_tree (scikit-learn#25271)

Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
@reshamas reshamas removed Waiting for Second Reviewer First reviewer is done, need a second one! Quick Review For PRs that are quick to review labels Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.