1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
/*!
* Copyright 2020 XGBoost contributors
*/
#ifndef XGBOOST_TEST_JSON_IO_H_
#define XGBOOST_TEST_JSON_IO_H_
#include <xgboost/linear_updater.h>
#include <xgboost/json.h>
#include <string>
#include "../helpers.h"
#include "../../../src/gbm/gblinear_model.h"
namespace xgboost {
inline void TestUpdaterJsonIO(std::string updater_str) {
Context ctx{MakeCUDACtx(GPUIDX)};
Json config_0 {Object() };
{
auto updater =
std::unique_ptr<xgboost::LinearUpdater>(xgboost::LinearUpdater::Create(updater_str, &ctx));
updater->Configure({{"eta", std::to_string(3.14)}});
updater->SaveConfig(&config_0);
}
{
auto updater =
std::unique_ptr<xgboost::LinearUpdater>(xgboost::LinearUpdater::Create(updater_str, &ctx));
updater->LoadConfig(config_0);
Json config_1 { Object() };
updater->SaveConfig(&config_1);
ASSERT_EQ(config_0, config_1);
auto eta = atof(get<String const>(config_1["linear_train_param"]["eta"]).c_str());
ASSERT_NEAR(eta, 3.14, kRtEps);
}
}
} // namespace xgboost
#endif // XGBOOST_TEST_JSON_IO_H_
|