Refactor tests with data generator. (#5439)
This commit is contained in:
@@ -9,26 +9,25 @@ namespace xgboost {
|
||||
namespace common {
|
||||
|
||||
TEST(DenseColumn, Test) {
|
||||
auto dmat = CreateDMatrix(100, 10, 0.0);
|
||||
auto dmat = RandomDataGenerator(100, 10, 0.0).GenerateDMatix();
|
||||
GHistIndexMatrix gmat;
|
||||
gmat.Init((*dmat).get(), 256);
|
||||
gmat.Init(dmat.get(), 256);
|
||||
ColumnMatrix column_matrix;
|
||||
column_matrix.Init(gmat, 0.2);
|
||||
|
||||
for (auto i = 0ull; i < (*dmat)->Info().num_row_; i++) {
|
||||
for (auto j = 0ull; j < (*dmat)->Info().num_col_; j++) {
|
||||
for (auto i = 0ull; i < dmat->Info().num_row_; i++) {
|
||||
for (auto j = 0ull; j < dmat->Info().num_col_; j++) {
|
||||
auto col = column_matrix.GetColumn(j);
|
||||
ASSERT_EQ(gmat.index[i * (*dmat)->Info().num_col_ + j],
|
||||
ASSERT_EQ(gmat.index[i * dmat->Info().num_col_ + j],
|
||||
col.GetGlobalBinIdx(i));
|
||||
}
|
||||
}
|
||||
delete dmat;
|
||||
}
|
||||
|
||||
TEST(SparseColumn, Test) {
|
||||
auto dmat = CreateDMatrix(100, 1, 0.85);
|
||||
auto dmat = RandomDataGenerator(100, 1, 0.85).GenerateDMatix();
|
||||
GHistIndexMatrix gmat;
|
||||
gmat.Init((*dmat).get(), 256);
|
||||
gmat.Init(dmat.get(), 256);
|
||||
ColumnMatrix column_matrix;
|
||||
column_matrix.Init(gmat, 0.5);
|
||||
auto col = column_matrix.GetColumn(0);
|
||||
@@ -37,13 +36,12 @@ TEST(SparseColumn, Test) {
|
||||
ASSERT_EQ(gmat.index[gmat.row_ptr[col.GetRowIdx(i)]],
|
||||
col.GetGlobalBinIdx(i));
|
||||
}
|
||||
delete dmat;
|
||||
}
|
||||
|
||||
TEST(DenseColumnWithMissing, Test) {
|
||||
auto dmat = CreateDMatrix(100, 1, 0.5);
|
||||
auto dmat = RandomDataGenerator(100, 1, 0.5).GenerateDMatix();
|
||||
GHistIndexMatrix gmat;
|
||||
gmat.Init((*dmat).get(), 256);
|
||||
gmat.Init(dmat.get(), 256);
|
||||
ColumnMatrix column_matrix;
|
||||
column_matrix.Init(gmat, 0.2);
|
||||
auto col = column_matrix.GetColumn(0);
|
||||
@@ -52,7 +50,6 @@ TEST(DenseColumnWithMissing, Test) {
|
||||
EXPECT_EQ(gmat.index[gmat.row_ptr[col.GetRowIdx(i)]],
|
||||
col.GetGlobalBinIdx(i));
|
||||
}
|
||||
delete dmat;
|
||||
}
|
||||
|
||||
void TestGHistIndexMatrixCreation(size_t nthreads) {
|
||||
|
||||
Reference in New Issue
Block a user