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

Function VerifySampling

tests/cpp/tree/hist/test_sampler.cc:25–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24namespace xgboost::tree::cpu_impl {
25void VerifySampling(float subsample, int sampling_method, bst_target_t n_targets = 1,
26 bool check_sum = true) {
27 Context ctx;
28
29 constexpr std::size_t kRows = 4096;
30 // Generate random gradients
31 auto gpair_container = GenerateRandomGradients(&ctx, kRows, n_targets);
32 auto h_gpair = gpair_container.gpair.HostView();
33
34 auto sum_gradients = [&]() {
35 auto sum = linalg::Empty<GradientPairPrecise>(&ctx, n_targets);
36 cpu_impl::SumGradients(&ctx, h_gpair, sum.HostView());
37 return sum.Data()->HostVector();
38 };
39
40 auto sum_gpair = sum_gradients();
41
42 TrainParam param;
43 param.UpdateAllowUnknown(Args{
44 {"subsample", std::to_string(subsample)},
45 {"sampling_method", sampling_method == TrainParam::kUniform ? "uniform" : "gradient_based"}});
46 Sampler sampler{param};
47 sampler.Sample(&ctx, h_gpair);
48
49 auto sum_sampled_gpair = sum_gradients();
50 CheckSampling(subsample, n_targets, check_sum, sum_sampled_gpair, sum_gpair, h_gpair);
51}
52
53TEST(CpuSampler, NoSampling) {
54 constexpr float kSubsample = 1.0f;

Callers 1

TESTFunction · 0.85

Calls 7

GenerateRandomGradientsFunction · 0.85
SumGradientsFunction · 0.85
CheckSamplingFunction · 0.85
SampleMethod · 0.80
HostViewMethod · 0.45
DataMethod · 0.45
UpdateAllowUnknownMethod · 0.45

Tested by

no test coverage detected