| 276 | |
| 277 | |
| 278 | void Predict(int num_iteration, int predict_type, int nrow, int ncol, |
| 279 | std::function<std::vector<std::pair<int, double>>(int row_idx)> get_row_fun, |
| 280 | const Config& config, |
| 281 | double* out_result, int64_t* out_len) { |
| 282 | if (ncol != boosting_->MaxFeatureIdx() + 1) { |
| 283 | Log::Fatal("The number of features in data (%d) is not the same as it was in training data (%d).", ncol, boosting_->MaxFeatureIdx() + 1); |
| 284 | } |
| 285 | std::lock_guard<std::mutex> lock(mutex_); |
| 286 | bool is_predict_leaf = false; |
| 287 | bool is_raw_score = false; |
| 288 | bool predict_contrib = false; |
| 289 | if (predict_type == C_API_PREDICT_LEAF_INDEX) { |
| 290 | is_predict_leaf = true; |
| 291 | } else if (predict_type == C_API_PREDICT_RAW_SCORE) { |
| 292 | is_raw_score = true; |
| 293 | } else if (predict_type == C_API_PREDICT_CONTRIB) { |
| 294 | predict_contrib = true; |
| 295 | } else { |
| 296 | is_raw_score = false; |
| 297 | } |
| 298 | |
| 299 | Predictor predictor(boosting_.get(), num_iteration, is_raw_score, is_predict_leaf, predict_contrib, |
| 300 | config.pred_early_stop, config.pred_early_stop_freq, config.pred_early_stop_margin); |
| 301 | int64_t num_pred_in_one_row = boosting_->NumPredictOneRow(num_iteration, is_predict_leaf, predict_contrib); |
| 302 | auto pred_fun = predictor.GetPredictFunction(); |
| 303 | OMP_INIT_EX(); |
| 304 | #pragma omp parallel for schedule(static) |
| 305 | for (int i = 0; i < nrow; ++i) { |
| 306 | OMP_LOOP_EX_BEGIN(); |
| 307 | auto one_row = get_row_fun(i); |
| 308 | auto pred_wrt_ptr = out_result + static_cast<size_t>(num_pred_in_one_row) * i; |
| 309 | pred_fun(one_row, pred_wrt_ptr); |
| 310 | OMP_LOOP_EX_END(); |
| 311 | } |
| 312 | OMP_THROW_EX(); |
| 313 | *out_len = num_pred_in_one_row * nrow; |
| 314 | } |
| 315 | |
| 316 | void Predict(int num_iteration, int predict_type, const char* data_filename, |
| 317 | int data_has_header, const Config& config, |
no test coverage detected