Unverified Commit 35612633 authored by Alberto Ferreira's avatar Alberto Ferreira Committed by GitHub
Browse files

Minor C API cleanup in predictor & SingleRowPredictor (#3777)



* Cleanup predictor

* Cleanup SingleRowPredictor

* Update src/application/predictor.hpp
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>

* Update src/application/predictor.hpp
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>

* Update src/application/predictor.hpp
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
Co-authored-by: default avatarNikita Titov <nekit94-08@mail.ru>
parent f1ec2d20
...@@ -251,10 +251,9 @@ class Predictor { ...@@ -251,10 +251,9 @@ class Predictor {
private: private:
void CopyToPredictBuffer(double* pred_buf, const std::vector<std::pair<int, double>>& features) { void CopyToPredictBuffer(double* pred_buf, const std::vector<std::pair<int, double>>& features) {
int loop_size = static_cast<int>(features.size()); for (const auto &feature : features) {
for (int i = 0; i < loop_size; ++i) { if (feature.first < num_feature_) {
if (features[i].first < num_feature_) { pred_buf[feature.first] = feature.second;
pred_buf[features[i].first] = features[i].second;
} }
} }
} }
...@@ -263,10 +262,9 @@ class Predictor { ...@@ -263,10 +262,9 @@ class Predictor {
if (features.size() > static_cast<size_t>(buf_size / 2)) { if (features.size() > static_cast<size_t>(buf_size / 2)) {
std::memset(pred_buf, 0, sizeof(double)*(buf_size)); std::memset(pred_buf, 0, sizeof(double)*(buf_size));
} else { } else {
int loop_size = static_cast<int>(features.size()); for (const auto &feature : features) {
for (int i = 0; i < loop_size; ++i) { if (feature.first < num_feature_) {
if (features[i].first < num_feature_) { pred_buf[feature.first] = 0.0f;
pred_buf[features[i].first] = 0.0f;
} }
} }
} }
...@@ -274,10 +272,9 @@ class Predictor { ...@@ -274,10 +272,9 @@ class Predictor {
std::unordered_map<int, double> CopyToPredictMap(const std::vector<std::pair<int, double>>& features) { std::unordered_map<int, double> CopyToPredictMap(const std::vector<std::pair<int, double>>& features) {
std::unordered_map<int, double> buf; std::unordered_map<int, double> buf;
int loop_size = static_cast<int>(features.size()); for (const auto &feature : features) {
for (int i = 0; i < loop_size; ++i) { if (feature.first < num_feature_) {
if (features[i].first < num_feature_) { buf[feature.first] = feature.second;
buf[features[i].first] = features[i].second;
} }
} }
return buf; return buf;
......
...@@ -72,8 +72,6 @@ class SingleRowPredictor { ...@@ -72,8 +72,6 @@ class SingleRowPredictor {
is_raw_score = true; is_raw_score = true;
} else if (predict_type == C_API_PREDICT_CONTRIB) { } else if (predict_type == C_API_PREDICT_CONTRIB) {
predict_contrib = true; predict_contrib = true;
} else {
is_raw_score = false;
} }
early_stop_ = config.pred_early_stop; early_stop_ = config.pred_early_stop;
early_stop_freq_ = config.pred_early_stop_freq; early_stop_freq_ = config.pred_early_stop_freq;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment