File: test_iterative_dmatrix.cc

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 (42 lines) | stat: -rw-r--r-- 1,160 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
34
35
36
37
38
39
40
41
42
/**
 * Copyright 2022-2024, XGBoost contributors
 */
#include "test_iterative_dmatrix.h"

#include <gtest/gtest.h>

#include <limits>  // for numeric_limits
#include <memory>

#include "../../../src/data/gradient_index.h"
#include "../../../src/data/iterative_dmatrix.h"
#include "../helpers.h"
#include "xgboost/data.h"  // DMatrix

namespace xgboost::data {
TEST(IterativeDMatrix, Ref) {
  Context ctx;
  TestRefDMatrix<GHistIndexMatrix, NumpyArrayIterForTest>(
      &ctx, [&](GHistIndexMatrix const& page) { return page.cut; });
}

TEST(IterativeDMatrix, IsDense) {
  bst_bin_t n_bins = 16;
  auto test = [n_bins](float sparsity) {
    NumpyArrayIterForTest iter(sparsity);
    auto n_threads = 0;
    IterativeDMatrix m(&iter, iter.Proxy(), nullptr, Reset, Next,
                       std::numeric_limits<float>::quiet_NaN(), n_threads, n_bins,
                       std::numeric_limits<std::int64_t>::max());
    ASSERT_EQ(m.Ctx()->Threads(), AllThreadsForTest());
    if (sparsity == 0.0) {
      ASSERT_TRUE(m.IsDense());
    } else {
      ASSERT_FALSE(m.IsDense());
    }
  };
  test(0.0);
  test(0.1);
  test(1.0);
}
}  // namespace xgboost::data