treelite
Functions
Predictor

Functions

int TreeliteAssembleSparseBatch (const float *data, const uint32_t *col_ind, const size_t *row_ptr, size_t num_row, size_t num_col, CSRBatchHandle *out)
 assemble a sparse batch More...
 
int TreeliteDeleteSparseBatch (CSRBatchHandle handle)
 delete a sparse batch from memory More...
 
int TreeliteAssembleDenseBatch (const float *data, float missing_value, size_t num_row, size_t num_col, DenseBatchHandle *out)
 assemble a dense batch More...
 
int TreeliteDeleteDenseBatch (DenseBatchHandle handle)
 delete a dense batch from memory More...
 
int TreeliteBatchGetDimension (void *handle, int batch_sparse, size_t *out_num_row, size_t *out_num_col)
 get dimensions of a batch More...
 
int TreelitePredictorLoad (const char *library_path, int num_worker_thread, PredictorHandle *out)
 load prediction code into memory. This function assumes that the prediction code has been already compiled into a dynamic shared library object (.so/.dll/.dylib). More...
 
int TreelitePredictorPredictBatch (PredictorHandle handle, void *batch, int batch_sparse, int verbose, int pred_margin, float *out_result, size_t *out_result_size)
 Make predictions on a batch of data rows (synchronously). This function internally divides the workload among all worker threads. More...
 
int TreelitePredictorPredictInst (PredictorHandle handle, union TreelitePredictorEntry *inst, int pred_margin, float *out_result, size_t *out_result_size)
 Make predictions on a single data row (synchronously). The work will be scheduled to the calling thread. More...
 
int TreelitePredictorQueryResultSize (PredictorHandle handle, void *batch, int batch_sparse, size_t *out)
 Given a batch of data rows, query the necessary size of array to hold predictions for all data points. More...
 
int TreelitePredictorQueryResultSizeSingleInst (PredictorHandle handle, size_t *out)
 Query the necessary size of array to hold the prediction for a single data row. More...
 
int TreelitePredictorQueryNumOutputGroup (PredictorHandle handle, size_t *out)
 Get the number of output groups in the loaded model The number is 1 for most tasks; it is greater than 1 for multiclass classifcation. More...
 
int TreelitePredictorQueryNumFeature (PredictorHandle handle, size_t *out)
 Get the width (number of features) of each instance used to train the loaded model. More...
 
int TreelitePredictorFree (PredictorHandle handle)
 delete predictor from memory More...
 

Detailed Description

Predictor interface

Function Documentation

◆ TreeliteAssembleDenseBatch()

int TreeliteAssembleDenseBatch ( const float *  data,
float  missing_value,
size_t  num_row,
size_t  num_col,
DenseBatchHandle out 
)

assemble a dense batch

Parameters
datafeature values
missing_valuevalue to represent the missing value
num_rownumber of data rows in the batch
num_colnumber of columns (features) in the batch
outhandle to sparse batch
Returns
0 for success, -1 for failure

Definition at line 37 of file c_api_runtime.cc.

◆ TreeliteAssembleSparseBatch()

int TreeliteAssembleSparseBatch ( const float *  data,
const uint32_t *  col_ind,
const size_t *  row_ptr,
size_t  num_row,
size_t  num_col,
CSRBatchHandle out 
)

assemble a sparse batch

Parameters
datafeature values
col_indfeature indices
row_ptrpointer to row headers
num_rownumber of data rows in the batch
num_colnumber of columns (features) in the batch
outhandle to sparse batch
Returns
0 for success, -1 for failure

Definition at line 15 of file c_api_runtime.cc.

◆ TreeliteBatchGetDimension()

int TreeliteBatchGetDimension ( void *  handle,
int  batch_sparse,
size_t *  out_num_row,
size_t *  out_num_col 
)

get dimensions of a batch

Parameters
handlea batch of rows (must be of type SparseBatch or DenseBatch)
batch_sparsewhether the batch is sparse (true) or dense (false)
out_num_rowused to set number of rows
out_num_colused to set number of columns
Returns
0 for success, -1 for failure

Definition at line 56 of file c_api_runtime.cc.

◆ TreeliteDeleteDenseBatch()

int TreeliteDeleteDenseBatch ( DenseBatchHandle  handle)

delete a dense batch from memory

Parameters
handledense batch
Returns
0 for success, -1 for failure

Definition at line 50 of file c_api_runtime.cc.

◆ TreeliteDeleteSparseBatch()

