MCPcopy Create free account
hub / github.com/dmlc/xgboost / TEST

Function TEST

tests/cpp/test_helpers.cc:12–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10namespace xgboost {
11
12TEST(RandomDataGenerator, DMatrix) {
13 size_t constexpr kRows { 16 }, kCols { 32 };
14 float constexpr kSparsity { 0.4f };
15 auto p_dmatrix = RandomDataGenerator{kRows, kCols, kSparsity}.GenerateDMatrix();
16
17 HostDeviceVector<float> csr_value;
18 HostDeviceVector<std::size_t> csr_rptr;
19 HostDeviceVector<bst_feature_t> csr_cidx;
20 RandomDataGenerator{kRows, kCols, kSparsity}.GenerateCSR(&csr_value, &csr_rptr, &csr_cidx);
21
22 HostDeviceVector<float> dense_data;
23 RandomDataGenerator{kRows, kCols, kSparsity}.GenerateDense(&dense_data);
24
25 auto it = std::copy_if(
26 dense_data.HostVector().begin(), dense_data.HostVector().end(),
27 dense_data.HostVector().begin(), [](float v) { return !std::isnan(v); });
28
29 CHECK_EQ(p_dmatrix->Info().num_row_, kRows);
30 CHECK_EQ(p_dmatrix->Info().num_col_, kCols);
31
32 for (auto const& page : p_dmatrix->GetBatches<SparsePage>()) {
33 size_t n_elements = page.data.Size();
34 CHECK_EQ(n_elements, it - dense_data.HostVector().begin());
35 CHECK_EQ(n_elements, csr_value.Size());
36
37 for (size_t i = 0; i < n_elements; ++i) {
38 CHECK_EQ(dense_data.HostVector()[i], csr_value.HostVector()[i]);
39 CHECK_EQ(dense_data.HostVector()[i], page.data.HostVector()[i].fvalue);
40 CHECK_EQ(page.data.HostVector()[i].index, csr_cidx.HostVector()[i]);
41 }
42 CHECK_EQ(page.offset.Size(), csr_rptr.Size());
43 for (size_t i = 0; i < p_dmatrix->Info().num_row_; ++i) {
44 CHECK_EQ(page.offset.HostVector()[i], csr_rptr.HostVector()[i]);
45 }
46 }
47}
48
49TEST(RandomDataGenerator, GenerateArrayInterfaceBatch) {
50 size_t constexpr kRows { 937 }, kCols { 100 }, kBatches { 13 };

Callers

nothing calls this directly

Calls 15

GenerateDMatrixMethod · 0.80
GenerateCSRMethod · 0.80
GenerateDenseMethod · 0.80
c_strMethod · 0.80
BatchesMethod · 0.80
ValidateFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
InfoMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected