6 #ifndef XGBOOST_C_API_H_
7 #define XGBOOST_C_API_H_
10 #define XGB_EXTERN_C extern "C"
21 #if defined(_MSC_VER) || defined(_WIN32)
22 #define XGB_DLL XGB_EXTERN_C __declspec(dllexport)
24 #define XGB_DLL XGB_EXTERN_C __attribute__((visibility("default")))
751 const char **features,
const bst_ulong size);
789 const char ***out_features);
890 const float **out_dptr);
904 const unsigned **out_dptr);
963 bst_ulong *out_indptr,
unsigned *out_indices,
float *out_data);
981 char const **out_indptr,
char const **out_data);
1115 char const *grad,
char const *hess);
1128 const char *evnames[],
bst_ulong len,
const char **out_result);
1169 unsigned ntree_limit,
int training,
bst_ulong *out_len,
1170 const float **out_result);
1231 char const *config,
bst_ulong const **out_shape,
1232 bst_ulong *out_dim,
float const **out_result);
1259 bst_ulong *out_dim,
const float **out_result);
1287 const float **out_result);
1313 char const *values,
bst_ulong ncol,
char const *config,
1315 bst_ulong *out_dim,
const float **out_result);
1339 const float **out_result);
1363 const float **out_result);
1438 char const **out_dptr);
1450 const char **out_dptr);
1497 bst_ulong *out_len,
const char ***out_dump_array);
1511 const char ***out_dump_array);
1525 const char **ftype,
int with_stats,
bst_ulong *out_len,
1526 const char ***out_models);
1541 const char **ftype,
int with_stats,
const char *format,
1542 bst_ulong *out_len,
const char ***out_models);
1607 const char **features,
const bst_ulong size);
1629 const char ***out_features);
1657 bst_ulong *out_n_features,
char const ***out_features,
1659 float const **out_scores);
#define XGB_EXTERN_C
C API of XGBoost, used to interface with other high-level languages.
Definition: c_api.h:15
#define XGB_DLL
Definition: c_api.h:24
uint64_t bst_ulong
Definition: c_api.h:28
int XGBoosterBoostedRounds(BoosterHandle handle, int *out)
Get number of boosted rounds from gradient booster. When process_type is update, this number might dr...
int XGBoosterSetAttr(BoosterHandle handle, const char *key, const char *value)
Set or delete string attribute.
int XGBoosterFeatureScore(BoosterHandle handle, const char *config, bst_ulong *out_n_features, char const ***out_features, bst_ulong *out_dim, bst_ulong const **out_shape, float const **out_scores)
Calculate feature scores for tree models. When used on linear model, only the weight importance type ...
int XGBoosterGetNumFeature(BoosterHandle handle, bst_ulong *out)
get number of features
int XGBoosterFree(BoosterHandle handle)
Delete the booster.
int XGBoosterGetAttr(BoosterHandle handle, const char *key, const char **out, int *success)
Get string attribute from Booster.
int XGBoosterSetStrFeatureInfo(BoosterHandle handle, const char *field, const char **features, const bst_ulong size)
Set string encoded feature info in Booster, similar to the feature info in DMatrix.
int XGBoosterGetCategories(BoosterHandle handle, char const *config, CategoriesHandle *out)
int XGBoosterSlice(BoosterHandle handle, int begin_layer, int end_layer, int step, BoosterHandle *out)
Slice a model using boosting index. The slice m:n indicates taking all trees that were fit during the...
int XGBoosterGetStrFeatureInfo(BoosterHandle handle, const char *field, bst_ulong *len, const char ***out_features)
Get string encoded feature info from Booster, similar to the feature info in DMatrix.
int XGBoosterEvalOneIter(BoosterHandle handle, int iter, DMatrixHandle dmats[], const char *evnames[], bst_ulong len, const char **out_result)
get evaluation statistics for xgboost
int XGBoosterUpdateOneIter(BoosterHandle handle, int iter, DMatrixHandle dtrain)
update the model in one round using dtrain
int XGBoosterSetParam(BoosterHandle handle, const char *name, const char *value)
set parameters
int XGBoosterDumpModelWithFeatures(BoosterHandle handle, int fnum, const char **fname, const char **ftype, int with_stats, bst_ulong *out_len, const char ***out_models)
dump model, return array of strings representing model dump
int XGBoosterDumpModelEx(BoosterHandle handle, const char *fmap, int with_stats, const char *format, bst_ulong *out_len, const char ***out_dump_array)
dump model, return array of strings representing model dump
int XGBoosterGetAttrNames(BoosterHandle handle, bst_ulong *out_len, const char ***out)
Get the names of all attribute from Booster.
int XGBoosterBoostOneIter(BoosterHandle handle, DMatrixHandle dtrain, float *grad, float *hess, bst_ulong len)
int XGBoosterGetCategoriesExportToArrow(BoosterHandle handle, char const *config, CategoriesHandle *out, char const **export_out)
int XGBoosterTrainOneIter(BoosterHandle handle, DMatrixHandle dtrain, int iter, char const *grad, char const *hess)
Update a model with gradient and Hessian. This is used for training with a custom objective function.
int XGBoosterCreate(const DMatrixHandle dmats[], bst_ulong len, BoosterHandle *out)
Create a XGBoost learner (booster)
int XGBoosterDumpModel(BoosterHandle handle, const char *fmap, int with_stats, bst_ulong *out_len, const char ***out_dump_array)
dump model, return array of strings representing model dump
int XGBoosterReset(BoosterHandle handle)
Reset the booster object to release data caches used for training.
int XGBoosterDumpModelExWithFeatures(BoosterHandle handle, int fnum, const char **fname, const char **ftype, int with_stats, const char *format, bst_ulong *out_len, const char ***out_models)
dump model, return array of strings representing model dump
int XGTrackerRun(TrackerHandle handle, char const *config)
Start the tracker. The tracker runs in the background and this function returns once the tracker is s...
int XGCommunicatorAllreduce(void *send_receive_buffer, size_t count, int data_type, int op)
Perform in-place allreduce. This function is NOT thread-safe.
int XGTrackerWaitFor(TrackerHandle handle, char const *config)
Wait for the tracker to finish, should be called after XGTrackerRun(). This function will block until...
int XGCommunicatorGetWorldSize(void)
Get the total number of processes.
int XGTrackerCreate(char const *config, TrackerHandle *handle)
Create a new tracker.
int XGCommunicatorBroadcast(void *send_receive_buffer, size_t size, int root)
Broadcast a memory region to all others from root. This function is NOT thread-safe.
int XGCommunicatorGetRank(void)
Get rank of the current process.
int XGCommunicatorPrint(char const *message)
Print the message to the tracker.
int XGCommunicatorInit(char const *config)
Initialize the collective communicator.
void * TrackerHandle
Handle to the tracker.
Definition: c_api.h:1699
int XGCommunicatorGetProcessorName(const char **name_str)
Get the name of the processor.
int XGCommunicatorFinalize(void)
Finalize the collective communicator.
int XGCommunicatorIsDistributed(void)
Get if the communicator is distributed.
int XGTrackerFree(TrackerHandle handle)
Free a tracker instance. This should be called after XGTrackerWaitFor(). If the tracker is not proper...
int XGTrackerWorkerArgs(TrackerHandle handle, char const **args)
Get the arguments needed for running workers. This should be called after XGTrackerRun().
int XGDMatrixDataSplitMode(DMatrixHandle handle, bst_ulong *out)
Get the data split mode from DMatrix.
int XGDMatrixSetUIntInfo(DMatrixHandle handle, const char *field, const unsigned *array, bst_ulong len)
int XGDMatrixSetStrFeatureInfo(DMatrixHandle handle, const char *field, const char **features, const bst_ulong size)
Set string encoded information of all features.
int XGDMatrixGetCategories(DMatrixHandle handle, char const *config, CategoriesHandle *out)
Create an opaque handle to the internal category container.
int XGDMatrixFree(DMatrixHandle handle)
Free a DMatrix object.
int XGDMatrixCreateFromCudaColumnar(char const *data, char const *config, DMatrixHandle *out)
Create DMatrix from CUDA columnar format. (cuDF)
int XGDMatrixCreateFromDense(char const *data, char const *config, DMatrixHandle *out)
Create a DMatrix from dense array.
int XGDMatrixSaveBinary(DMatrixHandle handle, const char *fname, int silent)
Save the DMatrix object into a file. QuantileDMatrix and external memory DMatrix are not supported.
int XGDMatrixSliceDMatrix(DMatrixHandle handle, const int *idxset, bst_ulong len, DMatrixHandle *out)
create a new dmatrix from sliced content of existing matrix
int XGDMatrixNumRow(DMatrixHandle handle, bst_ulong *out)
Get the number of rows from a DMatrix.
int XGDMatrixSliceDMatrixEx(DMatrixHandle handle, const int *idxset, bst_ulong len, DMatrixHandle *out, int allow_groups)
create a new dmatrix from sliced content of existing matrix
int XGDMatrixCreateFromCSR(char const *indptr, char const *indices, char const *data, bst_ulong ncol, char const *config, DMatrixHandle *out)
Create a DMatrix from CSR matrix.
int XGDMatrixCreateFromFile(const char *fname, int silent, DMatrixHandle *out)
load a data matrix
int XGDMatrixCreateFromCudaArrayInterface(char const *data, char const *config, DMatrixHandle *out)
Create DMatrix from CUDA array.
int XGDMatrixNumNonMissing(DMatrixHandle handle, bst_ulong *out)
Get number of valid values from a DMatrix.
int XGDMatrixGetDataAsCSR(DMatrixHandle const handle, char const *config, bst_ulong *out_indptr, unsigned *out_indices, float *out_data)
Get the predictors from DMatrix as CSR matrix for testing. If this is a quantized DMatrix,...
int XGDMatrixGetStrFeatureInfo(DMatrixHandle handle, const char *field, bst_ulong *size, const char ***out_features)
Get string encoded information of all features.
int XGDMatrixCreateFromMat_omp(const float *data, bst_ulong nrow, bst_ulong ncol, float missing, DMatrixHandle *out, int nthread)
create matrix content from dense matrix
int XGDMatrixGetUIntInfo(const DMatrixHandle handle, const char *field, bst_ulong *out_len, const unsigned **out_dptr)
get uint32 info vector from matrix
int XGDMatrixNumCol(DMatrixHandle handle, bst_ulong *out)
Get the number of columns from a DMatrix.
int XGDMatrixSetFloatInfo(DMatrixHandle handle, const char *field, const float *array, bst_ulong len)
set float vector to a content in info
int XGDMatrixGetInfoRef(DMatrixHandle handle, char const *field, char const **out_array)
Get a reference to data like label or weight.
int XGDMatrixGetQuantileCut(DMatrixHandle const handle, char const *config, char const **out_indptr, char const **out_data)
Export the quantile cuts used for training histogram-based models like hist and approx....
int XGDMatrixSetInfoFromInterface(DMatrixHandle handle, char const *field, char const *data)
Set content in array interface to a content in info.
int XGDMatrixSetDenseInfo(DMatrixHandle handle, const char *field, void const *data, bst_ulong size, int type)
int XGDMatrixCreateFromColumnar(char const *data, char const *config, DMatrixHandle *out)
Create a DMatrix from columnar data. (table)
int XGDMatrixCreateFromURI(char const *config, DMatrixHandle *out)
load a data matrix
int XGDMatrixCreateFromCSC(char const *indptr, char const *indices, char const *data, bst_ulong nrow, char const *config, DMatrixHandle *out)
Create a DMatrix from a CSC matrix.
int XGDMatrixGetCategoriesExportToArrow(DMatrixHandle handle, char const *config, CategoriesHandle *out, char const **export_out)
Create an opaque handle to the internal container and export it to arrow.
int XGDMatrixCreateFromMat(const float *data, bst_ulong nrow, bst_ulong ncol, float missing, DMatrixHandle *out)
create matrix content from dense matrix
int XGDMatrixGetFloatInfo(const DMatrixHandle handle, const char *field, bst_ulong *out_len, const float **out_dptr)
get float info vector from matrix.
int XGBCategoriesFree(CategoriesHandle handle)
Free the opaque handle.
int XGBGetGlobalConfig(char const **out_config)
Get current global configuration (collection of parameters that apply globally).
void * BoosterHandle
Handle to the Booster.
Definition: c_api.h:51
const char * XGBGetLastError()
Get the string message of the last error.
void * CategoriesHandle
Handle to the categories container.
Definition: c_api.h:57
int XGBSetGlobalConfig(char const *config)
Set global configuration (collection of parameters that apply globally). This function accepts the li...
int XGBuildInfo(char const **out)
Get compile information of the shared XGBoost library.
void * DMatrixHandle
Handle to the DMatrix.
Definition: c_api.h:49
int XGBRegisterLogCallback(void(*callback)(const char *))
register callback function for LOG(INFO) messages – helpful messages that are not errors.
void XGBoostVersion(int *major, int *minor, int *patch)
Return the version of the XGBoost library.
int XGBoosterPredictFromCudaArray(BoosterHandle handle, char const *values, char const *config, DMatrixHandle proxy, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
Inplace prediction from CUDA Dense matrix (cupy in Python).
int XGBoosterPredictFromDense(BoosterHandle handle, char const *values, char const *config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
Inplace prediction from CPU dense matrix.
int XGBoosterPredictFromCudaColumnar(BoosterHandle handle, char const *data, char const *config, DMatrixHandle proxy, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
Inplace prediction from CUDA dense dataframe (cuDF in Python).
int XGBoosterPredict(BoosterHandle handle, DMatrixHandle dmat, int option_mask, unsigned ntree_limit, int training, bst_ulong *out_len, const float **out_result)
make prediction based on dmat (deprecated, use XGBoosterPredictFromDMatrix instead)
int XGBoosterPredictFromCSR(BoosterHandle handle, char const *indptr, char const *indices, char const *values, bst_ulong ncol, char const *config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
Inplace prediction from CPU CSR matrix.
int XGBoosterPredictFromColumnar(BoosterHandle handle, char const *values, char const *config, DMatrixHandle m, bst_ulong const **out_shape, bst_ulong *out_dim, const float **out_result)
Inplace prediction from CPU columnar data. (Table)
int XGBoosterPredictFromDMatrix(BoosterHandle handle, DMatrixHandle dmat, char const *config, bst_ulong const **out_shape, bst_ulong *out_dim, float const **out_result)
Make prediction from DMatrix, replacing XGBoosterPredict.
int XGBoosterLoadModelFromBuffer(BoosterHandle handle, const void *buf, bst_ulong len)
load model from in memory buffer
int XGBoosterSaveModel(BoosterHandle handle, const char *fname)
Save the model into an existing file.
int XGBoosterLoadJsonConfig(BoosterHandle handle, char const *config)
Load XGBoost's internal configuration from a JSON document. Currently the support is experimental,...
int XGBoosterUnserializeFromBuffer(BoosterHandle handle, const void *buf, bst_ulong len)
Memory snapshot based serialization method. Loads the buffer returned from XGBoosterSerializeToBuffer...
int XGBoosterSaveModelToBuffer(BoosterHandle handle, char const *config, bst_ulong *out_len, char const **out_dptr)
Save model into raw bytes, return header of the array. User must copy the result out,...
int XGBoosterLoadModel(BoosterHandle handle, const char *fname)
Load the model from an existing file.
int XGBoosterSaveJsonConfig(BoosterHandle handle, bst_ulong *out_len, char const **out_str)
Save XGBoost's internal configuration into a JSON document. Currently the support is experimental,...
int XGBoosterSerializeToBuffer(BoosterHandle handle, bst_ulong *out_len, const char **out_dptr)
Memory snapshot based serialization method. Saves everything states into buffer.
void * DataHolderHandle
handle to an internal data holder.
Definition: c_api.h:376
int XGBCallbackDataIterNext(DataIterHandle data_handle, XGBCallbackSetData *set_function, DataHolderHandle set_function_handle)
The data reading callback function. The iterator will be able to give subset of batch in the data.
Definition: c_api.h:421
int XGProxyDMatrixSetDataCSR(DMatrixHandle handle, char const *indptr, char const *indices, char const *data, bst_ulong ncol)
Set data on a DMatrix proxy.
int XGBCallbackSetData(DataHolderHandle handle, XGBoostBatchCSR batch)
Callback to set the data to handle,.
Definition: c_api.h:407
int XGDMatrixCreateFromCallback(DataIterHandle iter, DMatrixHandle proxy, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, char const *config, DMatrixHandle *out)
Create an external memory DMatrix with data iterator.
int XGDMatrixCreateFromDataIter(DataIterHandle data_handle, XGBCallbackDataIterNext *callback, const char *cache_info, float missing, DMatrixHandle *out)
Create a DMatrix from a data iterator.
int XGProxyDMatrixSetDataColumnar(DMatrixHandle handle, char const *data)
Set columnar (table) data on a DMatrix proxy.
int XGProxyDMatrixCreate(DMatrixHandle *out)
Create a DMatrix proxy for setting data, can be freed by XGDMatrixFree.
int XGDMatrixCallbackNext(DataIterHandle iter)
Callback function prototype for getting next batch of data.
Definition: c_api.h:472
int XGProxyDMatrixSetDataDense(DMatrixHandle handle, char const *data)
Set data on a DMatrix proxy.
int XGExtMemQuantileDMatrixCreateFromCallback(DataIterHandle iter, DMatrixHandle proxy, DataIterHandle ref, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, char const *config, DMatrixHandle *out)
Create a Quantile DMatrix backed by external memory.
void * DataIterHandle
handle to a external data iterator
Definition: c_api.h:374
int XGQuantileDMatrixCreateFromCallback(DataIterHandle iter, DMatrixHandle proxy, DataIterHandle ref, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, char const *config, DMatrixHandle *out)
Create a Quantile DMatrix with a data iterator.
int XGProxyDMatrixSetDataCudaColumnar(DMatrixHandle handle, const char *data)
Set CUDA-based columnar (table) data on a DMatrix proxy.
void DataIterResetCallback(DataIterHandle handle)
Callback function prototype for resetting the external iterator.
Definition: c_api.h:477
int XGProxyDMatrixSetDataCudaArrayInterface(DMatrixHandle handle, const char *data)
Set data on a DMatrix proxy.
Mini batch used in XGBoost Data Iteration.
Definition: c_api.h:379
int64_t * offset
row pointer to the rows in the data
Definition: c_api.h:390
int * index
feature index
Definition: c_api.h:397
float * value
feature values
Definition: c_api.h:399
size_t columns
number of columns in the minibatch.
Definition: c_api.h:383
float * weight
weight of each instance, can be NULL
Definition: c_api.h:395
size_t size
number of rows in the minibatch
Definition: c_api.h:381