int TreeliteDeleteSparseBatch ( CSRBatchHandle  handle)

delete a sparse batch from memory

Parameters
handlesparse batch
Returns
0 for success, -1 for failure

Definition at line 31 of file c_api_runtime.cc.

◆ TreelitePredictorFree()

int TreelitePredictorFree ( PredictorHandle  handle)

delete predictor from memory

Parameters
handlepredictor to remove
Returns
0 for success, -1 for failure

Definition at line 160 of file c_api_runtime.cc.

◆ TreelitePredictorLoad()

int TreelitePredictorLoad ( const char *  library_path,
int  num_worker_thread,
PredictorHandle out 
)

load prediction code into memory. This function assumes that the prediction code has been already compiled into a dynamic shared library object (.so/.dll/.dylib).

Parameters
library_pathpath to library object file containing prediction code
num_worker_threadnumber of worker threads (-1 to use max number)
outhandle to predictor
Returns
0 for success, -1 for failure

Definition at line 73 of file c_api_runtime.cc.

◆ TreelitePredictorPredictBatch()

int TreelitePredictorPredictBatch ( PredictorHandle  handle,
void *  batch,
int  batch_sparse,
int  verbose,
int  pred_margin,
float *  out_result,
size_t *  out_result_size 
)

Make predictions on a batch of data rows (synchronously). This function internally divides the workload among all worker threads.

Parameters
handlepredictor
batcha batch of rows (must be of type SparseBatch or DenseBatch)
batch_sparsewhether batch is sparse (1) or dense (0)
verbosewhether to produce extra messages
pred_marginwhether to produce raw margin scores instead of transformed probabilities
out_resultresulting output vector; use TreelitePredictorQueryResultSize() to allocate sufficient space
out_result_sizeused to save length of the output vector, which is guaranteed to be less than or equal to TreelitePredictorQueryResultSize()
Returns
0 for success, -1 for failure

Definition at line 83 of file c_api_runtime.cc.

◆ TreelitePredictorPredictInst()

int TreelitePredictorPredictInst ( PredictorHandle  handle,
union TreelitePredictorEntry inst,
int  pred_margin,
float *  out_result,
size_t *  out_result_size 
)

Make predictions on a single data row (synchronously). The work will be scheduled to the calling thread.

Parameters
handlepredictor
instsingle data row
pred_marginwhether to produce raw margin scores instead of transformed probabilities
out_resultresulting output vector; use TreelitePredictorQueryResultSizeSingleInst() to allocate sufficient space
out_result_sizeused to save length of the output vector, which is guaranteed to be at most TreelitePredictorQueryResultSizeSingleInst()
Returns
0 for success, -1 for failure

Definition at line 111 of file c_api_runtime.cc.

◆ TreelitePredictorQueryNumFeature()

int TreelitePredictorQueryNumFeature ( PredictorHandle  handle,
size_t *  out 
)

Get the width (number of features) of each instance used to train the loaded model.

Parameters
handlepredictor
outnumber of features
Returns
0 for success, -1 for failure

Definition at line 153 of file c_api_runtime.cc.

◆ TreelitePredictorQueryNumOutputGroup()

int TreelitePredictorQueryNumOutputGroup ( PredictorHandle  handle,
size_t *  out 
)

Get the number of output groups in the loaded model The number is 1 for most tasks; it is greater than 1 for multiclass classifcation.

Parameters
handlepredictor
outlength of prediction array
Returns
0 for success, -1 for failure

Definition at line 146 of file c_api_runtime.cc.

◆ TreelitePredictorQueryResultSize()

int TreelitePredictorQueryResultSize ( PredictorHandle  handle,
void *  batch,
int  batch_sparse,
size_t *  out 
)

Given a batch of data rows, query the necessary size of array to hold predictions for all data points.

Parameters
handlepredictor
batcha batch of rows (must be of type SparseBatch or DenseBatch)
batch_sparsewhether batch is sparse (1) or dense (0)
outused to store the length of prediction array
Returns
0 for success, -1 for failure

Definition at line 122 of file c_api_runtime.cc.

◆ TreelitePredictorQueryResultSizeSingleInst()

int TreelitePredictorQueryResultSizeSingleInst ( PredictorHandle  handle,
size_t *  out 
)

Query the necessary size of array to hold the prediction for a single data row.

Parameters
handlepredictor
outused to store the length of prediction array
Returns
0 for success, -1 for failure

Definition at line 138 of file c_api_runtime.cc.