Medial Code Documentation
Loading...
Searching...
No Matches
test_json_io.h
1
4#ifndef XGBOOST_TEST_JSON_IO_H_
5#define XGBOOST_TEST_JSON_IO_H_
6
7#include <xgboost/linear_updater.h>
8#include <xgboost/json.h>
9#include <string>
10#include "../helpers.h"
11#include "../../../src/gbm/gblinear_model.h"
12
13namespace xgboost {
14inline void TestUpdaterJsonIO(std::string updater_str) {
15 Context ctx{MakeCUDACtx(GPUIDX)};
16 Json config_0 {Object() };
17
18 {
19 auto updater =
20 std::unique_ptr<xgboost::LinearUpdater>(xgboost::LinearUpdater::Create(updater_str, &ctx));
21 updater->Configure({{"eta", std::to_string(3.14)}});
22 updater->SaveConfig(&config_0);
23 }
24
25 {
26 auto updater =
27 std::unique_ptr<xgboost::LinearUpdater>(xgboost::LinearUpdater::Create(updater_str, &ctx));
28 updater->LoadConfig(config_0);
29 Json config_1 { Object() };
30 updater->SaveConfig(&config_1);
31
32 ASSERT_EQ(config_0, config_1);
33 auto eta = atof(get<String const>(config_1["linear_train_param"]["eta"]).c_str());
34 ASSERT_NEAR(eta, 3.14, kRtEps);
35 }
36
37}
38
39} // namespace xgboost
40
41#endif // XGBOOST_TEST_JSON_IO_H_
static LinearUpdater * Create(const std::string &name, Context const *)
Create a linear updater given name.
Definition linear_updater.cc:14
float atof(const char *nptr)
A faster implementation of atof(). Unlike std::atof(), this function returns float type....
Definition strtonum.h:448
c_str(string)
Definition basic.py:110
namespace of xgboost
Definition base.h:90
Context MakeCUDACtx(std::int32_t device)
Make a context that uses CUDA if device >= 0.
Definition helpers.h:410
constexpr bst_float kRtEps
small eps gap for minimum split decision.
Definition base.h:319