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

Function TestColumnSplit

tests/cpp/tree/test_column_split.cc:16–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15namespace xgboost::tree {
16void TestColumnSplit(bst_target_t n_targets, bool categorical, std::string name, float sparsity) {
17 auto constexpr kRows = 32;
18 auto constexpr kCols = 16;
19
20 RegTree expected_tree{n_targets, static_cast<bst_feature_t>(kCols)};
21 ObjInfo task{ObjInfo::kRegression};
22 Context ctx;
23 {
24 auto p_dmat = GenerateCatDMatrix(kRows, kCols, sparsity, categorical);
25 auto gpair = GenerateRandomGradients(&ctx, kRows, n_targets);
26 std::unique_ptr<TreeUpdater> updater{TreeUpdater::Create(name, &ctx, &task)};
27 std::vector<HostDeviceVector<bst_node_t>> position(1);
28 TrainParam param;
29 param.Init(Args{});
30 updater->Configure(Args{});
31 updater->Update(&param, &gpair, p_dmat.get(), position, {&expected_tree});
32 }
33
34 auto constexpr kWorldSize = 2;
35
36 auto verify = [&] {
37 Context ctx;
38 collective::GetWorkerLocalThreads(kWorldSize, &ctx);
39
40 auto p_dmat = GenerateCatDMatrix(kRows, kCols, sparsity, categorical);
41 auto gpair = GenerateRandomGradients(&ctx, kRows, n_targets);
42
43 ObjInfo task{ObjInfo::kRegression};
44 std::unique_ptr<TreeUpdater> updater{TreeUpdater::Create(name, &ctx, &task)};
45 std::vector<HostDeviceVector<bst_node_t>> position(1);
46
47 std::unique_ptr<DMatrix> sliced{
48 p_dmat->SliceCol(collective::GetWorldSize(), collective::GetRank())};
49
50 RegTree tree{n_targets, static_cast<bst_feature_t>(kCols)};
51 TrainParam param;
52 param.Init(Args{});
53 updater->Configure(Args{});
54 updater->Update(&param, &gpair, sliced.get(), position, {&tree});
55
56 Json json{Object{}};
57 tree.SaveModel(&json);
58 Json expected_json{Object{}};
59 expected_tree.SaveModel(&expected_json);
60 ASSERT_EQ(json, expected_json);
61 };
62
63 collective::TestDistributedGlobal(kWorldSize, [&] { verify(); });
64}
65} // namespace xgboost::tree

Callers 2

RunMethod · 0.70
RunMethod · 0.70

Calls 12

GenerateCatDMatrixFunction · 0.85
GenerateRandomGradientsFunction · 0.85
GetWorkerLocalThreadsFunction · 0.85
GetWorldSizeFunction · 0.85
GetRankFunction · 0.85
TestDistributedGlobalFunction · 0.85
InitMethod · 0.45
ConfigureMethod · 0.45
UpdateMethod · 0.45
getMethod · 0.45
SliceColMethod · 0.45
SaveModelMethod · 0.45

Tested by

no test coverage detected