@@ -138,7 +138,7 @@ cdef class ClassificationCriterion(Criterion):
138
138
cdef SIZE_t k = 0
139
139
cdef SIZE_t label_count_stride = 0
140
140
141
- for k from 0 <= k < n_outputs:
141
+ for k in range ( n_outputs) :
142
142
self .n_classes[k] = n_classes[k]
143
143
144
144
if n_classes[k] > label_count_stride:
@@ -211,17 +211,17 @@ cdef class ClassificationCriterion(Criterion):
211
211
cdef DOUBLE_t w = 1.0
212
212
cdef SIZE_t offset = 0
213
213
214
- for k from 0 <= k < n_outputs:
214
+ for k in range ( n_outputs) :
215
215
memset(label_count_total + offset, 0 , n_classes[k] * sizeof(double ))
216
216
offset += label_count_stride
217
217
218
- for p from start <= p < end:
218
+ for p in range ( start, end) :
219
219
i = samples[p]
220
220
221
221
if sample_weight != NULL :
222
222
w = sample_weight[i]
223
223
224
- for k from 0 <= k < n_outputs:
224
+ for k in range ( n_outputs) :
225
225
c = < SIZE_t> y[i * y_stride + k]
226
226
label_count_total[k * label_count_stride + c] += w
227
227
@@ -248,7 +248,7 @@ cdef class ClassificationCriterion(Criterion):
248
248
249
249
cdef SIZE_t k = 0
250
250
251
- for k from 0 <= k < n_outputs:
251
+ for k in range ( n_outputs) :
252
252
memset(label_count_left, 0 , n_classes[k] * sizeof(double ))
253
253
memcpy(label_count_right, label_count_total, n_classes[k] * sizeof(double ))
254
254
@@ -284,13 +284,13 @@ cdef class ClassificationCriterion(Criterion):
284
284
285
285
# Note: We assume start <= pos < new_pos <= end
286
286
287
- for p from pos <= p < new_pos:
287
+ for p in range ( pos, new_pos) :
288
288
i = samples[p]
289
289
290
290
if sample_weight != NULL :
291
291
w = sample_weight[i]
292
292
293
- for k from 0 <= k < n_outputs:
293
+ for k in range ( n_outputs) :
294
294
label_index = (k * label_count_stride +
295
295
< SIZE_t> y[i * y_stride + k])
296
296
label_count_left[label_index] += w
@@ -318,7 +318,7 @@ cdef class ClassificationCriterion(Criterion):
318
318
cdef double * label_count_total = self .label_count_total
319
319
cdef SIZE_t k
320
320
321
- for k from 0 <= k < n_outputs:
321
+ for k in range ( n_outputs) :
322
322
memcpy(dest, label_count_total, n_classes[k] * sizeof(double ))
323
323
dest += label_count_stride
324
324
label_count_total += label_count_stride
@@ -354,10 +354,10 @@ cdef class Entropy(ClassificationCriterion):
354
354
cdef SIZE_t k
355
355
cdef SIZE_t c
356
356
357
- for k from 0 <= k < n_outputs:
357
+ for k in range ( n_outputs) :
358
358
entropy = 0.0
359
359
360
- for c from 0 <= c < n_classes[k]:
360
+ for c in range ( n_classes[k]) :
361
361
tmp = label_count_total[c]
362
362
if tmp > 0.0 :
363
363
tmp /= weighted_n_node_samples
@@ -390,11 +390,11 @@ cdef class Entropy(ClassificationCriterion):
390
390
cdef SIZE_t k
391
391
cdef SIZE_t c
392
392
393
- for k from 0 <= k < n_outputs:
393
+ for k in range ( n_outputs) :
394
394
entropy_left = 0.0
395
395
entropy_right = 0.0
396
396
397
- for c from 0 <= c < n_classes[k]:
397
+ for c in range ( n_classes[k]) :
398
398
tmp = label_count_left[c]
399
399
if tmp > 0.0 :
400
400
tmp /= weighted_n_left
@@ -445,11 +445,11 @@ cdef class Gini(ClassificationCriterion):
445
445
cdef SIZE_t k
446
446
cdef SIZE_t c
447
447
448
- for k from 0 <= k < n_outputs:
448
+ for k in range ( n_outputs) :
449
449
gini = 0.0
450
450
451
- for c from 0 <= c < n_classes[k]:
452
- tmp = label_count_total[c] # TODO: use weighted count instead
451
+ for c in range ( n_classes[k]) :
452
+ tmp = label_count_total[c] # TODO: use weighted count instead
453
453
gini += tmp * tmp
454
454
455
455
gini = 1.0 - gini / (weighted_n_node_samples *
@@ -483,12 +483,12 @@ cdef class Gini(ClassificationCriterion):
483
483
cdef SIZE_t k
484
484
cdef SIZE_t c
485
485
486
- for k from 0 <= k < n_outputs:
486
+ for k in range ( n_outputs) :
487
487
gini_left = 0.0
488
488
gini_right = 0.0
489
489
490
- for c from 0 <= c < n_classes[k]:
491
- tmp = label_count_left[c] # TODO: use weighted count instead
490
+ for c in range ( n_classes[k]) :
491
+ tmp = label_count_left[c] # TODO: use weighted count instead
492
492
gini_left += tmp * tmp
493
493
tmp = label_count_right[c]
494
494
gini_right += tmp * tmp
@@ -638,7 +638,7 @@ cdef class RegressionCriterion(Criterion):
638
638
cdef DOUBLE_t y_ik = 0.0
639
639
cdef DOUBLE_t w = 1.0
640
640
641
- for k from 0 <= k < n_outputs:
641
+ for k in range ( n_outputs) :
642
642
mean_left[k] = 0.0
643
643
mean_right[k] = 0.0
644
644
mean_total[k] = 0.0
@@ -651,13 +651,13 @@ cdef class RegressionCriterion(Criterion):
651
651
self .sum_right[k] = 0.0
652
652
self .sum_total[k] = 0.0
653
653
654
- for p from start <= p < end:
654
+ for p in range ( start, end) :
655
655
i = samples[p]
656
656
657
657
if sample_weight != NULL :
658
658
w = sample_weight[i]
659
659
660
- for k from 0 <= k < n_outputs:
660
+ for k in range ( n_outputs) :
661
661
y_ik = y[i * y_stride + k]
662
662
sq_sum_total[k] += w * y_ik * y_ik
663
663
mean_total[k] += w * y_ik
@@ -667,7 +667,7 @@ cdef class RegressionCriterion(Criterion):
667
667
668
668
self .weighted_n_node_samples = weighted_n_node_samples
669
669
670
- for k from 0 <= k < n_outputs:
670
+ for k in range ( n_outputs) :
671
671
mean_total[k] /= weighted_n_node_samples
672
672
673
673
# Reset to pos=start
@@ -696,7 +696,7 @@ cdef class RegressionCriterion(Criterion):
696
696
697
697
cdef SIZE_t k = 0
698
698
699
- for k from 0 <= k < n_outputs:
699
+ for k in range ( n_outputs) :
700
700
mean_right[k] = mean_total[k]
701
701
mean_left[k] = 0.0
702
702
sq_sum_right[k] = sq_sum_total[k]
@@ -738,13 +738,13 @@ cdef class RegressionCriterion(Criterion):
738
738
739
739
# Note: We assume start <= pos < new_pos <= end
740
740
741
- for p from pos <= p < new_pos:
741
+ for p in range ( pos, new_pos) :
742
742
i = samples[p]
743
743
744
744
if sample_weight != NULL :
745
745
w = sample_weight[i]
746
746
747
- for k from 0 <= k < n_outputs:
747
+ for k in range ( n_outputs) :
748
748
y_ik = y[i * y_stride + k]
749
749
w_y_ik = w * y_ik
750
750
@@ -762,7 +762,7 @@ cdef class RegressionCriterion(Criterion):
762
762
weighted_n_left += w
763
763
weighted_n_right -= w
764
764
765
- for k from 0 <= k < n_outputs:
765
+ for k in range ( n_outputs) :
766
766
var_left[k] = (sq_sum_left[k] / weighted_n_left -
767
767
mean_left[k] * mean_left[k])
768
768
var_right[k] = (sq_sum_right[k] / weighted_n_right -
@@ -799,7 +799,7 @@ cdef class MSE(RegressionCriterion):
799
799
cdef double total = 0.0
800
800
cdef SIZE_t k
801
801
802
- for k from 0 <= k < n_outputs:
802
+ for k in range ( n_outputs) :
803
803
total += (sq_sum_total[k] / weighted_n_node_samples -
804
804
mean_total[k] * mean_total[k])
805
805
@@ -816,7 +816,7 @@ cdef class MSE(RegressionCriterion):
816
816
cdef double total_right = 0.0
817
817
cdef SIZE_t k
818
818
819
- for k from 0 <= k < n_outputs:
819
+ for k in range ( n_outputs) :
820
820
total_left += var_left[k]
821
821
total_right += var_right[k]
822
822
@@ -913,7 +913,7 @@ cdef class Splitter:
913
913
cdef SIZE_t i, j
914
914
j = 0
915
915
916
- for i from 0 <= i < n_samples:
916
+ for i in range ( n_samples) :
917
917
# Only work with positively weighted samples
918
918
if sample_weight == NULL or sample_weight[i] != 0.0 :
919
919
samples[j] = i
@@ -925,7 +925,7 @@ cdef class Splitter:
925
925
cdef SIZE_t n_features = X.shape[1 ]
926
926
cdef SIZE_t* features = < SIZE_t* > malloc(n_features * sizeof(SIZE_t))
927
927
928
- for i from 0 <= i < n_features:
928
+ for i in range ( n_features) :
929
929
features[i] = i
930
930
931
931
self .features = features
@@ -994,8 +994,8 @@ cdef class BestSplitter(Splitter):
994
994
cdef double best_impurity_left = INFINITY
995
995
cdef double best_impurity_right = INFINITY
996
996
cdef SIZE_t best_pos = end
997
- cdef SIZE_t best_feature
998
- cdef double best_threshold
997
+ cdef SIZE_t best_feature = 0
998
+ cdef double best_threshold = 0.
999
999
cdef double best_improvement = - INFINITY
1000
1000
1001
1001
cdef double current_improvement
@@ -1012,7 +1012,7 @@ cdef class BestSplitter(Splitter):
1012
1012
cdef SIZE_t partition_start
1013
1013
cdef SIZE_t partition_end
1014
1014
1015
- for f_idx from 0 <= f_idx < n_features:
1015
+ for f_idx in range ( n_features) :
1016
1016
# Draw a feature at random
1017
1017
f_i = n_features - f_idx - 1
1018
1018
f_j = rand_int(n_features - f_idx, random_state)
@@ -1176,8 +1176,8 @@ cdef class RandomSplitter(Splitter):
1176
1176
cdef double best_impurity_left = INFINITY
1177
1177
cdef double best_impurity_right = INFINITY
1178
1178
cdef SIZE_t best_pos = end
1179
- cdef SIZE_t best_feature
1180
- cdef double best_threshold
1179
+ cdef SIZE_t best_feature = 0
1180
+ cdef double best_threshold = 0.
1181
1181
cdef double best_improvement = - INFINITY
1182
1182
1183
1183
cdef double current_improvement
@@ -1197,7 +1197,7 @@ cdef class RandomSplitter(Splitter):
1197
1197
cdef SIZE_t partition_start
1198
1198
cdef SIZE_t partition_end
1199
1199
1200
- for f_idx from 0 <= f_idx < n_features:
1200
+ for f_idx in range ( n_features) :
1201
1201
# Draw a feature at random
1202
1202
f_i = n_features - f_idx - 1
1203
1203
f_j = rand_int(n_features - f_idx, random_state)
@@ -1211,7 +1211,7 @@ cdef class RandomSplitter(Splitter):
1211
1211
# Find min, max
1212
1212
min_feature_value = max_feature_value = X[X_sample_stride * samples[start] + X_fx_stride * current_feature]
1213
1213
1214
- for p from start < p < end:
1214
+ for p in range ( start + 1 , end) :
1215
1215
current_feature_value = X[X_sample_stride * samples[p] + X_fx_stride * current_feature]
1216
1216
1217
1217
if current_feature_value < min_feature_value:
@@ -1379,8 +1379,8 @@ cdef class PresortBestSplitter(Splitter):
1379
1379
cdef double best_impurity_left = INFINITY
1380
1380
cdef double best_impurity_right = INFINITY
1381
1381
cdef SIZE_t best_pos = end
1382
- cdef SIZE_t best_feature
1383
- cdef double best_threshold
1382
+ cdef SIZE_t best_feature = 0
1383
+ cdef double best_threshold = 0.
1384
1384
cdef double best_improvement = - INFINITY
1385
1385
1386
1386
cdef double current_improvement
@@ -1400,11 +1400,11 @@ cdef class PresortBestSplitter(Splitter):
1400
1400
cdef SIZE_t i, j
1401
1401
1402
1402
# Set sample mask
1403
- for p from start <= p < end:
1403
+ for p in range ( start, end) :
1404
1404
sample_mask[samples[p]] = 1
1405
1405
1406
1406
# Look for splits
1407
- for f_idx from 0 <= f_idx < n_features:
1407
+ for f_idx in range ( n_features) :
1408
1408
# Draw a feature at random
1409
1409
f_i = n_features - f_idx - 1
1410
1410
f_j = rand_int(n_features - f_idx, random_state)
@@ -1420,7 +1420,7 @@ cdef class PresortBestSplitter(Splitter):
1420
1420
# Extract ordering from X_argsorted
1421
1421
p = start
1422
1422
1423
- for i from 0 <= i < n_total_samples:
1423
+ for i in range ( n_total_samples) :
1424
1424
j = X_argsorted[X_argsorted_stride * current_feature + i]
1425
1425
if sample_mask[j] == 1 :
1426
1426
samples[p] = j
@@ -1496,7 +1496,7 @@ cdef class PresortBestSplitter(Splitter):
1496
1496
samples[p] = tmp
1497
1497
1498
1498
# Reset sample mask
1499
- for p from start <= p < end:
1499
+ for p in range ( start, end) :
1500
1500
sample_mask[samples[p]] = 0
1501
1501
1502
1502
# Return values
@@ -1933,7 +1933,7 @@ cdef class Tree:
1933
1933
1934
1934
cdef SIZE_t k
1935
1935
1936
- for k from 0 <= k < n_outputs:
1936
+ for k in range ( n_outputs) :
1937
1937
self .n_classes[k] = n_classes[k]
1938
1938
1939
1939
# Parameters
@@ -2152,7 +2152,7 @@ cdef class Tree:
2152
2152
out = np.zeros((n_samples, max_n_classes), dtype = np.float64)
2153
2153
2154
2154
with nogil:
2155
- for i from 0 <= i < n_samples:
2155
+ for i in range ( n_samples) :
2156
2156
node_id = 0
2157
2157
2158
2158
# While node_id not a leaf
@@ -2165,7 +2165,7 @@ cdef class Tree:
2165
2165
2166
2166
offset = node_id * value_stride
2167
2167
2168
- for c from 0 <= c < n_classes[0 ]:
2168
+ for c in range ( n_classes[0 ]) :
2169
2169
out[i, c] = value[offset + c]
2170
2170
2171
2171
return out
@@ -2176,7 +2176,7 @@ cdef class Tree:
2176
2176
max_n_classes), dtype = np.float64)
2177
2177
2178
2178
with nogil:
2179
- for i from 0 <= i < n_samples:
2179
+ for i in range ( n_samples) :
2180
2180
node_id = 0
2181
2181
2182
2182
# While node_id not a leaf
@@ -2189,8 +2189,8 @@ cdef class Tree:
2189
2189
2190
2190
offset = node_id * value_stride
2191
2191
2192
- for k from 0 <= k < n_outputs:
2193
- for c from 0 <= c < n_classes[k]:
2192
+ for k in range ( n_outputs) :
2193
+ for c in range ( n_classes[k]) :
2194
2194
out_multi[i, k, c] = value[offset + c]
2195
2195
offset += max_n_classes
2196
2196
@@ -2211,7 +2211,7 @@ cdef class Tree:
2211
2211
out = np.zeros((n_samples,), dtype = np.int32)
2212
2212
2213
2213
with nogil:
2214
- for i from 0 <= i < n_samples:
2214
+ for i in range ( n_samples) :
2215
2215
node_id = 0
2216
2216
2217
2217
# While node_id not a leaf
@@ -2244,7 +2244,7 @@ cdef class Tree:
2244
2244
cdef np.ndarray[np.float64_t, ndim= 1 ] importances
2245
2245
importances = np.zeros((self .n_features,))
2246
2246
2247
- for node from 0 <= node < node_count:
2247
+ for node in range ( node_count) :
2248
2248
if children_left[node] != _TREE_LEAF:
2249
2249
# ... and children_right[node] != _TREE_LEAF:
2250
2250
n_left = n_node_samples[children_left[node]]
@@ -2279,7 +2279,7 @@ cdef inline UINT32_t our_rand_r(UINT32_t* seed) nogil:
2279
2279
seed[0 ] ^= < UINT32_t> (seed[0 ] >> 17 )
2280
2280
seed[0 ] ^= < UINT32_t> (seed[0 ] << 5 )
2281
2281
2282
- return seed[0 ] % < UINT32_t> ( RAND_R_MAX + 1 )
2282
+ return seed[0 ] % ( < UINT32_t> RAND_R_MAX + 1 )
2283
2283
2284
2284
cdef inline np.ndarray int_ptr_to_ndarray(int * data, SIZE_t size):
2285
2285
""" Encapsulate data into a 1D numpy array of int's."""
0 commit comments