MCPcopy Create free account
hub / github.com/dmlc/xgboost / TEST

Function TEST

tests/cpp/common/test_hist_util.cc:19–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18namespace xgboost::common {
19TEST(ParallelGHistBuilder, Reset) {
20 constexpr size_t kBins = 10;
21 constexpr size_t kNodes = 5;
22 constexpr size_t kNodesExtended = 10;
23 constexpr size_t kTasksPerNode = 10;
24 constexpr double kValue = 1.0;
25 const size_t nthreads = AllThreadsForTest();
26
27 HistCollection collection;
28 collection.Init(kBins);
29
30 for (size_t inode = 0; inode < kNodesExtended; inode++) {
31 collection.AddHistRow(inode);
32 collection.AllocateData(inode);
33 }
34 ParallelGHistBuilder hist_builder;
35 hist_builder.Init(kBins);
36 std::vector<GHistRow> target_hist(kNodes);
37 for (size_t i = 0; i < target_hist.size(); ++i) {
38 target_hist[i] = collection[i];
39 }
40
41 common::BlockedSpace2d space(kNodes, [&](size_t /* node*/) { return kTasksPerNode; }, 1);
42 hist_builder.Reset(nthreads, kNodes, space, target_hist);
43
44 common::ParallelFor2d(space, nthreads, [&](size_t inode, common::Range1d) {
45 const size_t tid = omp_get_thread_num();
46
47 GHistRow hist = hist_builder.GetInitializedHist(tid, inode);
48 // fill hist by some non-null values
49 for (size_t j = 0; j < kBins; ++j) {
50 hist[j].Add(kValue, kValue);
51 }
52 });
53
54 // reset and extend buffer
55 target_hist.resize(kNodesExtended);
56 for (size_t i = 0; i < target_hist.size(); ++i) {
57 target_hist[i] = collection[i];
58 }
59 common::BlockedSpace2d space2(kNodesExtended, [&](size_t /*node*/) { return kTasksPerNode; }, 1);
60 hist_builder.Reset(nthreads, kNodesExtended, space2, target_hist);
61
62 common::ParallelFor2d(space2, nthreads, [&](size_t inode, common::Range1d) {
63 const size_t tid = omp_get_thread_num();
64
65 GHistRow hist = hist_builder.GetInitializedHist(tid, inode);
66 // fill hist by some non-null values
67 for (size_t j = 0; j < kBins; ++j) {
68 ASSERT_EQ(0.0, hist[j].GetGrad());
69 ASSERT_EQ(0.0, hist[j].GetHess());
70 }
71 });
72}
73
74TEST(ParallelGHistBuilder, ReduceHist) {
75 constexpr size_t kBins = 10;

Callers

nothing calls this directly

Calls 15

AllThreadsForTestFunction · 0.85
ParallelFor2dFunction · 0.85
RandomDataGeneratorClass · 0.85
CheckIndexDataFunction · 0.85
GenerateRandomFunction · 0.85
GenerateRandomWeightsFunction · 0.85
SketchOnDMatrixFunction · 0.85
ValidateCutsFunction · 0.85
UnrollGroupWeightsFunction · 0.85
Make1dInterfaceTestFunction · 0.85
AllocateDataMethod · 0.80

Tested by

no test coverage detected