From e6de39a71b0acf1dbe7204fcda047f0555a09b2a Mon Sep 17 00:00:00 2001 From: Nikita Titov Date: Mon, 30 Mar 2020 17:45:16 +0300 Subject: [PATCH] fix inf in json model dump (#2940) --- src/boosting/gbdt_model_text.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/boosting/gbdt_model_text.cpp b/src/boosting/gbdt_model_text.cpp index 015e6b510173..5ce26bca95ca 100644 --- a/src/boosting/gbdt_model_text.cpp +++ b/src/boosting/gbdt_model_text.cpp @@ -48,8 +48,12 @@ std::string GBDT::DumpModel(int start_iteration, int num_iteration) const { if (strs[0][0] == '[') { strs[0].erase(0, 1); // remove '[' strs[1].erase(strs[1].size() - 1); // remove ']' - json_str_buf << "{\"min_value\":" << strs[0] << ","; - json_str_buf << "\"max_value\":" << strs[1] << ","; + double max_, min_; + Common::Atof(strs[0].c_str(), &min_); + Common::Atof(strs[1].c_str(), &max_); + json_str_buf << std::setprecision(std::numeric_limits::digits10 + 2); + json_str_buf << "{\"min_value\":" << Common::AvoidInf(min_) << ","; + json_str_buf << "\"max_value\":" << Common::AvoidInf(max_) << ","; json_str_buf << "\"values\":[]}"; } else if (strs[0] != "none") { // categorical feature auto vals = Common::StringToArray(feature_infos_[i], ':');