Refactor tests with data generator. (#5439)

This commit is contained in:
Jiaming Yuan
2020-03-27 06:44:44 +08:00
committed by GitHub
parent 7146b91d5a
commit 4942da64ae
26 changed files with 334 additions and 259 deletions

View File

@@ -25,15 +25,13 @@ void TestPredictionFromGradientIndex(std::string name, size_t rows, int32_t bins
gbm::GBTreeModel model = CreateTestModel(&param, kClasses);
{
auto pp_ellpack = CreateDMatrix(rows, kCols, 0);
auto p_ellpack = *pp_ellpack;
auto p_ellpack = RandomDataGenerator(rows, kCols, 0).GenerateDMatix();
// Use same number of bins as rows.
for (auto const &page DMLC_ATTRIBUTE_UNUSED :
p_ellpack->GetBatches<Page>({0, static_cast<int32_t>(bins), 0})) {
}
auto pp_precise = CreateDMatrix(rows, kCols, 0);
auto p_precise = *pp_precise;
auto p_precise = RandomDataGenerator(rows, kCols, 0).GenerateDMatix();
PredictionCacheEntry approx_out_predictions;
predictor->PredictBatch(p_ellpack.get(), &approx_out_predictions, model, 0);
@@ -45,21 +43,16 @@ void TestPredictionFromGradientIndex(std::string name, size_t rows, int32_t bins
CHECK_EQ(approx_out_predictions.predictions.HostVector()[i],
precise_out_predictions.predictions.HostVector()[i]);
}
delete pp_precise;
delete pp_ellpack;
}
{
// Predictor should never try to create the histogram index by itself. As only
// histogram index from training data is valid and predictor doesn't known which
// matrix is used for training.
auto pp_dmat = CreateDMatrix(rows, kCols, 0);
auto p_dmat = *pp_dmat;
auto p_dmat = RandomDataGenerator(rows, kCols, 0).GenerateDMatix();
PredictionCacheEntry precise_out_predictions;
predictor->PredictBatch(p_dmat.get(), &precise_out_predictions, model, 0);
ASSERT_FALSE(p_dmat->PageExists<Page>());
delete pp_dmat;
}
}