| 615 | } |
| 616 | |
| 617 | [[nodiscard]] std::vector<float> GenerateRandomCategoricalSingleColumn(std::size_t n, |
| 618 | std::size_t n_categories) { |
| 619 | std::vector<float> x(n); |
| 620 | std::mt19937 rng(0); |
| 621 | std::uniform_int_distribution<size_t> dist(0, n_categories - 1); |
| 622 | std::generate(x.begin(), x.end(), [&]() { return static_cast<float>(dist(rng)); }); |
| 623 | // Make sure each category is present |
| 624 | for (size_t i = 0; i < n_categories; i++) { |
| 625 | x[i] = static_cast<decltype(x)::value_type>(i); |
| 626 | } |
| 627 | return x; |
| 628 | } |
| 629 | |
| 630 | std::shared_ptr<DMatrix> GetDMatrixFromData(const std::vector<float>& x, std::size_t num_rows, |
| 631 | bst_feature_t num_columns) { |