@@ -44,7 +44,7 @@ class calls the ``fit`` method of each sub-estimator on random samples
4444from  abc  import  ABCMeta , abstractmethod 
4545
4646from  ..base  import  ClassifierMixin , RegressorMixin 
47- from  ..externals .joblib  import  Parallel , delayed ,  cpu_count 
47+ from  ..externals .joblib  import  Parallel , delayed 
4848from  ..externals  import  six 
4949from  ..externals .six .moves  import  xrange 
5050from  ..feature_selection .from_model  import  _LearntSelectorMixin 
@@ -57,8 +57,7 @@ class calls the ``fit`` method of each sub-estimator on random samples
5757from  ..utils .validation  import  DataConversionWarning 
5858from  ..utils .fixes  import  bincount , unique 
5959
60- 
61- from  .base  import  BaseEnsemble 
60+ from  .base  import  BaseEnsemble , _partition_estimators 
6261
6362__all__  =  ["RandomForestClassifier" ,
6463           "RandomForestRegressor" ,
@@ -151,29 +150,6 @@ def _parallel_predict_regression(trees, X):
151150    return  sum (tree .predict (X ) for  tree  in  trees )
152151
153152
154- def  _partition_trees (forest ):
155-     """Private function used to partition trees between jobs.""" 
156-     # Compute the number of jobs 
157-     if  forest .n_jobs  ==  - 1 :
158-         n_jobs  =  min (cpu_count (), forest .n_estimators )
159- 
160-     else :
161-         n_jobs  =  min (forest .n_jobs , forest .n_estimators )
162- 
163-     # Partition trees between jobs 
164-     n_trees  =  [forest .n_estimators  //  n_jobs ] *  n_jobs 
165- 
166-     for  i  in  range (forest .n_estimators  %  n_jobs ):
167-         n_trees [i ] +=  1 
168- 
169-     starts  =  [0 ] *  (n_jobs  +  1 )
170- 
171-     for  i  in  range (1 , n_jobs  +  1 ):
172-         starts [i ] =  starts [i  -  1 ] +  n_trees [i  -  1 ]
173- 
174-     return  n_jobs , n_trees , starts 
175- 
176- 
177153class  BaseForest (six .with_metaclass (ABCMeta , BaseEnsemble ,
178154                                    _LearntSelectorMixin )):
179155    """Base class for forests of trees. 
@@ -286,7 +262,7 @@ def fit(self, X, y, sample_weight=None):
286262                             " if bootstrap=True" )
287263
288264        # Assign chunk of trees to jobs 
289-         n_jobs , n_trees , _  =  _partition_trees (self )
265+         n_jobs , n_trees , _  =  _partition_estimators (self )
290266
291267        # Precalculate the random states 
292268        seeds  =  [random_state .randint (MAX_INT , size = i ) for  i  in  n_trees ]
@@ -481,7 +457,7 @@ def predict_proba(self, X):
481457            X  =  array2d (X , dtype = DTYPE )
482458
483459        # Assign chunk of trees to jobs 
484-         n_jobs , n_trees , starts  =  _partition_trees (self )
460+         n_jobs , n_trees , starts  =  _partition_estimators (self )
485461
486462        # Parallel loop 
487463        all_proba  =  Parallel (n_jobs = n_jobs , verbose = self .verbose )(
@@ -590,7 +566,7 @@ def predict(self, X):
590566            X  =  array2d (X , dtype = DTYPE )
591567
592568        # Assign chunk of trees to jobs 
593-         n_jobs , n_trees , starts  =  _partition_trees (self )
569+         n_jobs , n_trees , starts  =  _partition_estimators (self )
594570
595571        # Parallel loop 
596572        all_y_hat  =  Parallel (n_jobs = n_jobs , verbose = self .verbose )(
0 commit comments