| 31 | |
| 32 | namespace xgboost { |
| 33 | void TestBasic(DMatrix *dmat, Context const *ctx) { |
| 34 | auto predictor = std::unique_ptr<Predictor>(CreatePredictorForTest(ctx)); |
| 35 | |
| 36 | size_t const kCols = dmat->Info().num_col_; |
| 37 | |
| 38 | LearnerModelParam mparam{MakeMP(kCols, .0, 1, ctx->Device())}; |
| 39 | |
| 40 | std::unique_ptr<gbm::GBTreeModel> p_model = CreateTestModel(&mparam, ctx); |
| 41 | auto const &model = *p_model; |
| 42 | |
| 43 | // Test predict batch |
| 44 | PredictionCacheEntry out_predictions; |
| 45 | predictor->InitOutPredictions(dmat->Info(), &out_predictions.predictions, model); |
| 46 | predictor->PredictBatch(dmat, &out_predictions, model, 0); |
| 47 | |
| 48 | std::vector<float> &out_predictions_h = out_predictions.predictions.HostVector(); |
| 49 | for (size_t i = 0; i < out_predictions.predictions.Size(); i++) { |
| 50 | ASSERT_EQ(out_predictions_h[i], 1.5); |
| 51 | } |
| 52 | |
| 53 | // Test predict leaf |
| 54 | HostDeviceVector<float> leaf_out_predictions; |
| 55 | predictor->PredictLeaf(dmat, &leaf_out_predictions, model); |
| 56 | auto const &h_leaf_out_predictions = leaf_out_predictions.ConstHostVector(); |
| 57 | for (auto v : h_leaf_out_predictions) { |
| 58 | ASSERT_EQ(v, 0); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void TestBatchPredictionWithWeights(Context const *ctx) { |
| 63 | size_t constexpr kRows = 5, kCols = 5; |
no test coverage detected