File: test_json_io.h

package info (click to toggle)
xgboost 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,796 kB
  • sloc: cpp: 67,502; python: 35,503; java: 4,676; ansic: 1,426; sh: 1,320; xml: 1,197; makefile: 204; javascript: 19
file content (41 lines) | stat: -rw-r--r-- 1,079 bytes parent folder | download | duplicates (2)
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_