Commit 1141ed9d authored by zhangyafeikimi's avatar zhangyafeikimi Committed by Guolin Ke
Browse files

eliminate all VS2017 warnings (#367)

parent d541855a
...@@ -271,6 +271,20 @@ inline static std::string ArrayToString(const std::vector<T>& arr, size_t n, cha ...@@ -271,6 +271,20 @@ inline static std::string ArrayToString(const std::vector<T>& arr, size_t n, cha
return str_buf.str(); return str_buf.str();
} }
template<typename T, bool is_float>
struct __StringToTHelper {
T operator()(const std::string& str) const {
return static_cast<T>(std::stol(str));
}
};
template<typename T>
struct __StringToTHelper<T, true> {
T operator()(const std::string& str) const {
return static_cast<T>(std::stod(str));
}
};
template<typename T> template<typename T>
inline static std::vector<T> StringToArray(const std::string& str, char delimiter, size_t n) { inline static std::vector<T> StringToArray(const std::string& str, char delimiter, size_t n) {
if (n == 0) { if (n == 0) {
...@@ -281,14 +295,9 @@ inline static std::vector<T> StringToArray(const std::string& str, char delimite ...@@ -281,14 +295,9 @@ inline static std::vector<T> StringToArray(const std::string& str, char delimite
Log::Fatal("StringToArray error, size doesn't match."); Log::Fatal("StringToArray error, size doesn't match.");
} }
std::vector<T> ret(n); std::vector<T> ret(n);
if (std::is_same<T, float>::value || std::is_same<T, double>::value) { __StringToTHelper<T, std::is_floating_point<T>::value> helper;
for (size_t i = 0; i < n; ++i) { for (size_t i = 0; i < n; ++i) {
ret[i] = static_cast<T>(std::stod(strs[i])); ret[i] = helper(strs[i]);
}
} else {
for (size_t i = 0; i < n; ++i) {
ret[i] = static_cast<T>(std::stol(strs[i]));
}
} }
return ret; return ret;
} }
...@@ -297,14 +306,10 @@ template<typename T> ...@@ -297,14 +306,10 @@ template<typename T>
inline static std::vector<T> StringToArray(const std::string& str, char delimiter) { inline static std::vector<T> StringToArray(const std::string& str, char delimiter) {
std::vector<std::string> strs = Split(str.c_str(), delimiter); std::vector<std::string> strs = Split(str.c_str(), delimiter);
std::vector<T> ret; std::vector<T> ret;
if (std::is_same<T, float>::value || std::is_same<T, double>::value) { ret.reserve(strs.size());
for (const auto& s : strs) { __StringToTHelper<T, std::is_floating_point<T>::value> helper;
ret.push_back(static_cast<T>(std::stod(s))); for (const auto& s : strs) {
} ret.push_back(helper(s));
} else {
for (const auto& s : strs) {
ret.push_back(static_cast<T>(std::stol(s)));
}
} }
return ret; return ret;
} }
......
...@@ -968,7 +968,7 @@ LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForCSC(BoosterHandle handle, ...@@ -968,7 +968,7 @@ LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForCSC(BoosterHandle handle,
int64_t num_preb_in_one_row = GetNumPredOneRow(ref_booster, predict_type, num_iteration); int64_t num_preb_in_one_row = GetNumPredOneRow(ref_booster, predict_type, num_iteration);
int ncol = static_cast<int>(ncol_ptr - 1); int ncol = static_cast<int>(ncol_ptr - 1);
Threading::For<int64_t>(0, num_row, Threading::For<data_size_t>(0, static_cast<data_size_t>(num_row),
[&predictor, &out_result, num_preb_in_one_row, ncol, col_ptr, col_ptr_type, indices, data, data_type, ncol_ptr, nelem] [&predictor, &out_result, num_preb_in_one_row, ncol, col_ptr, col_ptr_type, indices, data, data_type, ncol_ptr, nelem]
(int, data_size_t start, data_size_t end) { (int, data_size_t start, data_size_t end) {
std::vector<CSC_RowIterator> iterators; std::vector<CSC_RowIterator> iterators;
......
...@@ -83,7 +83,7 @@ void SerialTreeLearner::Init(const Dataset* train_data) { ...@@ -83,7 +83,7 @@ void SerialTreeLearner::Init(const Dataset* train_data) {
// if has ordered bin, need to allocate a buffer to fast split // if has ordered bin, need to allocate a buffer to fast split
if (has_ordered_bin_) { if (has_ordered_bin_) {
is_data_in_leaf_.resize(num_data_); is_data_in_leaf_.resize(num_data_);
std::fill(is_data_in_leaf_.begin(), is_data_in_leaf_.end(), 0); std::fill(is_data_in_leaf_.begin(), is_data_in_leaf_.end(), static_cast<char>(0));
ordered_bin_indices_.clear(); ordered_bin_indices_.clear();
for (int i = 0; i < static_cast<int>(ordered_bins_.size()); i++) { for (int i = 0; i < static_cast<int>(ordered_bins_.size()); i++) {
if (ordered_bins_[i] != nullptr) { if (ordered_bins_[i] != nullptr) {
...@@ -125,7 +125,7 @@ void SerialTreeLearner::ResetTrainingData(const Dataset* train_data) { ...@@ -125,7 +125,7 @@ void SerialTreeLearner::ResetTrainingData(const Dataset* train_data) {
// if has ordered bin, need to allocate a buffer to fast split // if has ordered bin, need to allocate a buffer to fast split
if (has_ordered_bin_) { if (has_ordered_bin_) {
is_data_in_leaf_.resize(num_data_); is_data_in_leaf_.resize(num_data_);
std::fill(is_data_in_leaf_.begin(), is_data_in_leaf_.end(), 0); std::fill(is_data_in_leaf_.begin(), is_data_in_leaf_.end(), static_cast<char>(0));
ordered_bin_indices_.clear(); ordered_bin_indices_.clear();
for (int i = 0; i < static_cast<int>(ordered_bins_.size()); i++) { for (int i = 0; i < static_cast<int>(ordered_bins_.size()); i++) {
if (ordered_bins_[i] != nullptr) { if (ordered_bins_[i] != nullptr) {
......
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