| 22 | |
| 23 | namespace xgboost::common { |
| 24 | TEST(ColumnMatrix, Basic) { |
| 25 | int32_t max_num_bins[] = {static_cast<int32_t>(std::numeric_limits<uint8_t>::max()) + 1, |
| 26 | static_cast<int32_t>(std::numeric_limits<uint16_t>::max()) + 1, |
| 27 | static_cast<int32_t>(std::numeric_limits<uint16_t>::max()) + 2}; |
| 28 | Context ctx; |
| 29 | BinTypeSize last{kUint8BinsTypeSize}; |
| 30 | for (int32_t max_num_bin : max_num_bins) { |
| 31 | auto dmat = RandomDataGenerator(100, 10, 0.0).GenerateDMatrix(); |
| 32 | auto sparse_thresh = 0.2; |
| 33 | GHistIndexMatrix gmat{&ctx, dmat.get(), max_num_bin, sparse_thresh, false}; |
| 34 | ColumnMatrix column_matrix; |
| 35 | for (auto const& page : dmat->GetBatches<SparsePage>()) { |
| 36 | column_matrix.InitFromSparse(page, gmat, sparse_thresh, ctx.Threads()); |
| 37 | } |
| 38 | ASSERT_GE(column_matrix.GetTypeSize(), last); |
| 39 | ASSERT_LE(column_matrix.GetTypeSize(), kUint32BinsTypeSize); |
| 40 | last = column_matrix.GetTypeSize(); |
| 41 | ASSERT_FALSE(column_matrix.AnyMissing()); |
| 42 | for (auto i = 0ull; i < dmat->Info().num_row_; i++) { |
| 43 | for (auto j = 0ull; j < dmat->Info().num_col_; j++) { |
| 44 | DispatchBinType(column_matrix.GetTypeSize(), [&](auto dtype) { |
| 45 | using T = decltype(dtype); |
| 46 | auto col = column_matrix.DenseColumn<T, false>(j); |
| 47 | ASSERT_EQ(gmat.index[i * dmat->Info().num_col_ + j], col.GetGlobalBinIdx(i)); |
| 48 | }); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | template <typename BinIdxType> |
| 55 | void CheckSparseColumn(SparseColumnIter<BinIdxType>* p_col, const GHistIndexMatrix& gmat) { |
nothing calls this directly
no test coverage detected