11 #ifndef TREELITE_C_API_H_
12 #define TREELITE_C_API_H_
15 #define TREELITE_EXTERN_C extern "C"
19 #define TREELITE_EXTERN_C
25 #if defined(_MSC_VER) || defined(_WIN32)
26 #define TREELITE_DLL TREELITE_EXTERN_C __declspec(dllexport)
27 #define TREELITE_DLL_STRUCT TREELITE_EXTERN_C struct __declspec(dllexport)
29 #define TREELITE_DLL TREELITE_EXTERN_C __attribute__((visibility("default")))
30 #define TREELITE_DLL_STRUCT TREELITE_EXTERN_C struct __attribute__((visibility("default")))
168 int n_targets, int64_t
const* node_count, int64_t
const** children_left,
169 int64_t
const** children_right, int64_t
const** feature,
double const** threshold,
170 double const** value, int64_t
const** n_node_samples,
double const** weighted_n_node_samples,
199 int64_t
const* node_count, int64_t
const** children_left, int64_t
const** children_right,
200 int64_t
const** feature,
double const** threshold,
double const** value,
201 int64_t
const** n_node_samples,
double const** weighted_n_node_samples,
double const** impurity,
233 int n_targets, int32_t
const* n_classes, int64_t
const* node_count,
234 int64_t
const** children_left, int64_t
const** children_right, int64_t
const** feature,
235 double const** threshold,
double const** value, int64_t
const** n_node_samples,
236 double const** weighted_n_node_samples,
double const** impurity,
TreeliteModelHandle* out);
268 int64_t
const* node_count, int64_t
const** children_left, int64_t
const** children_right,
269 int64_t
const** feature,
double const** threshold,
double const** value,
270 int64_t
const** n_node_samples,
double const** weighted_n_node_samples,
double const** impurity,
304 int n_classes, int64_t
const* node_count, int64_t
const** children_left,
305 int64_t
const** children_right, int64_t
const** feature,
double const** threshold,
306 double const** value, int64_t
const** n_node_samples,
double const** weighted_n_node_samples,
339 int64_t
const* node_count,
void const** nodes,
int expected_sizeof_node_struct,
340 uint32_t n_categorical_splits, uint32_t
const** raw_left_cat_bitsets,
341 uint32_t
const* known_cat_bitsets, uint32_t
const* known_cat_bitsets_offset_map,
342 int32_t
const* features_map, int64_t
const** categories_map,
double const* base_scores,
378 int n_classes, int64_t
const* node_count,
void const** nodes,
int expected_sizeof_node_struct,
379 uint32_t n_categorical_splits, uint32_t
const** raw_left_cat_bitsets,
380 uint32_t
const* known_cat_bitsets, uint32_t
const* known_cat_bitsets_offset_map,
381 int32_t
const* features_map, int64_t
const** categories_map,
double const* base_scores,
466 int32_t split_index,
double threshold,
int default_left,
char const* cmp,
int left_child_key,
467 int right_child_key);
483 int32_t split_index,
int default_left, uint32_t
const* category_list,
size_t category_list_len,
484 int category_list_right_child,
int left_child_key,
int right_child_key);
735 char const* input_type, uint64_t
const* col_ind, uint64_t
const* row_ptr, uint64_t num_row,
char const * TreeliteGetLastError(void)
Display last error; can be called by multiple threads Note. Each thread will get the last error occur...
int TreeliteRegisterLogCallback(void(*callback)(char const *))
Register callback function for LOG(INFO) messages – helpful messages that are not errors....
char const * TREELITE_VERSION
int TreeliteRegisterWarningCallback(void(*callback)(char const *))
Register callback function for LOG(WARNING) messages Note: This function can be called by multiple th...
#define TREELITE_DLL_STRUCT
Definition: c_api.h:30
#define TREELITE_DLL
Definition: c_api.h:29
int TreeliteGetHeaderField(TreeliteModelHandle model, char const *name, TreelitePyBufferFrame *out_frame)
Get a field in the header.
int TreeliteGetTreeField(TreeliteModelHandle model, uint64_t tree_id, char const *name, TreelitePyBufferFrame *out_frame)
Get a field in a tree.
int TreeliteSetTreeField(TreeliteModelHandle model, uint64_t tree_id, char const *name, TreelitePyBufferFrame frame)
Set a field in a tree.
int TreeliteSetHeaderField(TreeliteModelHandle model, char const *name, TreelitePyBufferFrame frame)
Set a field in the header.
size_t nitem
Definition: c_api.h:57
char * format
Definition: c_api.h:55
struct TreelitePyBufferFrame TreelitePyBufferFrame
Represent a frame in the Python buffer protocol (PEP 3118).
Definition: c_api.h:62
size_t itemsize
Definition: c_api.h:56
int TreeliteGTILGetOutputShape(TreeliteModelHandle model, uint64_t num_row, TreeliteGTILConfigHandle config, uint64_t const **out, uint64_t *out_ndim)
Given a data matrix, query the necessary shape of array to hold predictions for all data points.
int TreeliteGTILParseConfig(char const *config_json, TreeliteGTILConfigHandle *out)
Load a configuration for GTIL predictor from a JSON string.
int TreeliteGTILPredictSparse(TreeliteModelHandle model, void const *data, char const *input_type, uint64_t const *col_ind, uint64_t const *row_ptr, uint64_t num_row, void *output, TreeliteGTILConfigHandle config)
Predict with sparse data with CSR (compressed sparse row) layout.
int TreeliteGTILPredict(TreeliteModelHandle model, void const *input, char const *input_type, uint64_t num_row, void *output, TreeliteGTILConfigHandle config)
Predict with a 2D dense array.
int TreeliteGTILDeleteConfig(TreeliteGTILConfigHandle handle)
Delete a GTIL configuration from memory.
int TreeliteDeleteModelBuilder(TreeliteModelBuilderHandle model_builder)
Delete model builder object from memory.
int TreeliteModelBuilderEndTree(TreeliteModelBuilderHandle model_builder)
End the current tree.
int TreeliteModelBuilderGain(TreeliteModelBuilderHandle model_builder, double gain)
Specify the gain (loss reduction) that's resulted from the current split.
int TreeliteModelBuilderStartNode(TreeliteModelBuilderHandle model_builder, int node_key)
Start a new node.
int TreeliteGetModelBuilder(char const *json_str, TreeliteModelBuilderHandle *out)
Initialize a model builder object from a JSON string.
int TreeliteModelBuilderLeafVectorFloat64(TreeliteModelBuilderHandle model_builder, double const *leaf_vector, size_t leaf_vector_len)
Declare the current node as a leaf node with a vector output (float64)
int TreeliteModelBuilderLeafVectorFloat32(TreeliteModelBuilderHandle model_builder, float const *leaf_vector, size_t leaf_vector_len)
Declare the current node as a leaf node with a vector output (float32)
int TreeliteModelBuilderNumericalTest(TreeliteModelBuilderHandle model_builder, int32_t split_index, double threshold, int default_left, char const *cmp, int left_child_key, int right_child_key)
Declare the current node as a numerical test node, where the test is of form [feature value] [cmp] [t...
int TreeliteModelBuilderLeafScalar(TreeliteModelBuilderHandle model_builder, double leaf_value)
Declare the current node as a leaf node with a scalar output.
int TreeliteModelBuilderDataCount(TreeliteModelBuilderHandle model_builder, uint64_t data_count)
Specify the number of data points (samples) that are mapped to the current node.
int TreeliteModelBuilderStartTree(TreeliteModelBuilderHandle model_builder)
Start a new tree.
int TreeliteModelBuilderCommitModel(TreeliteModelBuilderHandle model_builder, TreeliteModelHandle *out)
Conclude model building and obtain the final model object.
int TreeliteModelBuilderSumHess(TreeliteModelBuilderHandle model_builder, double sum_hess)
Specify the weighted sample count or the sum of Hessians for the data points that are mapped to the c...
int TreeliteModelBuilderEndNode(TreeliteModelBuilderHandle model_builder)
End the current node.
int TreeliteModelBuilderCategoricalTest(TreeliteModelBuilderHandle model_builder, int32_t split_index, int default_left, uint32_t const *category_list, size_t category_list_len, int category_list_right_child, int left_child_key, int right_child_key)
Declare the current node as a categorical test node, where the test is of form [feature value] \in [c...
int TreeliteLoadLightGBMModel(char const *filename, char const *config_json, TreeliteModelHandle *out)
Load a model file generated by LightGBM (Microsoft/LightGBM). The model file must contain a decision ...
int TreeliteLoadXGBoostModel(char const *filename, char const *config_json, TreeliteModelHandle *out)
Load a model file generated by XGBoost (dmlc/xgboost), stored in the JSON format.
int TreeliteLoadLightGBMModelFromString(char const *model_str, char const *config_json, TreeliteModelHandle *out)
Load a LightGBM model from a string. The string should be created with the model_to_string() method i...
int TreeliteLoadXGBoostModelLegacyBinaryFromMemoryBuffer(void const *buf, size_t len, char const *config_json, TreeliteModelHandle *out)
Load an XGBoost model from a memory buffer using the legacy binary format.
int TreeliteLoadXGBoostModelLegacyBinary(char const *filename, char const *config_json, TreeliteModelHandle *out)
Load a model file generated by XGBoost (dmlc/xgboost), stored in the legacy binary format.
int TreeliteLoadXGBoostModelFromString(char const *json_str, size_t length, char const *config_json, TreeliteModelHandle *out)
Load an XGBoost model from a JSON string.
int TreeliteFreeModel(TreeliteModelHandle handle)
Delete model from memory.
int TreeliteDumpAsJSON(TreeliteModelHandle handle, int pretty_print, char const **out_json_str)
Dump a model object as a JSON string.
int TreeliteConcatenateModelObjects(TreeliteModelHandle const *objs, size_t len, TreeliteModelHandle *out)
Concatenate multiple model objects into a single model object by copying all member trees into the de...
int TreeliteGetOutputType(TreeliteModelHandle model, char const **out_str)
Query the output type of a Treelite model object.
int TreeliteQueryNumFeature(TreeliteModelHandle model, int *out)
Query the number of features used in the model.
int TreeliteGetInputType(TreeliteModelHandle model, char const **out_str)
Query the input type of a Treelite model object.
int TreeliteQueryNumTree(TreeliteModelHandle model, size_t *out)
Query the number of trees in the model.
void * TreeliteGTILConfigHandle
Handle to a configuration of GTIL predictor.
Definition: c_api.h:42
void * TreeliteModelBuilderHandle
Handle to a model builder object.
Definition: c_api.h:40
void * TreeliteModelHandle
Handle to a decision tree ensemble model.
Definition: c_api.h:38
int TreeliteSerializeModelToPyBuffer(TreeliteModelHandle handle, TreelitePyBufferFrame **out_frames, size_t *out_num_frames)
Serialize a model object using the Python buffer protocol (PEP 3118).
int TreeliteDeserializeModelFromPyBuffer(TreelitePyBufferFrame *frames, size_t num_frames, TreeliteModelHandle *out)
Deserialize a model object using the Python buffer protocol (PEP 3118).
int TreeliteSerializeModelToBytes(TreeliteModelHandle handle, char const **out_bytes, size_t *out_bytes_len)
Serialize (persist) a model object to a byte sequence.
int TreeliteDeserializeModelFromFile(char const *filename, TreeliteModelHandle *out)
Deserialize (load) a model object from disk.
int TreeliteSerializeModelToFile(TreeliteModelHandle handle, char const *filename)
Serialize (persist) a model object to disk.
int TreeliteDeserializeModelFromBytes(char const *bytes, size_t bytes_len, TreeliteModelHandle *out)
Deserialize (load) a model object from a byte sequence.
int TreeliteLoadSKLearnHistGradientBoostingRegressor(int n_iter, int n_features, int64_t const *node_count, void const **nodes, int expected_sizeof_node_struct, uint32_t n_categorical_splits, uint32_t const **raw_left_cat_bitsets, uint32_t const *known_cat_bitsets, uint32_t const *known_cat_bitsets_offset_map, int32_t const *features_map, int64_t const **categories_map, double const *base_scores, TreeliteModelHandle *out)
Load a scikit-learn HistGradientBoostingRegressor model from a collection of arrays....
int TreeliteLoadSKLearnRandomForestRegressor(int n_estimators, int n_features, int n_targets, int64_t const *node_count, int64_t const **children_left, int64_t const **children_right, int64_t const **feature, double const **threshold, double const **value, int64_t const **n_node_samples, double const **weighted_n_node_samples, double const **impurity, TreeliteModelHandle *out)
Load a scikit-learn RandomForestRegressor model from a collection of arrays. Refer to https://scikit-...
int TreeliteLoadSKLearnIsolationForest(int n_estimators, int n_features, int64_t const *node_count, int64_t const **children_left, int64_t const **children_right, int64_t const **feature, double const **threshold, double const **value, int64_t const **n_node_samples, double const **weighted_n_node_samples, double const **impurity, double ratio_c, TreeliteModelHandle *out)
Load a scikit-learn IsolationForest model from a collection of arrays. Refer to https://scikit-learn....
int TreeliteLoadSKLearnHistGradientBoostingClassifier(int n_iter, int n_features, int n_classes, int64_t const *node_count, void const **nodes, int expected_sizeof_node_struct, uint32_t n_categorical_splits, uint32_t const **raw_left_cat_bitsets, uint32_t const *known_cat_bitsets, uint32_t const *known_cat_bitsets_offset_map, int32_t const *features_map, int64_t const **categories_map, double const *base_scores, TreeliteModelHandle *out)
Load a scikit-learn HistGradientBoostingClassifier model from a collection of arrays....
int TreeliteLoadSKLearnRandomForestClassifier(int n_estimators, int n_features, int n_targets, int32_t const *n_classes, int64_t const *node_count, int64_t const **children_left, int64_t const **children_right, int64_t const **feature, double const **threshold, double const **value, int64_t const **n_node_samples, double const **weighted_n_node_samples, double const **impurity, TreeliteModelHandle *out)
Load a scikit-learn RandomForestClassifier model from a collection of arrays. Refer to https://scikit...
int TreeliteLoadSKLearnGradientBoostingRegressor(int n_iter, int n_features, int64_t const *node_count, int64_t const **children_left, int64_t const **children_right, int64_t const **feature, double const **threshold, double const **value, int64_t const **n_node_samples, double const **weighted_n_node_samples, double const **impurity, double const *base_scores, TreeliteModelHandle *out)
Load a scikit-learn GradientBoostingRegressor model from a collection of arrays. Refer to https://sci...
int TreeliteLoadSKLearnGradientBoostingClassifier(int n_iter, int n_features, int n_classes, int64_t const *node_count, int64_t const **children_left, int64_t const **children_right, int64_t const **feature, double const **threshold, double const **value, int64_t const **n_node_samples, double const **weighted_n_node_samples, double const **impurity, double const *base_scores, TreeliteModelHandle *out)
Load a scikit-learn GradientBoostingClassifier model from a collection of arrays. Refer to https://sc...