-
-
Notifications
You must be signed in to change notification settings - Fork 26k
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
Changes from all commits
48a58e8
4e2232e
357400e
e74a0cf
e2a1204
90a4233
9d95769
b0cc454
32dc901
ae05493
cdde707
753fb60
6b32bab
e66a3dd
df7a31a
defe311
502ca72
bc410d0
877dc32
b41e857
fdabf1d
4ef948f
ab7abcc
765bead
ae10cc5
bb1713b
ae3d69b
0014b13
a099db9
e348e4a
45598a6
310d11c
3dfaea0
346d4d4
2dea684
ee91a14
88b9efb
276abdd
cb8ffe6
ebb7155
3d1622c
8b9a5dc
d7e2c01
0dc4a12
ba0e0b0
229f4d7
339e30d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1042,10 +1042,10 @@ def _compute_partial_dependence_recursion(self, grid, target_features): | |
|
||
Parameters | ||
---------- | ||
grid : ndarray of shape (n_samples, n_target_features) | ||
grid : ndarray of shape (n_samples, n_target_features), dtype=np.float32 | ||
The grid points on which the partial dependence should be | ||
evaluated. | ||
target_features : ndarray of shape (n_target_features,) | ||
target_features : ndarray of shape (n_target_features,), dtype=np.intp | ||
The set of target features for which the partial dependence | ||
should be evaluated. | ||
|
||
|
@@ -1068,6 +1068,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 commentThe reason will be displayed to describe this comment to others. Learn more. You can specify the dtype of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
for stage in range(n_estimators): | ||
for k in range(n_trees_per_stage): | ||
tree = self.estimators_[stage, k].tree_ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1357,10 +1357,10 @@ def _compute_partial_dependence_recursion(self, grid, target_features): | |
|
||
Parameters | ||
---------- | ||
grid : ndarray, shape (n_samples, n_target_features) | ||
grid : ndarray, shape (n_samples, n_target_features), dtype=np.float32 | ||
The grid points on which the partial dependence should be | ||
evaluated. | ||
target_features : ndarray, shape (n_target_features) | ||
target_features : ndarray, shape (n_target_features), dtype=np.intp | ||
The set of target features for which the partial dependence | ||
should be evaluated. | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Can you update the docstring above to specify the dtype of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
for predictors_of_ith_iteration in self._predictors: | ||
for k, predictor in enumerate(predictors_of_ith_iteration): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1387,22 +1387,23 @@ def _compute_partial_dependence_recursion(self, grid, target_features): | |
|
||
Parameters | ||
---------- | ||
grid : ndarray of shape (n_samples, n_target_features) | ||
grid : ndarray of shape (n_samples, n_target_features), dtype=np.float32 | ||
The grid points on which the partial dependence should be | ||
evaluated. | ||
target_features : ndarray of shape (n_target_features) | ||
target_features : ndarray of shape (n_target_features), dtype=np.intp | ||
The set of target features for which the partial dependence | ||
should be evaluated. | ||
|
||
Returns | ||
------- | ||
averaged_predictions : ndarray of shape (n_samples,) | ||
averaged_predictions : ndarray of shape (n_samples,), dtype=np.float64 | ||
The value of the partial dependence function on each grid point. | ||
""" | ||
grid = np.asarray(grid, dtype=DTYPE, order="C") | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. you can also update the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
self.tree_.compute_partial_dependence( | ||
grid, target_features, averaged_predictions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,8 +193,12 @@ cdef class Splitter: | |
self.criterion.init_sum_missing() | ||
return 0 | ||
|
||
cdef int node_reset(self, intp_t start, intp_t end, | ||
float64_t* weighted_n_node_samples) except -1 nogil: | ||
cdef int node_reset( | ||
self, | ||
intp_t start, | ||
intp_t end, | ||
float64_t* weighted_n_node_samples | ||
) except -1 nogil: | ||
"""Reset splitter on node samples[start:end]. | ||
|
||
Returns -1 in case of failure to allocate memory (and raise MemoryError) | ||
|
@@ -559,7 +563,7 @@ cdef inline int node_split_best( | |
cdef inline void sort(float32_t* feature_values, intp_t* samples, intp_t n) noexcept nogil: | ||
if n == 0: | ||
return | ||
cdef int maxd = 2 * <int>log(n) | ||
cdef intp_t maxd = 2 * <intp_t>log(n) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
introsort(feature_values, samples, n, maxd) | ||
|
||
|
||
|
@@ -593,7 +597,7 @@ cdef inline float32_t median3(float32_t* feature_values, intp_t n) noexcept nogi | |
# Introsort with median of 3 pivot selection and 3-way partition function | ||
# (robust to repeated elements, e.g. lots of zero features). | ||
cdef void introsort(float32_t* feature_values, intp_t *samples, | ||
intp_t n, int maxd) noexcept nogil: | ||
intp_t n, intp_t maxd) noexcept nogil: | ||
cdef float32_t pivot | ||
cdef intp_t i, l, r | ||
|
||
|
@@ -1340,7 +1344,11 @@ cdef class SparsePartitioner: | |
|
||
|
||
cdef int compare_SIZE_t(const void* a, const void* b) noexcept nogil: | ||
"""Comparison function for sort.""" | ||
"""Comparison function for sort. | ||
|
||
This must return an `int` as it is used by stdlib's qsort, which expects | ||
an `int` return value. | ||
""" | ||
return <int>((<intp_t*>a)[0] - (<intp_t*>b)[0]) | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,10 +63,10 @@ cdef float64_t INFINITY = np.inf | |
cdef float64_t EPSILON = np.finfo('double').eps | ||
|
||
# Some handy constants (BestFirstTreeBuilder) | ||
cdef int IS_FIRST = 1 | ||
cdef int IS_NOT_FIRST = 0 | ||
cdef int IS_LEFT = 1 | ||
cdef int IS_NOT_LEFT = 0 | ||
cdef bint IS_FIRST = 1 | ||
cdef bint IS_NOT_FIRST = 0 | ||
cdef bint IS_LEFT = 1 | ||
cdef bint IS_NOT_LEFT = 0 | ||
|
||
TREE_LEAF = -1 | ||
TREE_UNDEFINED = -2 | ||
|
@@ -177,10 +177,10 @@ cdef class DepthFirstTreeBuilder(TreeBuilder): | |
X, y, sample_weight = self._check_input(X, y, sample_weight) | ||
|
||
# Initial capacity | ||
cdef int init_capacity | ||
cdef intp_t init_capacity | ||
|
||
if tree.max_depth <= 10: | ||
init_capacity = <int> (2 ** (tree.max_depth + 1)) - 1 | ||
init_capacity = <intp_t> (2 ** (tree.max_depth + 1)) - 1 | ||
else: | ||
init_capacity = 2047 | ||
|
||
|
@@ -696,32 +696,32 @@ cdef class Tree: | |
|
||
Attributes | ||
---------- | ||
node_count : int | ||
node_count : intp_t | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that I agree with the changes below because they are all linked to some sort of indexing types. |
||
The number of nodes (internal nodes + leaves) in the tree. | ||
|
||
capacity : int | ||
capacity : intp_t | ||
The current capacity (i.e., size) of the arrays, which is at least as | ||
great as `node_count`. | ||
|
||
max_depth : int | ||
max_depth : intp_t | ||
The depth of the tree, i.e. the maximum depth of its leaves. | ||
|
||
children_left : array of int, shape [node_count] | ||
children_left : array of intp_t, shape [node_count] | ||
children_left[i] holds the node id of the left child of node i. | ||
For leaves, children_left[i] == TREE_LEAF. Otherwise, | ||
children_left[i] > i. This child handles the case where | ||
X[:, feature[i]] <= threshold[i]. | ||
|
||
children_right : array of int, shape [node_count] | ||
children_right : array of intp_t, shape [node_count] | ||
children_right[i] holds the node id of the right child of node i. | ||
For leaves, children_right[i] == TREE_LEAF. Otherwise, | ||
children_right[i] > i. This child handles the case where | ||
X[:, feature[i]] > threshold[i]. | ||
|
||
n_leaves : int | ||
n_leaves : intp_t | ||
Number of leaves in the tree. | ||
|
||
feature : array of int, shape [node_count] | ||
feature : array of intp_t, shape [node_count] | ||
feature[i] holds the feature to split on, for the internal node i. | ||
|
||
threshold : array of float64_t, shape [node_count] | ||
|
@@ -734,7 +734,7 @@ cdef class Tree: | |
impurity[i] holds the impurity (i.e., the value of the splitting | ||
criterion) at node i. | ||
|
||
n_node_samples : array of int, shape [node_count] | ||
n_node_samples : array of intp_t, shape [node_count] | ||
n_node_samples[i] holds the number of training samples reaching node i. | ||
|
||
weighted_n_node_samples : array of float64_t, shape [node_count] | ||
|
@@ -797,7 +797,7 @@ cdef class Tree: | |
|
||
# TODO: Convert n_classes to cython.integral memory view once | ||
# https://github.com/cython/cython/issues/5243 is fixed | ||
def __cinit__(self, int n_features, cnp.ndarray n_classes, int n_outputs): | ||
def __cinit__(self, intp_t n_features, cnp.ndarray n_classes, intp_t n_outputs): | ||
"""Constructor.""" | ||
cdef intp_t dummy = 0 | ||
size_t_dtype = np.array(dummy).dtype | ||
|
@@ -1343,7 +1343,7 @@ cdef class Tree: | |
return arr | ||
|
||
def compute_partial_dependence(self, float32_t[:, ::1] X, | ||
int[::1] target_features, | ||
const intp_t[::1] target_features, | ||
float64_t[::1] out): | ||
"""Partial dependence of the response on the ``target_feature`` set. | ||
|
||
|
@@ -1379,7 +1379,7 @@ cdef class Tree: | |
dtype=np.intp) | ||
intp_t sample_idx | ||
intp_t feature_idx | ||
int stack_size | ||
intp_t stack_size | ||
float64_t left_sample_frac | ||
float64_t current_weight | ||
float64_t total_weight # used for sanity check only | ||
|
@@ -1627,7 +1627,7 @@ cdef class _PathFinder(_CCPPruneController): | |
cdef float64_t[:] impurities | ||
cdef uint32_t count | ||
|
||
def __cinit__(self, int node_count): | ||
def __cinit__(self, intp_t node_count): | ||
self.ccp_alphas = np.zeros(shape=(node_count), dtype=np.float64) | ||
self.impurities = np.zeros(shape=(node_count), dtype=np.float64) | ||
self.count = 0 | ||
|
Uh oh!
There was an error while loading. Please reload this page.