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, int include_master_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 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 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 TreelitePredictorFree (PredictorHandle handle)
 delete predictor from memory More...
 

Detailed Description

Predictor interface

Function Documentation

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 36 of file c_api_runtime.cc.

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 14 of file c_api_runtime.cc.

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 55 of file c_api_runtime.cc.

int TreeliteDeleteDenseBatch ( DenseBatchHandle  handle)

delete a dense batch from memory

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

Definition at line 49 of file c_api_runtime.cc.

int TreeliteDeleteSparseBatch ( CSRBatchHandle  handle)

delete a sparse batch from memory

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

Definition at line 30 of file c_api_runtime.cc.

int TreelitePredictorFree ( PredictorHandle  handle)

delete predictor from memory

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

Definition at line 128 of file c_api_runtime.cc.

int TreelitePredictorLoad ( const char *  library_path,
int  num_worker_thread,
int  include_master_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)
include_master_threadwhether to assign workload to the master thread. If not, only workers threads will be assigned work.
outhandle to predictor
Returns
0 for success, -1 for failure

Definition at line 72 of file c_api_runtime.cc.

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 84 of file c_api_runtime.cc.

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 121 of file c_api_runtime.cc.

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 105 of file c_api_runtime.cc.