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

Function TEST

tests/cpp/common/test_stats.cc:18–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17namespace xgboost::common {
18TEST(Stats, Quantile) {
19 Context ctx;
20 {
21 linalg::Tensor<float, 1> arr({20.f, 0.f, 15.f, 50.f, 40.f, 0.f, 35.f}, {7}, DeviceOrd::CPU());
22 std::vector<size_t> index{0, 2, 3, 4, 6};
23 auto h_arr = arr.HostView();
24 auto beg = MakeIndexTransformIter([&](size_t i) { return h_arr(index[i]); });
25 auto end = beg + index.size();
26 auto q = Quantile(&ctx, 0.40f, beg, end);
27 ASSERT_EQ(q, 26.0);
28
29 q = Quantile(&ctx, 0.20f, beg, end);
30 ASSERT_EQ(q, 16.0);
31
32 q = Quantile(&ctx, 0.10f, beg, end);
33 ASSERT_EQ(q, 15.0);
34 }
35
36 {
37 std::vector<float> vec{1., 2., 3., 4., 5.};
38 auto beg = MakeIndexTransformIter([&](size_t i) { return vec[i]; });
39 auto end = beg + vec.size();
40 auto q = Quantile(&ctx, 0.5f, beg, end);
41 ASSERT_EQ(q, 3.);
42 }
43}
44
45TEST(Stats, WeightedQuantile) {
46 Context ctx;

Callers

nothing calls this directly

Calls 15

CPUFunction · 0.85
MakeIndexTransformIterFunction · 0.85
QuantileFunction · 0.85
WeightedQuantileFunction · 0.85
TestMeanFunction · 0.85
MakeCUDACtxFunction · 0.85
TestSampleMeanFunction · 0.85
TestWeightedSampleMeanFunction · 0.85
MakeCUDAMethod · 0.80
MakeCPUMethod · 0.80

Tested by

no test coverage detected