forked from dmlc/treelite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_loader.cc
More file actions
115 lines (101 loc) · 4.23 KB
/
model_loader.cc
File metadata and controls
115 lines (101 loc) · 4.23 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*!
* Copyright (c) 2023 by Contributors
* \file model_loader.cc
* \author Hyunsu Cho
* \brief C API for frontend functions
*/
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
#include <treelite/c_api.h>
#include <treelite/c_api_error.h>
#include <treelite/model_loader.h>
#include <treelite/tree.h>
#include "./c_api_utils.h"
int TreeliteLoadXGBoostModelLegacyBinary(
char const* filename, [[maybe_unused]] char const* config_json, TreeliteModelHandle* out) {
// config_json is unused for now
API_BEGIN();
std::unique_ptr<treelite::Model> model
= treelite::model_loader::LoadXGBoostModelLegacyBinary(filename);
*out = static_cast<TreeliteModelHandle>(model.release());
API_END();
}
int TreeliteLoadXGBoostModelLegacyBinaryFromMemoryBuffer(void const* buf, std::uint64_t len,
[[maybe_unused]] char const* config_json, TreeliteModelHandle* out) {
// config_json is unused for now
API_BEGIN();
std::unique_ptr<treelite::Model> model
= treelite::model_loader::LoadXGBoostModelLegacyBinary(buf, len);
*out = static_cast<TreeliteModelHandle>(model.release());
API_END();
}
int TreeliteLoadXGBoostModel(
char const* filename, char const* config_json, TreeliteModelHandle* out) {
TREELITE_LOG(WARNING) << "TreeliteLoadXGBoostModel() is deprecated. Please use "
<< "TreeliteLoadXGBoostModelJSON() instead.";
return TreeliteLoadXGBoostModelJSON(filename, config_json, out);
}
int TreeliteLoadXGBoostModelFromString(
char const* json_str, std::size_t length, char const* config_json, TreeliteModelHandle* out) {
TREELITE_LOG(WARNING) << "TreeliteLoadXGBoostModelFromString() is deprecated. Please use "
<< "TreeliteLoadXGBoostModelFromJSONString() instead.";
return TreeliteLoadXGBoostModelFromJSONString(json_str, length, config_json, out);
}
int TreeliteLoadXGBoostModelJSON(
char const* filename, char const* config_json, TreeliteModelHandle* out) {
API_BEGIN();
std::unique_ptr<treelite::Model> model
= treelite::model_loader::LoadXGBoostModelJSON(filename, config_json);
*out = static_cast<TreeliteModelHandle>(model.release());
API_END();
}
int TreeliteLoadXGBoostModelFromJSONString(
char const* json_str, std::size_t length, char const* config_json, TreeliteModelHandle* out) {
API_BEGIN();
std::unique_ptr<treelite::Model> model = treelite::model_loader::LoadXGBoostModelFromJSONString(
std::string_view{json_str, length}, config_json);
*out = static_cast<TreeliteModelHandle>(model.release());
API_END();
}
int TreeliteLoadXGBoostModelUBJSON(
char const* filename, char const* config_json, TreeliteModelHandle* out) {
API_BEGIN();
std::unique_ptr<treelite::Model> model
= treelite::model_loader::LoadXGBoostModelUBJSON(filename, config_json);
*out = static_cast<TreeliteModelHandle>(model.release());
API_END();
}
int TreeliteLoadXGBoostModelFromUBJSONString(
char const* ubjson_str, std::size_t length, char const* config_json, TreeliteModelHandle* out) {
API_BEGIN();
std::unique_ptr<treelite::Model> model = treelite::model_loader::LoadXGBoostModelFromUBJSONString(
std::string_view{ubjson_str, length}, config_json);
*out = static_cast<TreeliteModelHandle>(model.release());
API_END();
}
int TreeliteDetectXGBoostFormat(char const* filename, char const** out_str) {
API_BEGIN();
std::string& ret_str = treelite::c_api::ReturnValueStore::Get()->ret_str;
ret_str = treelite::model_loader::DetectXGBoostFormat(filename);
*out_str = ret_str.c_str();
API_END();
}
int TreeliteLoadLightGBMModel(
char const* filename, [[maybe_unused]] char const* config_json, TreeliteModelHandle* out) {
// config_json is unused for now
API_BEGIN();
std::unique_ptr<treelite::Model> model = treelite::model_loader::LoadLightGBMModel(filename);
*out = static_cast<TreeliteModelHandle>(model.release());
API_END();
}
TREELITE_DLL int TreeliteLoadLightGBMModelFromString(
char const* model_str, [[maybe_unused]] char const* config_json, TreeliteModelHandle* out) {
// config_json is unused for now
API_BEGIN();
std::unique_ptr<treelite::Model> model
= treelite::model_loader::LoadLightGBMModelFromString(model_str);
*out = static_cast<TreeliteModelHandle>(model.release());
API_END();
}