Skip to content

Commit

Permalink
eliminate all VS2017 warnings (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyafeikimi authored and guolinke committed Mar 28, 2017
1 parent d541855 commit 1141ed9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
37 changes: 21 additions & 16 deletions include/LightGBM/utils/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ inline static std::string ArrayToString(const std::vector<T>& arr, size_t n, cha
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>
inline static std::vector<T> StringToArray(const std::string& str, char delimiter, size_t n) {
if (n == 0) {
Expand All @@ -281,14 +295,9 @@ inline static std::vector<T> StringToArray(const std::string& str, char delimite
Log::Fatal("StringToArray error, size doesn't match.");
}
std::vector<T> ret(n);
if (std::is_same<T, float>::value || std::is_same<T, double>::value) {
for (size_t i = 0; i < n; ++i) {
ret[i] = static_cast<T>(std::stod(strs[i]));
}
} else {
for (size_t i = 0; i < n; ++i) {
ret[i] = static_cast<T>(std::stol(strs[i]));
}
__StringToTHelper<T, std::is_floating_point<T>::value> helper;
for (size_t i = 0; i < n; ++i) {
ret[i] = helper(strs[i]);
}
return ret;
}
Expand All @@ -297,14 +306,10 @@ template<typename T>
inline static std::vector<T> StringToArray(const std::string& str, char delimiter) {
std::vector<std::string> strs = Split(str.c_str(), delimiter);
std::vector<T> ret;
if (std::is_same<T, float>::value || std::is_same<T, double>::value) {
for (const auto& s : strs) {
ret.push_back(static_cast<T>(std::stod(s)));
}
} else {
for (const auto& s : strs) {
ret.push_back(static_cast<T>(std::stol(s)));
}
ret.reserve(strs.size());
__StringToTHelper<T, std::is_floating_point<T>::value> helper;
for (const auto& s : strs) {
ret.push_back(helper(s));
}
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion src/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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]
(int, data_size_t start, data_size_t end) {
std::vector<CSC_RowIterator> iterators;
Expand Down
4 changes: 2 additions & 2 deletions src/treelearner/serial_tree_learner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
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();
for (int i = 0; i < static_cast<int>(ordered_bins_.size()); i++) {
if (ordered_bins_[i] != nullptr) {
Expand Down Expand Up @@ -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_) {
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();
for (int i = 0; i < static_cast<int>(ordered_bins_.size()); i++) {
if (ordered_bins_[i] != nullptr) {
Expand Down

0 comments on commit 1141ed9

Please sign in to comment.