| 162 | class GHistIndexMatrixTest : public testing::TestWithParam<std::tuple<float, float>> { |
| 163 | protected: |
| 164 | void Run(float density, double threshold) { |
| 165 | // Only testing with small sample size as the cuts might be different between host and |
| 166 | // device. |
| 167 | size_t n_samples{128}, n_features{13}; |
| 168 | Context ctx; |
| 169 | auto Xy = RandomDataGenerator{n_samples, n_features, 1 - density}.GenerateDMatrix(true); |
| 170 | std::unique_ptr<GHistIndexMatrix> from_ellpack; |
| 171 | ASSERT_TRUE(Xy->SingleColBlock()); |
| 172 | bst_bin_t constexpr kBins{17}; |
| 173 | auto p = BatchParam{kBins, threshold}; |
| 174 | auto gpu_ctx = MakeCUDACtx(0); |
| 175 | for (auto const &page : Xy->GetBatches<EllpackPage>( |
| 176 | &gpu_ctx, BatchParam{kBins, tree::TrainParam::DftSparseThreshold()})) { |
| 177 | from_ellpack = std::make_unique<GHistIndexMatrix>(&ctx, Xy->Info(), page, p); |
| 178 | } |
| 179 | |
| 180 | for (auto const &from_sparse_page : Xy->GetBatches<GHistIndexMatrix>(&ctx, p)) { |
| 181 | ASSERT_EQ(from_sparse_page.IsDense(), from_ellpack->IsDense()); |
| 182 | ASSERT_EQ(from_sparse_page.base_rowid, 0); |
| 183 | ASSERT_EQ(from_sparse_page.base_rowid, from_ellpack->base_rowid); |
| 184 | ASSERT_EQ(from_sparse_page.Size(), from_ellpack->Size()); |
| 185 | ASSERT_EQ(from_sparse_page.index.Size(), from_ellpack->index.Size()); |
| 186 | |
| 187 | common::ValidateCuts(from_sparse_page.Cuts(), Xy.get(), kBins); |
| 188 | common::ValidateCuts(from_ellpack->Cuts(), Xy.get(), kBins); |
| 189 | |
| 190 | auto const &columns_from_sparse = from_sparse_page.Transpose(); |
| 191 | auto const &columns_from_ellpack = from_ellpack->Transpose(); |
| 192 | ASSERT_EQ(columns_from_sparse.AnyMissing(), columns_from_ellpack.AnyMissing()); |
| 193 | ASSERT_EQ(columns_from_sparse.GetTypeSize(), columns_from_ellpack.GetTypeSize()); |
| 194 | ASSERT_EQ(columns_from_sparse.GetNumFeature(), columns_from_ellpack.GetNumFeature()); |
| 195 | for (size_t i = 0; i < n_features; ++i) { |
| 196 | ASSERT_EQ(columns_from_sparse.GetColumnType(i), columns_from_ellpack.GetColumnType(i)); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | }; |
| 201 | } // anonymous namespace |
| 202 |
no test coverage detected