Skip to content

Commit 2105500

Browse files
authored
MAINT Replace double with float64_t inside tree submodule (scikit-learn#27539)
Signed-off-by: Adam Li <adam2392@gmail.com>
1 parent 5e9302b commit 2105500

File tree

8 files changed

+289
-285
lines changed

8 files changed

+289
-285
lines changed

sklearn/tree/_criterion.pxd

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ cdef class Criterion:
3232
cdef intp_t n_outputs # Number of outputs
3333
cdef intp_t n_samples # Number of samples
3434
cdef intp_t n_node_samples # Number of samples in the node (end-start)
35-
cdef double weighted_n_samples # Weighted number of samples (in total)
36-
cdef double weighted_n_node_samples # Weighted number of samples in the node
37-
cdef double weighted_n_left # Weighted number of samples in the left node
38-
cdef double weighted_n_right # Weighted number of samples in the right node
39-
cdef double weighted_n_missing # Weighted number of samples that are missing
35+
cdef float64_t weighted_n_samples # Weighted number of samples (in total)
36+
cdef float64_t weighted_n_node_samples # Weighted number of samples in the node
37+
cdef float64_t weighted_n_left # Weighted number of samples in the left node
38+
cdef float64_t weighted_n_right # Weighted number of samples in the right node
39+
cdef float64_t weighted_n_missing # Weighted number of samples that are missing
4040

4141
# The criterion object is maintained such that left and right collected
4242
# statistics correspond to samples[start:pos] and samples[pos:end].
@@ -46,7 +46,7 @@ cdef class Criterion:
4646
self,
4747
const float64_t[:, ::1] y,
4848
const float64_t[:] sample_weight,
49-
double weighted_n_samples,
49+
float64_t weighted_n_samples,
5050
const intp_t[:] sample_indices,
5151
intp_t start,
5252
intp_t end
@@ -56,43 +56,43 @@ cdef class Criterion:
5656
cdef int reset(self) except -1 nogil
5757
cdef int reverse_reset(self) except -1 nogil
5858
cdef int update(self, intp_t new_pos) except -1 nogil
59-
cdef double node_impurity(self) noexcept nogil
59+
cdef float64_t node_impurity(self) noexcept nogil
6060
cdef void children_impurity(
6161
self,
62-
double* impurity_left,
63-
double* impurity_right
62+
float64_t* impurity_left,
63+
float64_t* impurity_right
6464
) noexcept nogil
6565
cdef void node_value(
6666
self,
67-
double* dest
67+
float64_t* dest
6868
) noexcept nogil
6969
cdef void clip_node_value(
7070
self,
71-
double* dest,
72-
double lower_bound,
73-
double upper_bound
71+
float64_t* dest,
72+
float64_t lower_bound,
73+
float64_t upper_bound
7474
) noexcept nogil
75-
cdef double middle_value(self) noexcept nogil
76-
cdef double impurity_improvement(
75+
cdef float64_t middle_value(self) noexcept nogil
76+
cdef float64_t impurity_improvement(
7777
self,
78-
double impurity_parent,
79-
double impurity_left,
80-
double impurity_right
78+
float64_t impurity_parent,
79+
float64_t impurity_left,
80+
float64_t impurity_right
8181
) noexcept nogil
82-
cdef double proxy_impurity_improvement(self) noexcept nogil
82+
cdef float64_t proxy_impurity_improvement(self) noexcept nogil
8383
cdef bint check_monotonicity(
8484
self,
8585
cnp.int8_t monotonic_cst,
86-
double lower_bound,
87-
double upper_bound,
86+
float64_t lower_bound,
87+
float64_t upper_bound,
8888
) noexcept nogil
8989
cdef inline bint _check_monotonicity(
9090
self,
9191
cnp.int8_t monotonic_cst,
92-
double lower_bound,
93-
double upper_bound,
94-
double sum_left,
95-
double sum_right,
92+
float64_t lower_bound,
93+
float64_t upper_bound,
94+
float64_t sum_left,
95+
float64_t sum_right,
9696
) noexcept nogil
9797

9898
cdef class ClassificationCriterion(Criterion):
@@ -101,17 +101,17 @@ cdef class ClassificationCriterion(Criterion):
101101
cdef intp_t[::1] n_classes
102102
cdef intp_t max_n_classes
103103

104-
cdef double[:, ::1] sum_total # The sum of the weighted count of each label.
105-
cdef double[:, ::1] sum_left # Same as above, but for the left side of the split
106-
cdef double[:, ::1] sum_right # Same as above, but for the right side of the split
107-
cdef double[:, ::1] sum_missing # Same as above, but for missing values in X
104+
cdef float64_t[:, ::1] sum_total # The sum of the weighted count of each label.
105+
cdef float64_t[:, ::1] sum_left # Same as above, but for the left side of the split
106+
cdef float64_t[:, ::1] sum_right # Same as above, but for the right side of the split
107+
cdef float64_t[:, ::1] sum_missing # Same as above, but for missing values in X
108108

109109
cdef class RegressionCriterion(Criterion):
110110
"""Abstract regression criterion."""
111111

112-
cdef double sq_sum_total
112+
cdef float64_t sq_sum_total
113113

114-
cdef double[::1] sum_total # The sum of w*y.
115-
cdef double[::1] sum_left # Same as above, but for the left side of the split
116-
cdef double[::1] sum_right # Same as above, but for the right side of the split
117-
cdef double[::1] sum_missing # Same as above, but for missing values in X
114+
cdef float64_t[::1] sum_total # The sum of w*y.
115+
cdef float64_t[::1] sum_left # Same as above, but for the left side of the split
116+
cdef float64_t[::1] sum_right # Same as above, but for the right side of the split
117+
cdef float64_t[::1] sum_missing # Same as above, but for missing values in X

0 commit comments

Comments
 (0)