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

Function TEST

tests/cpp/data/test_data.cc:14–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13namespace xgboost {
14TEST(SparsePage, PushCSC) {
15 std::vector<bst_idx_t> offset {0};
16 std::vector<Entry> data;
17 SparsePage batch;
18 batch.offset.HostVector() = offset;
19 batch.data.HostVector() = data;
20
21 offset = {0, 1, 4};
22 for (size_t i = 0; i < offset.back(); ++i) {
23 data.emplace_back(i, 0.1f);
24 }
25
26 SparsePage other;
27 other.offset.HostVector() = offset;
28 other.data.HostVector() = data;
29
30 batch.PushCSC(other);
31
32 ASSERT_EQ(batch.offset.HostVector().size(), offset.size());
33 ASSERT_EQ(batch.data.HostVector().size(), data.size());
34 for (size_t i = 0; i < offset.size(); ++i) {
35 ASSERT_EQ(batch.offset.HostVector()[i], offset[i]);
36 }
37 for (size_t i = 0; i < data.size(); ++i) {
38 ASSERT_EQ(batch.data.HostVector()[i].index, data[i].index);
39 }
40
41 batch.PushCSC(other);
42 ASSERT_EQ(batch.offset.HostVector().size(), offset.size());
43 ASSERT_EQ(batch.data.Size(), data.size() * 2);
44
45 for (size_t i = 0; i < offset.size(); ++i) {
46 ASSERT_EQ(batch.offset.HostVector()[i], offset[i] * 2);
47 }
48
49 auto page = batch.GetView();
50 auto inst = page[0];
51 ASSERT_EQ(inst.size(), 2ul);
52 for (auto entry : inst) {
53 ASSERT_EQ(entry.index, 0u);
54 }
55
56 inst = page[1];
57 ASSERT_EQ(inst.size(), 6ul);
58 std::vector<size_t> indices_sol {1, 2, 3};
59 for (size_t i = 0; i < inst.size(); ++i) {
60 ASSERT_EQ(inst[i].index, indices_sol[i % 3]);
61 }
62}
63
64TEST(SparsePage, PushCSCAfterTranspose) {
65 bst_idx_t constexpr kRows = 1024, kCols = 21;

Callers

nothing calls this directly

Calls 15

AllThreadsForTestFunction · 0.85
swapFunction · 0.85
CreateTestCSVFunction · 0.85
PushCSCMethod · 0.80
GetViewMethod · 0.80
BatchesMethod · 0.80
GetTransposeMethod · 0.80
SortRowsMethod · 0.80
GenerateDMatrixMethod · 0.80
IsIndicesSortedMethod · 0.80
SortIndicesMethod · 0.80

Tested by

no test coverage detected