22 * Copyright 2021-2024, XGBoost contributors
33 */
44#include < gtest/gtest.h>
5- #include < xgboost/data.h> // for BatchIterator, BatchSet, DMatrix, BatchParam
6-
7- #include < algorithm> // for sort, unique
8- #include < cmath> // for isnan
9- #include < cstddef> // for size_t
10- #include < limits> // for numeric_limits
11- #include < memory> // for shared_ptr, __shared_ptr_access, unique_ptr
12- #include < string> // for string
13- #include < tuple> // for make_tuple, tie, tuple
14- #include < utility> // for move
15- #include < vector> // for vector
5+ #include < xgboost/data.h> // for BatchIterator, BatchSet, DMatrix, BatchParam
6+
7+ #include < algorithm> // for sort, unique
8+ #include < cmath> // for isnan
9+ #include < cstddef> // for size_t
10+ #include < limits> // for numeric_limits
11+ #include < memory> // for shared_ptr, __shared_ptr_access, unique_ptr
12+ #include < string> // for string
13+ #include < tuple> // for make_tuple, tie, tuple
14+ #include < utility> // for move
15+ #include < vector> // for vector
1616
1717#include " ../../../src/common/categorical.h" // for AsCat
1818#include " ../../../src/common/column_matrix.h" // for ColumnMatrix
1919#include " ../../../src/common/hist_util.h" // for Index, HistogramCuts, SketchOnDMatrix
20- #include " ../../../src/common/io.h" // for MemoryBufferStream
2120#include " ../../../src/data/adapter.h" // for SparsePageAdapterBatch
2221#include " ../../../src/data/gradient_index.h" // for GHistIndexMatrix
2322#include " ../../../src/tree/param.h" // for TrainParam
23+ #include " ../common/test_hist_util.h" // for ValidateCuts
2424#include " ../helpers.h" // for GenerateRandomCategoricalSingleColumn...
2525#include " xgboost/base.h" // for bst_bin_t
2626#include " xgboost/context.h" // for Context
@@ -184,12 +184,8 @@ class GHistIndexMatrixTest : public testing::TestWithParam<std::tuple<float, flo
184184 ASSERT_EQ (from_sparse_page.Size (), from_ellpack->Size ());
185185 ASSERT_EQ (from_sparse_page.index .Size (), from_ellpack->index .Size ());
186186
187- auto const &gidx_from_sparse = from_sparse_page.index ;
188- auto const &gidx_from_ellpack = from_ellpack->index ;
189-
190- for (size_t i = 0 ; i < gidx_from_sparse.Size (); ++i) {
191- ASSERT_EQ (gidx_from_sparse[i], gidx_from_ellpack[i]);
192- }
187+ common::ValidateCuts (from_sparse_page.Cuts (), Xy.get (), kBins );
188+ common::ValidateCuts (from_ellpack->Cuts (), Xy.get (), kBins );
193189
194190 auto const &columns_from_sparse = from_sparse_page.Transpose ();
195191 auto const &columns_from_ellpack = from_ellpack->Transpose ();
@@ -199,20 +195,6 @@ class GHistIndexMatrixTest : public testing::TestWithParam<std::tuple<float, flo
199195 for (size_t i = 0 ; i < n_features; ++i) {
200196 ASSERT_EQ (columns_from_sparse.GetColumnType (i), columns_from_ellpack.GetColumnType (i));
201197 }
202-
203- std::string from_sparse_buf;
204- {
205- common::AlignedMemWriteStream fo{&from_sparse_buf};
206- auto n_bytes = columns_from_sparse.Write (&fo);
207- ASSERT_EQ (fo.Tell (), n_bytes);
208- }
209- std::string from_ellpack_buf;
210- {
211- common::AlignedMemWriteStream fo{&from_ellpack_buf};
212- auto n_bytes = columns_from_sparse.Write (&fo);
213- ASSERT_EQ (fo.Tell (), n_bytes);
214- }
215- ASSERT_EQ (from_sparse_buf, from_ellpack_buf);
216198 }
217199 }
218200};
0 commit comments