File: test_column_split.h

package info (click to toggle)
xgboost 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,796 kB
  • sloc: cpp: 67,502; python: 35,503; java: 4,676; ansic: 1,426; sh: 1,320; xml: 1,197; makefile: 204; javascript: 19
file content (33 lines) | stat: -rw-r--r-- 1,066 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
 * Copyright 2023-2024, XGBoost Contributors
 */
#pragma once

#include <xgboost/data.h>          // for FeatureType, DMatrix

#include <cstddef>  // for size_t
#include <memory>   // for shared_ptr
#include <vector>   // for vector

#include "../helpers.h"                 // for RandomDataGenerator

namespace xgboost::tree {
inline std::shared_ptr<DMatrix> GenerateCatDMatrix(std::size_t rows, std::size_t cols,
                                                   float sparsity, bool categorical) {
  if (categorical) {
    std::vector<FeatureType> ft(cols);
    for (size_t i = 0; i < ft.size(); ++i) {
      ft[i] = (i % 3 == 0) ? FeatureType::kNumerical : FeatureType::kCategorical;
    }
    return RandomDataGenerator(rows, cols, sparsity)
        .Seed(3)
        .Type(ft)
        .MaxCategory(17)
        .GenerateDMatrix();
  } else {
    return RandomDataGenerator{rows, cols, sparsity}.Seed(3).GenerateDMatrix();
  }
}

void TestColumnSplit(bst_target_t n_targets, bool categorical, std::string name, float sparsity);
}  // namespace xgboost::tree