treelite
Functions
C API: General Tree Inference Library (GTIL)

Functions

int TreeliteGTILParseConfig (char const *config_json, TreeliteGTILConfigHandle *out)
 Load a configuration for GTIL predictor from a JSON string. More...
 
int TreeliteGTILDeleteConfig (TreeliteGTILConfigHandle handle)
 Delete a GTIL configuration from memory. More...
 
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. More...
 
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. More...
 
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. More...
 

Detailed Description

GTIL provides a reference implementation for predicting with decision trees.

Function Documentation

◆ TreeliteGTILDeleteConfig()

int TreeliteGTILDeleteConfig ( TreeliteGTILConfigHandle  handle)

Delete a GTIL configuration from memory.

Parameters
handleHandle to the GTIL configuration to be deleted
Returns
0 for success; -1 for failure

◆ TreeliteGTILGetOutputShape()

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.

Parameters
modelTreelite Model object
num_rowNumber of rows in the input
configConfiguration of GTIL predictor. Set this by calling TreeliteGTILParseConfig.
out_shapeArray of dimensions
out_ndimNumber of dimensions in out_shape
Returns
0 for success; -1 for failure

◆ TreeliteGTILParseConfig()

int TreeliteGTILParseConfig ( char const *  config_json,
TreeliteGTILConfigHandle out 
)

Load a configuration for GTIL predictor from a JSON string.

Parameters
config_jsona JSON string with the following fields:
  • "nthread" (optional): Number of threads used for initializing DMatrix. Set <= 0 to use all CPU cores.
  • "predict_type" (required): Must be one of the following.
    • "default": Sum over trees and apply post-processing
    • "raw": Sum over trees, but don't apply post-processing; get raw margin scores instead.
    • "leaf_id": Output one (integer) leaf ID per tree.
    • "score_per_tree": Output one or more margin scores per tree.
outParsed configuration
Returns
0 for success; -1 for failure

◆ TreeliteGTILPredict()

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.

Parameters
modelTreelite Model object
inputThe 2D data array, laid out in row-major layout
input_typeData type of the data matrix
num_rowNumber of rows in the data matrix.
outputPointer to buffer to store the output. Call TreeliteGTILGetOutputShape to get the amount of buffer you should allocate for this parameter.
configConfiguration of GTIL predictor. Set this by calling TreeliteGTILParseConfig.
Returns
0 for success; -1 for failure

◆ TreeliteGTILPredictSparse()

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.

In the CSR layout, data[row_ptr[i]:row_ptr[i+1]] store the nonzero entries of row i, and col_ind[row_ptr[i]:row_ptr[i+1]] stores the corresponding column indices.

Parameters
modelTreelite Model object
dataNonzero elements in the data matrix
input_typeData type of the data matrix
col_indFeature indices. col_ind[i] indicates the feature index associated with data[i].
row_ptrPointer to row headers. Length is [num_row] + 1.
num_rowNumber of rows in the data matrix.
outputPointer to buffer to store the output. Call GetOutputShape to get the amount of buffer you should allocate for this parameter.
configConfiguration of GTIL predictor. Set this by calling TreeliteGTILParseConfig.
Returns
0 for success; -1 for failure