| 27 | } |
| 28 | |
| 29 | void RunLearnerTest(Context const* ctx, std::string updater_name, float subsample, |
| 30 | std::string const& grow_policy, std::string const& strategy) { |
| 31 | std::unique_ptr<Learner> learner{Learner::Create({Xy_})}; |
| 32 | learner->SetParam("device", ctx->DeviceName()); |
| 33 | learner->SetParam("updater", updater_name); |
| 34 | learner->SetParam("multi_strategy", strategy); |
| 35 | learner->SetParam("grow_policy", grow_policy); |
| 36 | learner->SetParam("subsample", std::to_string(subsample)); |
| 37 | learner->SetParam("nthread", "0"); |
| 38 | learner->Configure(); |
| 39 | |
| 40 | for (size_t i = 0; i < 8; ++i) { |
| 41 | learner->UpdateOneIter(i, Xy_); |
| 42 | } |
| 43 | |
| 44 | HostDeviceVector<float> out_prediction_cached; |
| 45 | learner->Predict(Xy_, false, &out_prediction_cached, 0, 0); |
| 46 | |
| 47 | Json model{Object()}; |
| 48 | learner->SaveModel(&model); |
| 49 | |
| 50 | HostDeviceVector<float> out_prediction; |
| 51 | { |
| 52 | std::unique_ptr<Learner> learner{Learner::Create({Xy_})}; |
| 53 | learner->LoadModel(model); |
| 54 | learner->Predict(Xy_, false, &out_prediction, 0, 0); |
| 55 | } |
| 56 | |
| 57 | auto const h_predt_cached = out_prediction_cached.ConstHostSpan(); |
| 58 | auto const h_predt = out_prediction.ConstHostSpan(); |
| 59 | |
| 60 | ASSERT_EQ(h_predt.size(), h_predt_cached.size()); |
| 61 | for (size_t i = 0; i < h_predt.size(); ++i) { |
| 62 | ASSERT_NEAR(h_predt[i], h_predt_cached[i], kRtEps); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | void RunTest(Context* ctx, std::string const& updater_name, std::string const& strategy) { |
| 67 | { |
no test coverage detected