Skip to content

MAINT Convert int to intp_t ctype def in tree/ related code #27546

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
merged 47 commits into from
Jan 22, 2024

Conversation

adam2392
Copy link
Member

@adam2392 adam2392 commented Oct 7, 2023

Reference Issues/PRs

Follow-on to #27352 and #27539

Related to #25572

What does this implement/fix? Explain your changes.

Converts int to intp_t where applicable

Any other comments?

LOC such as:

cdef int compare_SIZE_t(const void* a, const void* b) noexcept nogil:
    """Comparison function for sort."""
    return <int>((<intp_t*>a)[0] - (<intp_t*>b)[0])

in splitter.pyx is not convertible as it is used in a libc stdlib function, which seems to only accept int?

Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
@github-actions
Copy link

github-actions bot commented Oct 7, 2023

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 339e30d. Link to the linter CI: here

Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
@adam2392 adam2392 changed the title [MAINT] Convert int to intp_t ctype def [MAINT] Convert int to intp_t ctype def in tree/ related code Oct 9, 2023
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.

Thanks, @adam2392.

I would also keep compare_SIZE_t unchanged.

Here are a few comments and suggestions.

@jjerphan jjerphan changed the title [MAINT] Convert int to intp_t ctype def in tree/ related code MAINT Convert int to intp_t ctype def in tree/ related code Nov 3, 2023
adam2392 and others added 4 commits November 3, 2023 16:09
Signed-off-by: Adam Li <adam2392@gmail.com>
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
@jjerphan
Copy link
Member

jjerphan commented Dec 9, 2023

Just a small gentle follow-up.

@glemaitre: do you think we can merge this PR?

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a pass. I think it makes sense to use intp_t whenever we have variable linked to indexing and sizing. A lot of changes are related to return value that are usually 0, 1, -1 because it is related to failure. In general, those are always int by convention and I don't think it make sense to do something different.

@@ -1383,6 +1383,7 @@ def _compute_partial_dependence_recursion(self, grid, target_features):
averaged_predictions = np.zeros(
(self.n_trees_per_iteration_, grid.shape[0]), dtype=Y_DTYPE
)
target_features = np.asarray(target_features, dtype=np.intp, order="C")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the docstring above to specify the dtype of grid and target_features.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1061,6 +1061,8 @@ def _compute_partial_dependence_recursion(self, grid, target_features):
averaged_predictions = np.zeros(
(n_trees_per_stage, grid.shape[0]), dtype=np.float64, order="C"
)
target_features = np.asarray(target_features, dtype=np.intp, order="C")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can specify the dtype of grid and target_features in the docstring as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1403,6 +1403,7 @@ def _compute_partial_dependence_recursion(self, grid, target_features):
averaged_predictions = np.zeros(
shape=grid.shape[0], dtype=np.float64, order="C"
)
target_features = np.asarray(target_features, dtype=np.intp, order="C")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also update the grid and target_features dtype in the docstring.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

adam2392 and others added 2 commits January 17, 2024 12:18
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
Copy link
Member Author

@adam2392 adam2392 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed your comments in 8b9a5dc

@@ -1383,6 +1383,7 @@ def _compute_partial_dependence_recursion(self, grid, target_features):
averaged_predictions = np.zeros(
(self.n_trees_per_iteration_, grid.shape[0]), dtype=Y_DTYPE
)
target_features = np.asarray(target_features, dtype=np.intp, order="C")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1061,6 +1061,8 @@ def _compute_partial_dependence_recursion(self, grid, target_features):
averaged_predictions = np.zeros(
(n_trees_per_stage, grid.shape[0]), dtype=np.float64, order="C"
)
target_features = np.asarray(target_features, dtype=np.intp, order="C")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -1403,6 +1403,7 @@ def _compute_partial_dependence_recursion(self, grid, target_features):
averaged_predictions = np.zeros(
shape=grid.shape[0], dtype=np.float64, order="C"
)
target_features = np.asarray(target_features, dtype=np.intp, order="C")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 66 to 69
cdef intp_t IS_FIRST = 1
cdef intp_t IS_NOT_FIRST = 0
cdef intp_t IS_LEFT = 1
cdef intp_t IS_NOT_LEFT = 0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure that makes sense. I changed

@adam2392 adam2392 requested a review from glemaitre January 17, 2024 17:44
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @adam2392

@glemaitre glemaitre enabled auto-merge (squash) January 22, 2024 15:12
@glemaitre
Copy link
Member

Enabling auto-merge.

@glemaitre glemaitre merged commit b38b7f3 into scikit-learn:main Jan 22, 2024
@adam2392 adam2392 deleted the ctypeint branch January 22, 2024 16:15
glemaitre added a commit to glemaitre/scikit-learn that referenced this pull request Feb 10, 2024
…ikit-learn#27546)

Signed-off-by: Adam Li <adam2392@gmail.com>
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
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.

3 participants