Medial Code Documentation
Loading...
Searching...
No Matches
test_quantile.h
1#ifndef XGBOOST_TESTS_CPP_COMMON_TEST_QUANTILE_H_
2#define XGBOOST_TESTS_CPP_COMMON_TEST_QUANTILE_H_
3
4#include <algorithm>
5#include <string>
6#include <vector>
7
8#include "../helpers.h"
9
10namespace xgboost {
11namespace common {
12template <typename Fn> void RunWithSeedsAndBins(size_t rows, Fn fn) {
13 std::vector<int32_t> seeds(2);
14 SimpleLCG lcg;
15 SimpleRealUniformDistribution<float> dist(3, 1000);
16 std::generate(seeds.begin(), seeds.end(), [&](){ return dist(&lcg); });
17
18 std::vector<size_t> bins(2);
19 for (size_t i = 0; i < bins.size() - 1; ++i) {
20 bins[i] = i * 35 + 2;
21 }
22 bins.back() = rows + 160; // provide a bin number greater than rows.
23
24 std::vector<MetaInfo> infos(2);
25 auto& h_weights = infos.front().weights_.HostVector();
26 h_weights.resize(rows);
27
28 SimpleRealUniformDistribution<float> weight_dist(0, 10);
29 std::generate(h_weights.begin(), h_weights.end(), [&]() { return weight_dist(&lcg); });
30
31 for (auto seed : seeds) {
32 for (auto n_bin : bins) {
33 for (auto const& info : infos) {
34 fn(seed, n_bin, info);
35 }
36 }
37 }
38}
39} // namespace common
40} // namespace xgboost
41
42#endif // XGBOOST_TESTS_CPP_COMMON_TEST_QUANTILE_H_
namespace of xgboost
Definition base.h:90