@@ -53,7 +53,7 @@ cdef class Criterion:
53
53
54
54
cdef void init(self , DOUBLE_t* y, SIZE_t y_stride, DOUBLE_t* sample_weight,
55
55
double weighted_n_samples, SIZE_t* samples, SIZE_t start,
56
- SIZE_t end) nogil:
56
+ SIZE_t end) nogil except * :
57
57
""" Placeholder for a method which will initialize the criterion.
58
58
59
59
Parameters
@@ -79,22 +79,22 @@ cdef class Criterion:
79
79
80
80
pass
81
81
82
- cdef void reset(self ) nogil:
82
+ cdef void reset(self ) nogil except * :
83
83
""" Reset the criterion at pos=start.
84
84
85
85
This method must be implemented by the subclass.
86
86
"""
87
87
88
88
pass
89
89
90
- cdef void reverse_reset(self ) nogil:
90
+ cdef void reverse_reset(self ) nogil except * :
91
91
""" Reset the criterion at pos=end.
92
92
93
93
This method must be implemented by the subclass.
94
94
"""
95
95
pass
96
96
97
- cdef void update(self , SIZE_t new_pos) nogil:
97
+ cdef void update(self , SIZE_t new_pos) nogil except * :
98
98
""" Updated statistics by moving samples[pos:new_pos] to the left child.
99
99
100
100
This updates the collected statistics by moving samples[pos:new_pos]
@@ -109,7 +109,7 @@ cdef class Criterion:
109
109
110
110
pass
111
111
112
- cdef double node_impurity(self ) nogil:
112
+ cdef double node_impurity(self ) nogil except * :
113
113
""" Placeholder for calculating the impurity of the node.
114
114
115
115
Placeholder for a method which will evaluate the impurity of
@@ -120,7 +120,7 @@ cdef class Criterion:
120
120
pass
121
121
122
122
cdef void children_impurity(self , double * impurity_left,
123
- double * impurity_right) nogil:
123
+ double * impurity_right) nogil except * :
124
124
""" Placeholder for calculating the impurity of children.
125
125
126
126
Placeholder for a method which evaluates the impurity in
@@ -139,7 +139,7 @@ cdef class Criterion:
139
139
140
140
pass
141
141
142
- cdef void node_value(self , double * dest) nogil:
142
+ cdef void node_value(self , double * dest) nogil except * :
143
143
""" Placeholder for storing the node value.
144
144
145
145
Placeholder for a method which will compute the node value
@@ -153,7 +153,7 @@ cdef class Criterion:
153
153
154
154
pass
155
155
156
- cdef double proxy_impurity_improvement(self ) nogil:
156
+ cdef double proxy_impurity_improvement(self ) nogil except * :
157
157
""" Compute a proxy of the impurity reduction
158
158
159
159
This method is used to speed up the search for the best split.
@@ -171,7 +171,7 @@ cdef class Criterion:
171
171
return (- self .weighted_n_right * impurity_right
172
172
- self .weighted_n_left * impurity_left)
173
173
174
- cdef double impurity_improvement(self , double impurity) nogil:
174
+ cdef double impurity_improvement(self , double impurity) nogil except * :
175
175
""" Compute the improvement in impurity
176
176
177
177
This method computes the improvement in impurity when a split occurs.
@@ -283,7 +283,7 @@ cdef class ClassificationCriterion(Criterion):
283
283
284
284
cdef void init(self , DOUBLE_t* y, SIZE_t y_stride,
285
285
DOUBLE_t* sample_weight, double weighted_n_samples,
286
- SIZE_t* samples, SIZE_t start, SIZE_t end) nogil:
286
+ SIZE_t* samples, SIZE_t start, SIZE_t end) nogil except * :
287
287
""" Initialize the criterion at node samples[start:end] and
288
288
children samples[start:start] and samples[start:end].
289
289
@@ -348,7 +348,7 @@ cdef class ClassificationCriterion(Criterion):
348
348
# Reset to pos=start
349
349
self .reset()
350
350
351
- cdef void reset(self ) nogil:
351
+ cdef void reset(self ) nogil except * :
352
352
""" Reset the criterion at pos=start."""
353
353
354
354
self .pos = self .start
@@ -371,7 +371,7 @@ cdef class ClassificationCriterion(Criterion):
371
371
sum_left += self .sum_stride
372
372
sum_right += self .sum_stride
373
373
374
- cdef void reverse_reset(self ) nogil:
374
+ cdef void reverse_reset(self ) nogil except * :
375
375
""" Reset the criterion at pos=end."""
376
376
self .pos = self .end
377
377
@@ -393,7 +393,7 @@ cdef class ClassificationCriterion(Criterion):
393
393
sum_left += self .sum_stride
394
394
sum_right += self .sum_stride
395
395
396
- cdef void update(self , SIZE_t new_pos) nogil:
396
+ cdef void update(self , SIZE_t new_pos) nogil except * :
397
397
""" Updated statistics by moving samples[pos:new_pos] to the left child.
398
398
399
399
Parameters
@@ -471,14 +471,14 @@ cdef class ClassificationCriterion(Criterion):
471
471
472
472
self .pos = new_pos
473
473
474
- cdef double node_impurity(self ) nogil:
474
+ cdef double node_impurity(self ) nogil except * :
475
475
pass
476
476
477
477
cdef void children_impurity(self , double * impurity_left,
478
- double * impurity_right) nogil:
478
+ double * impurity_right) nogil except * :
479
479
pass
480
480
481
- cdef void node_value(self , double * dest) nogil:
481
+ cdef void node_value(self , double * dest) nogil except * :
482
482
""" Compute the node value of samples[start:end] and save it into dest.
483
483
484
484
Parameters
@@ -513,7 +513,7 @@ cdef class Entropy(ClassificationCriterion):
513
513
cross-entropy = -\sum_{k=0}^{K-1} count_k log(count_k)
514
514
"""
515
515
516
- cdef double node_impurity(self ) nogil:
516
+ cdef double node_impurity(self ) nogil except * :
517
517
""" Evaluate the impurity of the current node, i.e. the impurity of
518
518
samples[start:end], using the cross-entropy criterion."""
519
519
@@ -536,7 +536,7 @@ cdef class Entropy(ClassificationCriterion):
536
536
return entropy / self .n_outputs
537
537
538
538
cdef void children_impurity(self , double * impurity_left,
539
- double * impurity_right) nogil:
539
+ double * impurity_right) nogil except * :
540
540
""" Evaluate the impurity in children nodes
541
541
542
542
i.e. the impurity of the left child (samples[start:pos]) and the
@@ -595,7 +595,7 @@ cdef class Gini(ClassificationCriterion):
595
595
= 1 - \sum_{k=0}^{K-1} count_k ** 2
596
596
"""
597
597
598
- cdef double node_impurity(self ) nogil:
598
+ cdef double node_impurity(self ) nogil except * :
599
599
""" Evaluate the impurity of the current node, i.e. the impurity of
600
600
samples[start:end] using the Gini criterion."""
601
601
@@ -623,7 +623,7 @@ cdef class Gini(ClassificationCriterion):
623
623
return gini / self .n_outputs
624
624
625
625
cdef void children_impurity(self , double * impurity_left,
626
- double * impurity_right) nogil:
626
+ double * impurity_right) nogil except * :
627
627
""" Evaluate the impurity in children nodes
628
628
629
629
i.e. the impurity of the left child (samples[start:pos]) and the
@@ -738,7 +738,7 @@ cdef class RegressionCriterion(Criterion):
738
738
739
739
cdef void init(self , DOUBLE_t* y, SIZE_t y_stride, DOUBLE_t* sample_weight,
740
740
double weighted_n_samples, SIZE_t* samples, SIZE_t start,
741
- SIZE_t end) nogil:
741
+ SIZE_t end) nogil except * :
742
742
""" Initialize the criterion at node samples[start:end] and
743
743
children samples[start:start] and samples[start:end]."""
744
744
# Initialize fields
@@ -779,7 +779,7 @@ cdef class RegressionCriterion(Criterion):
779
779
# Reset to pos=start
780
780
self .reset()
781
781
782
- cdef void reset(self ) nogil:
782
+ cdef void reset(self ) nogil except * :
783
783
""" Reset the criterion at pos=start."""
784
784
cdef SIZE_t n_bytes = self .n_outputs * sizeof(double )
785
785
memset(self .sum_left, 0 , n_bytes)
@@ -789,7 +789,7 @@ cdef class RegressionCriterion(Criterion):
789
789
self .weighted_n_right = self .weighted_n_node_samples
790
790
self .pos = self .start
791
791
792
- cdef void reverse_reset(self ) nogil:
792
+ cdef void reverse_reset(self ) nogil except * :
793
793
""" Reset the criterion at pos=end."""
794
794
cdef SIZE_t n_bytes = self .n_outputs * sizeof(double )
795
795
memset(self .sum_right, 0 , n_bytes)
@@ -799,7 +799,7 @@ cdef class RegressionCriterion(Criterion):
799
799
self .weighted_n_left = self .weighted_n_node_samples
800
800
self .pos = self .end
801
801
802
- cdef void update(self , SIZE_t new_pos) nogil:
802
+ cdef void update(self , SIZE_t new_pos) nogil except * :
803
803
""" Updated statistics by moving samples[pos:new_pos] to the left."""
804
804
805
805
cdef double * sum_left = self .sum_left
@@ -860,14 +860,14 @@ cdef class RegressionCriterion(Criterion):
860
860
861
861
self .pos = new_pos
862
862
863
- cdef double node_impurity(self ) nogil:
863
+ cdef double node_impurity(self ) nogil except * :
864
864
pass
865
865
866
866
cdef void children_impurity(self , double * impurity_left,
867
- double * impurity_right) nogil:
867
+ double * impurity_right) nogil except * :
868
868
pass
869
869
870
- cdef void node_value(self , double * dest) nogil:
870
+ cdef void node_value(self , double * dest) nogil except * :
871
871
""" Compute the node value of samples[start:end] into dest."""
872
872
873
873
cdef SIZE_t k
@@ -882,7 +882,7 @@ cdef class MSE(RegressionCriterion):
882
882
MSE = var_left + var_right
883
883
"""
884
884
885
- cdef double node_impurity(self ) nogil:
885
+ cdef double node_impurity(self ) nogil except * :
886
886
""" Evaluate the impurity of the current node, i.e. the impurity of
887
887
samples[start:end]."""
888
888
@@ -896,7 +896,7 @@ cdef class MSE(RegressionCriterion):
896
896
897
897
return impurity / self .n_outputs
898
898
899
- cdef double proxy_impurity_improvement(self ) nogil:
899
+ cdef double proxy_impurity_improvement(self ) nogil except * :
900
900
""" Compute a proxy of the impurity reduction
901
901
902
902
This method is used to speed up the search for the best split.
@@ -923,7 +923,7 @@ cdef class MSE(RegressionCriterion):
923
923
proxy_impurity_right / self .weighted_n_right)
924
924
925
925
cdef void children_impurity(self , double * impurity_left,
926
- double * impurity_right) nogil:
926
+ double * impurity_right) nogil except * :
927
927
""" Evaluate the impurity in children nodes, i.e. the impurity of the
928
928
left child (samples[start:pos]) and the impurity the right child
929
929
(samples[pos:end])."""
@@ -1030,7 +1030,7 @@ cdef class MAE(RegressionCriterion):
1030
1030
1031
1031
cdef void init(self , DOUBLE_t* y, SIZE_t y_stride, DOUBLE_t* sample_weight,
1032
1032
double weighted_n_samples, SIZE_t* samples, SIZE_t start,
1033
- SIZE_t end) nogil:
1033
+ SIZE_t end) nogil except * :
1034
1034
""" Initialize the criterion at node samples[start:end] and
1035
1035
children samples[start:start] and samples[start:end]."""
1036
1036
@@ -1080,7 +1080,7 @@ cdef class MAE(RegressionCriterion):
1080
1080
# Reset to pos=start
1081
1081
self .reset()
1082
1082
1083
- cdef void reset(self ) nogil:
1083
+ cdef void reset(self ) nogil except * :
1084
1084
""" Reset the criterion at pos=start."""
1085
1085
1086
1086
cdef SIZE_t i, k
@@ -1106,7 +1106,7 @@ cdef class MAE(RegressionCriterion):
1106
1106
(< WeightedMedianCalculator> right_child[k]).push(value,
1107
1107
weight)
1108
1108
1109
- cdef void reverse_reset(self ) nogil:
1109
+ cdef void reverse_reset(self ) nogil except * :
1110
1110
""" Reset the criterion at pos=end."""
1111
1111
1112
1112
self .weighted_n_right = 0.0
@@ -1129,7 +1129,7 @@ cdef class MAE(RegressionCriterion):
1129
1129
(< WeightedMedianCalculator> left_child[k]).push(value,
1130
1130
weight)
1131
1131
1132
- cdef void update(self , SIZE_t new_pos) nogil:
1132
+ cdef void update(self , SIZE_t new_pos) nogil except * :
1133
1133
""" Updated statistics by moving samples[pos:new_pos] to the left."""
1134
1134
1135
1135
cdef DOUBLE_t* sample_weight = self .sample_weight
@@ -1186,14 +1186,14 @@ cdef class MAE(RegressionCriterion):
1186
1186
self .weighted_n_left)
1187
1187
self .pos = new_pos
1188
1188
1189
- cdef void node_value(self , double * dest) nogil:
1189
+ cdef void node_value(self , double * dest) nogil except * :
1190
1190
""" Computes the node value of samples[start:end] into dest."""
1191
1191
1192
1192
cdef SIZE_t k
1193
1193
for k in range (self .n_outputs):
1194
1194
dest[k] = < double > self .node_medians[k]
1195
1195
1196
- cdef double node_impurity(self ) nogil:
1196
+ cdef double node_impurity(self ) nogil except * :
1197
1197
""" Evaluate the impurity of the current node, i.e. the impurity of
1198
1198
samples[start:end]"""
1199
1199
@@ -1216,7 +1216,7 @@ cdef class MAE(RegressionCriterion):
1216
1216
return impurity / (self .weighted_n_node_samples * self .n_outputs)
1217
1217
1218
1218
cdef void children_impurity(self , double * impurity_left,
1219
- double * impurity_right) nogil:
1219
+ double * impurity_right) nogil except * :
1220
1220
""" Evaluate the impurity in children nodes, i.e. the impurity of the
1221
1221
left child (samples[start:pos]) and the impurity the right child
1222
1222
(samples[pos:end]).
@@ -1273,7 +1273,7 @@ cdef class FriedmanMSE(MSE):
1273
1273
improvement = n_left * n_right * diff^2 / (n_left + n_right)
1274
1274
"""
1275
1275
1276
- cdef double proxy_impurity_improvement(self ) nogil:
1276
+ cdef double proxy_impurity_improvement(self ) nogil except * :
1277
1277
""" Compute a proxy of the impurity reduction
1278
1278
1279
1279
This method is used to speed up the search for the best split.
@@ -1303,7 +1303,7 @@ cdef class FriedmanMSE(MSE):
1303
1303
1304
1304
return diff * diff / (self .weighted_n_left * self .weighted_n_right)
1305
1305
1306
- cdef double impurity_improvement(self , double impurity) nogil:
1306
+ cdef double impurity_improvement(self , double impurity) nogil except * :
1307
1307
cdef double * sum_left = self .sum_left
1308
1308
cdef double * sum_right = self .sum_right
1309
1309
0 commit comments