Skip to content

Commit

Permalink
Code syle cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Ferreira committed Apr 18, 2020
1 parent 63dd2c5 commit 2ab5707
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
2 changes: 1 addition & 1 deletion include/LightGBM/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForMatSingleRow(BoosterHandle handle,
/*!
* \brief Release FastConfig object.
*
* \param fastConfig Handle to the FastConfig object acquired with a `...FastInit()` method.
* \param fastConfig Handle to the FastConfig object acquired with a `*FastInit()` method.
* \return LIGHTGBM_C_EXPORT LGBM_FastConfigFree
*/
LIGHTGBM_C_EXPORT int LGBM_FastConfigFree(FastConfigHandle fastConfig);
Expand Down
52 changes: 22 additions & 30 deletions src/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,23 +1642,15 @@ int LGBM_BoosterPredictForMatSingleRow(BoosterHandle handle,
API_END();
}

/*
struct SingleRowPredictCfg {
Config config;
Booster* ref_booster;
int is_row_major;
int predict_type;
int num_iteration;
std::function<std::vector<std::pair<int, double>>(int row_idx)> get_row_fun;
}
*/


static Config _PredictForMatSingleRowFastConfig_;
static std::function<std::vector<std::pair<int, double>>(int row_idx)> _get_row_fun_fast_;

/*!
* \brief Store resources meant for single-row Fast Predict methods.
* \brief Object to store resources meant for single-row Fast Predict methods.
*
* Meant to be used as a basic struct by the *Fast* predict methods only.
* It stores the configuration resources for reuse during prediction.
*
* Even the row function is stored. We score the instance at the same memory
* address all the time. One just replaces the feature values at that address
* and scores again with the *Fast* methods.
*/
struct FastConfig {
public:
Expand All @@ -1670,17 +1662,17 @@ struct FastConfig {
}

friend int LGBM_BoosterPredictForMatSingleRowFastInit(BoosterHandle handle,
const void* data,
int data_type,
int32_t ncol,
const char* parameter,
FastConfigHandle *out_fastConfig);
const void* data,
int data_type,
int32_t ncol,
const char* parameter,
FastConfigHandle *out_fastConfig);

friend int LGBM_BoosterPredictForMatSingleRowFast(FastConfigHandle fast_config_handle,
int predict_type,
int num_iteration,
int64_t* out_len,
double* out_result);
int predict_type,
int num_iteration,
int64_t* out_len,
double* out_result);
private:
Booster* booster;
Config config;
Expand All @@ -1701,18 +1693,18 @@ int LGBM_BoosterPredictForMatSingleRowFastInit(BoosterHandle handle,
const char* parameter,
FastConfigHandle *out_fastConfig) {
API_BEGIN();
auto fastPredictConfig_ptr = std::unique_ptr<FastConfig>(new FastConfig(
auto fastConfig_ptr = std::unique_ptr<FastConfig>(new FastConfig(
reinterpret_cast<Booster*>(handle),
parameter,
RowPairFunctionFromDenseMatric(data, 1, ncol, data_type, 1),
RowPairFunctionFromDenseMatric(data, 1, ncol, data_type, 1), // Single row in row-major format.
ncol
));

if (fastPredictConfig_ptr->config.num_threads > 0) {
omp_set_num_threads(fastPredictConfig_ptr->config.num_threads);
if (fastConfig_ptr->config.num_threads > 0) {
omp_set_num_threads(fastConfig_ptr->config.num_threads);
}

*out_fastConfig = fastPredictConfig_ptr.release();
*out_fastConfig = fastConfig_ptr.release();
API_END();
}

Expand Down

0 comments on commit 2ab5707

Please sign in to comment.