-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
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
Conversation
Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
int
to intp_t
ctype defint
to intp_t
ctype def in tree/
related code
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.
Thanks, @adam2392.
I would also keep compare_SIZE_t
unchanged.
Here are a few comments and suggestions.
int
to intp_t
ctype def in tree/
related codeint
to intp_t
ctype def in tree/
related code
Signed-off-by: Adam Li <adam2392@gmail.com>
Co-authored-by: Julien Jerphanion <git@jjerphan.xyz>
Just a small gentle follow-up. @glemaitre: do you think we can merge this PR? |
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.
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") |
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.
Can you update the docstring above to specify the dtype of grid
and target_features
.
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.
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") | |||
|
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 can specify the dtype of grid
and target_features
in the docstring as well.
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.
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") |
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 can also update the grid
and target_features
dtype in the docstring.
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.
Done
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
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.
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") |
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.
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") | |||
|
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.
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") |
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.
Done
sklearn/tree/_tree.pyx
Outdated
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 |
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.
Sure that makes sense. I changed
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. Thanks @adam2392
Enabling auto-merge. |
…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>
Reference Issues/PRs
Follow-on to #27352 and #27539
Related to #25572
What does this implement/fix? Explain your changes.
Converts
int
tointp_t
where applicableAny other comments?
LOC such as:
in
splitter.pyx
is not convertible as it is used in alibc
stdlib function, which seems to only acceptint
?