Add float32 histogram (#5624)
* new single_precision_histogram param was added. Co-authored-by: SHVETS, KIRILL <kirill.shvets@intel.com> Co-authored-by: fis <jm.yuan@outlook.com>
This commit is contained in:
@@ -20,8 +20,8 @@ size_t GetNThreads() {
|
||||
return nthreads;
|
||||
}
|
||||
|
||||
|
||||
TEST(ParallelGHistBuilder, Reset) {
|
||||
template <typename GradientSumT>
|
||||
void ParallelGHistBuilderReset() {
|
||||
constexpr size_t kBins = 10;
|
||||
constexpr size_t kNodes = 5;
|
||||
constexpr size_t kNodesExtended = 10;
|
||||
@@ -29,16 +29,16 @@ TEST(ParallelGHistBuilder, Reset) {
|
||||
constexpr double kValue = 1.0;
|
||||
const size_t nthreads = GetNThreads();
|
||||
|
||||
HistCollection collection;
|
||||
HistCollection<GradientSumT> collection;
|
||||
collection.Init(kBins);
|
||||
|
||||
for(size_t inode = 0; inode < kNodesExtended; inode++) {
|
||||
collection.AddHistRow(inode);
|
||||
}
|
||||
|
||||
ParallelGHistBuilder hist_builder;
|
||||
ParallelGHistBuilder<GradientSumT> hist_builder;
|
||||
hist_builder.Init(kBins);
|
||||
std::vector<GHistRow> target_hist(kNodes);
|
||||
std::vector<GHistRow<GradientSumT>> target_hist(kNodes);
|
||||
for(size_t i = 0; i < target_hist.size(); ++i) {
|
||||
target_hist[i] = collection[i];
|
||||
}
|
||||
@@ -49,7 +49,7 @@ TEST(ParallelGHistBuilder, Reset) {
|
||||
common::ParallelFor2d(space, nthreads, [&](size_t inode, common::Range1d r) {
|
||||
const size_t tid = omp_get_thread_num();
|
||||
|
||||
GHistRow hist = hist_builder.GetInitializedHist(tid, inode);
|
||||
GHistRow<GradientSumT> hist = hist_builder.GetInitializedHist(tid, inode);
|
||||
// fill hist by some non-null values
|
||||
for(size_t j = 0; j < kBins; ++j) {
|
||||
hist[j].Add(kValue, kValue);
|
||||
@@ -67,7 +67,7 @@ TEST(ParallelGHistBuilder, Reset) {
|
||||
common::ParallelFor2d(space2, nthreads, [&](size_t inode, common::Range1d r) {
|
||||
const size_t tid = omp_get_thread_num();
|
||||
|
||||
GHistRow hist = hist_builder.GetInitializedHist(tid, inode);
|
||||
GHistRow<GradientSumT> hist = hist_builder.GetInitializedHist(tid, inode);
|
||||
// fill hist by some non-null values
|
||||
for(size_t j = 0; j < kBins; ++j) {
|
||||
ASSERT_EQ(0.0, hist[j].GetGrad());
|
||||
@@ -76,23 +76,25 @@ TEST(ParallelGHistBuilder, Reset) {
|
||||
});
|
||||
}
|
||||
|
||||
TEST(ParallelGHistBuilder, ReduceHist) {
|
||||
|
||||
template <typename GradientSumT>
|
||||
void ParallelGHistBuilderReduceHist(){
|
||||
constexpr size_t kBins = 10;
|
||||
constexpr size_t kNodes = 5;
|
||||
constexpr size_t kTasksPerNode = 10;
|
||||
constexpr double kValue = 1.0;
|
||||
const size_t nthreads = GetNThreads();
|
||||
|
||||
HistCollection collection;
|
||||
HistCollection<GradientSumT> collection;
|
||||
collection.Init(kBins);
|
||||
|
||||
for(size_t inode = 0; inode < kNodes; inode++) {
|
||||
collection.AddHistRow(inode);
|
||||
}
|
||||
|
||||
ParallelGHistBuilder hist_builder;
|
||||
ParallelGHistBuilder<GradientSumT> hist_builder;
|
||||
hist_builder.Init(kBins);
|
||||
std::vector<GHistRow> target_hist(kNodes);
|
||||
std::vector<GHistRow<GradientSumT>> target_hist(kNodes);
|
||||
for(size_t i = 0; i < target_hist.size(); ++i) {
|
||||
target_hist[i] = collection[i];
|
||||
}
|
||||
@@ -104,7 +106,7 @@ TEST(ParallelGHistBuilder, ReduceHist) {
|
||||
common::ParallelFor2d(space, nthreads, [&](size_t inode, common::Range1d r) {
|
||||
const size_t tid = omp_get_thread_num();
|
||||
|
||||
GHistRow hist = hist_builder.GetInitializedHist(tid, inode);
|
||||
GHistRow<GradientSumT> hist = hist_builder.GetInitializedHist(tid, inode);
|
||||
for(size_t i = 0; i < kBins; ++i) {
|
||||
hist[i].Add(kValue, kValue);
|
||||
}
|
||||
@@ -122,6 +124,21 @@ TEST(ParallelGHistBuilder, ReduceHist) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ParallelGHistBuilder, ResetDouble) {
|
||||
ParallelGHistBuilderReset<double>();
|
||||
}
|
||||
|
||||
TEST(ParallelGHistBuilder, ResetFloat) {
|
||||
ParallelGHistBuilderReset<float>();
|
||||
}
|
||||
|
||||
TEST(ParallelGHistBuilder, ReduceHistDouble) {
|
||||
ParallelGHistBuilderReduceHist<double>();
|
||||
}
|
||||
|
||||
TEST(ParallelGHistBuilder, ReduceHistFloat) {
|
||||
ParallelGHistBuilderReduceHist<float>();
|
||||
}
|
||||
|
||||
TEST(CutsBuilder, SearchGroupInd) {
|
||||
size_t constexpr kNumGroups = 4;
|
||||
|
||||
Reference in New Issue
Block a user