MCPcopy Create free account
hub / github.com/dmlc/xgboost / TestBasic

Function TestBasic

tests/cpp/predictor/test_predictor.cc:33–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32namespace xgboost {
33void 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
62void TestBatchPredictionWithWeights(Context const *ctx) {
63 size_t constexpr kRows = 5, kCols = 5;

Callers 3

TESTFunction · 0.70
TestColumnSplitFunction · 0.70
TESTFunction · 0.50

Calls 9

CreatePredictorForTestFunction · 0.85
MakeMPFunction · 0.85
CreateTestModelFunction · 0.85
InitOutPredictionsMethod · 0.80
InfoMethod · 0.45
DeviceMethod · 0.45
PredictBatchMethod · 0.45
SizeMethod · 0.45
PredictLeafMethod · 0.45

Tested by

no test coverage detected