| 16 | |
| 17 | namespace xgboost::common { |
| 18 | TEST(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 | |
| 45 | TEST(Stats, WeightedQuantile) { |
| 46 | Context ctx; |
nothing calls this directly
no test coverage detected