[MRG] MNT Initialize histograms in parallel and don't call np.zero in Hist-GBDT
@@ -132,7 +132,8 @@ cdef class HistogramBuilder:
G_H_DTYPE_C [::1] gradients = self.gradients
G_H_DTYPE_C [::1] ordered_hessians = self.ordered_hessians
G_H_DTYPE_C [::1] hessians = self.hessians
- hist_struct [:, ::1] histograms = np.zeros(
+ # Histograms will be initialized to zero later within a prange
+ hist_struct [:, ::1] histograms = np.empty(
shape=(self.n_features, self.n_bins),
dtype=HISTOGRAM_DTYPE
)
@@ -177,6 +178,12 @@ cdef class HistogramBuilder:
self.ordered_hessians[:n_samples]
unsigned char hessians_are_constant = \
self.hessians_are_constant
+ unsigned int bin_idx = 0
+
+ for bin_idx in range(self.n_bins):
+ histograms[feature_idx, bin_idx].sum_gradients = 0.
+ histograms[feature_idx, bin_idx].sum_hessians = 0.
+ histograms[feature_idx, bin_idx].count = 0
if root_node:
if hessians_are_constant:
@@ -227,7 +234,7 @@ cdef class HistogramBuilder:
cdef:
int feature_idx
int n_features = self.n_features
- hist_struct [:, ::1] histograms = np.zeros(
+ hist_struct [:, ::1] histograms = np.empty(
shape=(self.n_features, self.n_bins),
dtype=HISTOGRAM_DTYPE
)
