@@ -16,16 +16,12 @@ from sklearn.tree._tree cimport Tree, Node
1616
1717ctypedef np.int32_t int32
1818ctypedef np.float64_t float64
19- ctypedef np.int8_t int8
20- 
21- from  numpy import  bool  as  np_bool
19+ ctypedef np.uint8_t uint8
2220
2321#  no namespace lookup for numpy dtype and array creation
2422from  numpy import  zeros as  np_zeros
2523from  numpy import  ones as  np_ones
2624from  numpy import  bool  as  np_bool
27- from  numpy import  int8 as  np_int8
28- from  numpy import  intp as  np_intp
2925from  numpy import  float32 as  np_float32
3026from  numpy import  float64 as  np_float64
3127
@@ -267,7 +263,8 @@ cpdef _partial_dependence_tree(Tree tree, DTYPE_t[:, ::1] X,
267263                             total_weight)
268264
269265
270- def  _random_sample_mask (int n_total_samples , int n_total_in_bag , random_state ):
266+ def  _random_sample_mask (np.npy_intp n_total_samples ,
267+                         np.npy_intp n_total_in_bag , random_state ):
271268     """ Create a random sample mask where ``n_total_in_bag`` elements are set.
272269
273270     Parameters 
@@ -289,15 +286,15 @@ def _random_sample_mask(int n_total_samples, int n_total_in_bag, random_state):
289286     """  
290287     cdef np.ndarray[float64, ndim= 1 , mode= " c" =  \
291288          random_state.rand(n_total_samples)
292-      cdef np.ndarray[int8 , ndim= 1 , mode= " c" =  \
293-           np_zeros((n_total_samples,), dtype = np_int8 )
289+      cdef np.ndarray[uint8 , ndim= 1 , mode= " c" , cast = True ] sample_mask =  \
290+           np_zeros((n_total_samples,), dtype = np_bool )
294291
295-      cdef int  n_bagged =  0 
296-      cdef int  i =  0 
292+      cdef np.npy_intp  n_bagged =  0 
293+      cdef np.npy_intp  i =  0 
297294
298-      for  i from   0   <=  i  <   n_total_samples:
295+      for  i in   range ( n_total_samples) :
299296         if  rand[i] *  (n_total_samples -  i) <  (n_total_in_bag -  n_bagged):
300297             sample_mask[i] =  1 
301298             n_bagged +=  1 
302299
303-      return  sample_mask.astype(np_bool) 
300+      return  sample_mask
0 commit comments