Commit 90127b52 authored by Nikita Titov's avatar Nikita Titov Committed by Guolin Ke
Browse files

cpplint whitespaces and new lines (#1986)

parent 6f548ada
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
namespace LightGBM{ namespace LightGBM {
/*! /*!
* \brief An interface for writing files from buffers * \brief An interface for writing files from buffers
*/ */
struct VirtualFileWriter { struct VirtualFileWriter {
virtual ~VirtualFileWriter() {}; virtual ~VirtualFileWriter() {}
/*! /*!
* \brief Initialize the writer * \brief Initialize the writer
* \return True when the file is available for writes * \return True when the file is available for writes
...@@ -48,7 +48,7 @@ struct VirtualFileReader { ...@@ -48,7 +48,7 @@ struct VirtualFileReader {
* \brief Constructor * \brief Constructor
* \param filename Filename of the data * \param filename Filename of the data
*/ */
virtual ~VirtualFileReader() {}; virtual ~VirtualFileReader() {}
/*! /*!
* \brief Initialize the reader * \brief Initialize the reader
* \return True when the file is available for read * \return True when the file is available for read
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
namespace LightGBM { namespace LightGBM {
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define THREAD_LOCAL __declspec(thread) #define THREAD_LOCAL __declspec(thread)
#else #else
#define THREAD_LOCAL thread_local #define THREAD_LOCAL thread_local
#endif #endif
...@@ -84,7 +84,6 @@ public: ...@@ -84,7 +84,6 @@ public:
} }
private: private:
static void Write(LogLevel level, const char* level_str, const char *format, va_list val) { static void Write(LogLevel level, const char* level_str, const char *format, va_list val) {
if (level <= GetLevel()) { // omit the message with low level if (level <= GetLevel()) { // omit the message with low level
// write to STDOUT // write to STDOUT
...@@ -98,7 +97,6 @@ private: ...@@ -98,7 +97,6 @@ private:
// a trick to use static variable in header file. // a trick to use static variable in header file.
// May be not good, but avoid to use an additional cpp file // May be not good, but avoid to use an additional cpp file
static LogLevel& GetLevel() { static THREAD_LOCAL LogLevel level = LogLevel::Info; return level; } static LogLevel& GetLevel() { static THREAD_LOCAL LogLevel level = LogLevel::Info; return level; }
}; };
} // namespace LightGBM } // namespace LightGBM
......
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
class ThreadExceptionHelper { class ThreadExceptionHelper {
public: public:
ThreadExceptionHelper() { ThreadExceptionHelper() {
ex_ptr_ = nullptr; ex_ptr_ = nullptr;
} }
~ThreadExceptionHelper() { ~ThreadExceptionHelper() {
ReThrow(); ReThrow();
} }
void ReThrow() { void ReThrow() {
...@@ -38,7 +38,6 @@ private: ...@@ -38,7 +38,6 @@ private:
#define OMP_INIT_EX() ThreadExceptionHelper omp_except_helper #define OMP_INIT_EX() ThreadExceptionHelper omp_except_helper
#define OMP_LOOP_EX_BEGIN() try { #define OMP_LOOP_EX_BEGIN() try {
#define OMP_LOOP_EX_END() } \ #define OMP_LOOP_EX_END() } \
catch(std::exception& ex) { Log::Warning(ex.what()); omp_except_helper.CaptureException(); } \ catch(std::exception& ex) { Log::Warning(ex.what()); omp_except_helper.CaptureException(); } \
catch(...) { omp_except_helper.CaptureException(); } catch(...) { omp_except_helper.CaptureException(); }
...@@ -47,7 +46,7 @@ catch(...) { omp_except_helper.CaptureException(); } ...@@ -47,7 +46,7 @@ catch(...) { omp_except_helper.CaptureException(); }
#else #else
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning( disable : 4068 ) // disable unknown pragma warning #pragma warning(disable: 4068) // disable unknown pragma warning
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
...@@ -61,7 +60,7 @@ catch(...) { omp_except_helper.CaptureException(); } ...@@ -61,7 +60,7 @@ catch(...) { omp_except_helper.CaptureException(); }
inline int omp_get_num_threads() {return 1;} inline int omp_get_num_threads() {return 1;}
inline int omp_get_thread_num() {return 0;} inline int omp_get_thread_num() {return 0;}
#ifdef __cplusplus #ifdef __cplusplus
}; // extern "C" }; // extern "C"
#endif #endif
#define OMP_INIT_EX() #define OMP_INIT_EX()
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include <vector> #include <vector>
#include "file_io.h" #include "file_io.h"
namespace LightGBM{ namespace LightGBM {
/*! /*!
* \brief A pipeline file reader, use 2 threads, one read block from file, the other process the block * \brief A pipeline file reader, use 2 threads, one read block from file, the other process the block
...@@ -24,13 +24,13 @@ public: ...@@ -24,13 +24,13 @@ public:
* \param filename Filename of data * \param filename Filename of data
* \process_fun Process function * \process_fun Process function
*/ */
static size_t Read(const char* filename, int skip_bytes, const std::function<size_t (const char*, size_t)>& process_fun) { static size_t Read(const char* filename, int skip_bytes, const std::function<size_t(const char*, size_t)>& process_fun) {
auto reader = VirtualFileReader::Make(filename); auto reader = VirtualFileReader::Make(filename);
if (!reader->Init()) { if (!reader->Init()) {
return 0; return 0;
} }
size_t cnt = 0; size_t cnt = 0;
const size_t buffer_size = 16 * 1024 * 1024 ; const size_t buffer_size = 16 * 1024 * 1024;
// buffer used for the process_fun // buffer used for the process_fun
auto buffer_process = std::vector<char>(buffer_size); auto buffer_process = std::vector<char>(buffer_size);
// buffer used for the file reading // buffer used for the file reading
...@@ -49,8 +49,7 @@ public: ...@@ -49,8 +49,7 @@ public:
std::thread read_worker = std::thread( std::thread read_worker = std::thread(
[&] { [&] {
last_read_cnt = reader->Read(buffer_read.data(), buffer_size); last_read_cnt = reader->Read(buffer_read.data(), buffer_size);
} });
);
// start process // start process
cnt += process_fun(buffer_process.data(), read_cnt); cnt += process_fun(buffer_process.data(), read_cnt);
// wait for read thread // wait for read thread
...@@ -61,7 +60,6 @@ public: ...@@ -61,7 +60,6 @@ public:
} }
return cnt; return cnt;
} }
}; };
} // namespace LightGBM } // namespace LightGBM
......
...@@ -93,6 +93,7 @@ public: ...@@ -93,6 +93,7 @@ public:
} }
return ret; return ret;
} }
private: private:
inline int RandInt16() { inline int RandInt16() {
x = (214013 * x + 2531011); x = (214013 * x + 2531011);
......
...@@ -26,7 +26,7 @@ public: ...@@ -26,7 +26,7 @@ public:
* \param is_skip_first_line True if need to skip header * \param is_skip_first_line True if need to skip header
*/ */
TextReader(const char* filename, bool is_skip_first_line): TextReader(const char* filename, bool is_skip_first_line):
filename_(filename), is_skip_first_line_(is_skip_first_line){ filename_(filename), is_skip_first_line_(is_skip_first_line) {
if (is_skip_first_line_) { if (is_skip_first_line_) {
auto reader = VirtualFileReader::Make(filename); auto reader = VirtualFileReader::Make(filename);
if (!reader->Init()) { if (!reader->Init()) {
...@@ -210,7 +210,7 @@ public: ...@@ -210,7 +210,7 @@ public:
} }
else { else {
const size_t idx = static_cast<size_t>(random.NextInt(0, static_cast<int>(out_used_data_indices->size()))); const size_t idx = static_cast<size_t>(random.NextInt(0, static_cast<int>(out_used_data_indices->size())));
if (idx < static_cast<size_t>(sample_cnt) ) { if (idx < static_cast<size_t>(sample_cnt)) {
out_sampled_data->operator[](idx) = std::string(buffer, size); out_sampled_data->operator[](idx) = std::string(buffer, size);
} }
} }
...@@ -225,7 +225,7 @@ public: ...@@ -225,7 +225,7 @@ public:
}); });
} }
INDEX_T ReadAllAndProcessParallelWithFilter(const std::function<void(INDEX_T, const std::vector<std::string>&)>& process_fun, const std::function<bool(INDEX_T,INDEX_T)>& filter_fun) { INDEX_T ReadAllAndProcessParallelWithFilter(const std::function<void(INDEX_T, const std::vector<std::string>&)>& process_fun, const std::function<bool(INDEX_T, INDEX_T)>& filter_fun) {
last_line_ = ""; last_line_ = "";
INDEX_T total_cnt = 0; INDEX_T total_cnt = 0;
INDEX_T used_cnt = 0; INDEX_T used_cnt = 0;
...@@ -296,7 +296,7 @@ public: ...@@ -296,7 +296,7 @@ public:
INDEX_T ReadPartAndProcessParallel(const std::vector<INDEX_T>& used_data_indices, const std::function<void(INDEX_T, const std::vector<std::string>&)>& process_fun) { INDEX_T ReadPartAndProcessParallel(const std::vector<INDEX_T>& used_data_indices, const std::function<void(INDEX_T, const std::vector<std::string>&)>& process_fun) {
return ReadAllAndProcessParallelWithFilter(process_fun, return ReadAllAndProcessParallelWithFilter(process_fun,
[&used_data_indices](INDEX_T used_cnt ,INDEX_T total_cnt) { [&used_data_indices](INDEX_T used_cnt, INDEX_T total_cnt) {
if (static_cast<size_t>(used_cnt) < used_data_indices.size() && total_cnt == used_data_indices[used_cnt]) { if (static_cast<size_t>(used_cnt) < used_data_indices.size() && total_cnt == used_data_indices[used_cnt]) {
return true; return true;
} }
...@@ -314,7 +314,7 @@ private: ...@@ -314,7 +314,7 @@ private:
/*! \brief Buffer for last line */ /*! \brief Buffer for last line */
std::string last_line_; std::string last_line_;
/*! \brief first line */ /*! \brief first line */
std::string first_line_=""; std::string first_line_ = "";
/*! \brief is skip first line */ /*! \brief is skip first line */
bool is_skip_first_line_ = false; bool is_skip_first_line_ = false;
/*! \brief is skip first line */ /*! \brief is skip first line */
......
...@@ -10,7 +10,6 @@ namespace LightGBM { ...@@ -10,7 +10,6 @@ namespace LightGBM {
class Threading { class Threading {
public: public:
template<typename INDEX_T> template<typename INDEX_T>
static inline void For(INDEX_T start, INDEX_T end, const std::function<void(int, INDEX_T, INDEX_T)>& inner_fun) { static inline void For(INDEX_T start, INDEX_T end, const std::function<void(int, INDEX_T, INDEX_T)>& inner_fun) {
int num_threads = 1; int num_threads = 1;
...@@ -22,7 +21,7 @@ public: ...@@ -22,7 +21,7 @@ public:
INDEX_T num_inner = (end - start + num_threads - 1) / num_threads; INDEX_T num_inner = (end - start + num_threads - 1) / num_threads;
if (num_inner <= 0) { num_inner = 1; } if (num_inner <= 0) { num_inner = 1; }
OMP_INIT_EX(); OMP_INIT_EX();
#pragma omp parallel for schedule(static,1) #pragma omp parallel for schedule(static, 1)
for (int i = 0; i < num_threads; ++i) { for (int i = 0; i < num_threads; ++i) {
OMP_LOOP_EX_BEGIN(); OMP_LOOP_EX_BEGIN();
INDEX_T inner_start = start + num_inner * i; INDEX_T inner_start = start + num_inner * i;
......
...@@ -136,8 +136,7 @@ void Application::LoadData() { ...@@ -136,8 +136,7 @@ void Application::LoadData() {
dataset_loader.LoadFromFileAlignWithOtherDataset( dataset_loader.LoadFromFileAlignWithOtherDataset(
config_.valid[i].c_str(), config_.valid[i].c_str(),
config_.valid_data_initscores[i].c_str(), config_.valid_data_initscores[i].c_str(),
train_data_.get()) train_data_.get()));
);
valid_datas_.push_back(std::move(new_dataset)); valid_datas_.push_back(std::move(new_dataset));
// need save binary file // need save binary file
if (config_.save_binary) { if (config_.save_binary) {
...@@ -212,7 +211,6 @@ void Application::Train() { ...@@ -212,7 +211,6 @@ void Application::Train() {
} }
void Application::Predict() { void Application::Predict() {
if (config_.task == TaskType::KRefitTree) { if (config_.task == TaskType::KRefitTree) {
// create predictor // create predictor
Predictor predictor(boosting_.get(), -1, false, true, false, false, 1, 1); Predictor predictor(boosting_.get(), -1, false, true, false, false, 1, 1);
......
...@@ -35,7 +35,6 @@ public: ...@@ -35,7 +35,6 @@ public:
Predictor(Boosting* boosting, int num_iteration, Predictor(Boosting* boosting, int num_iteration,
bool is_raw_score, bool predict_leaf_index, bool predict_contrib, bool is_raw_score, bool predict_leaf_index, bool predict_contrib,
bool early_stop, int early_stop_freq, double early_stop_margin) { bool early_stop, int early_stop_freq, double early_stop_margin) {
early_stop_ = CreatePredictionEarlyStopInstance("none", LightGBM::PredictionEarlyStopConfig()); early_stop_ = CreatePredictionEarlyStopInstance("none", LightGBM::PredictionEarlyStopConfig());
if (early_stop && !boosting->NeedAccuratePrediction()) { if (early_stop && !boosting->NeedAccuratePrediction()) {
PredictionEarlyStopConfig pred_early_stop_config; PredictionEarlyStopConfig pred_early_stop_config;
...@@ -76,16 +75,16 @@ public: ...@@ -76,16 +75,16 @@ public:
} }
}; };
} else if (predict_contrib) { } else if (predict_contrib) {
predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) { predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) {
int tid = omp_get_thread_num(); int tid = omp_get_thread_num();
CopyToPredictBuffer(predict_buf_[tid].data(), features); CopyToPredictBuffer(predict_buf_[tid].data(), features);
// get result for leaf index // get result for leaf index
boosting_->PredictContrib(predict_buf_[tid].data(), output, &early_stop_); boosting_->PredictContrib(predict_buf_[tid].data(), output, &early_stop_);
ClearPredictBuffer(predict_buf_[tid].data(), predict_buf_[tid].size(), features); ClearPredictBuffer(predict_buf_[tid].data(), predict_buf_[tid].size(), features);
}; };
} else { } else {
if (is_raw_score) { if (is_raw_score) {
predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) { predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) {
int tid = omp_get_thread_num(); int tid = omp_get_thread_num();
if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) { if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) {
auto buf = CopyToPredictMap(features); auto buf = CopyToPredictMap(features);
...@@ -97,7 +96,7 @@ public: ...@@ -97,7 +96,7 @@ public:
} }
}; };
} else { } else {
predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) { predict_fun_ = [=](const std::vector<std::pair<int, double>>& features, double* output) {
int tid = omp_get_thread_num(); int tid = omp_get_thread_num();
if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) { if (num_feature_ > kFeatureThreshold && features.size() < KSparseThreshold) {
auto buf = CopyToPredictMap(features); auto buf = CopyToPredictMap(features);
...@@ -173,7 +172,7 @@ public: ...@@ -173,7 +172,7 @@ public:
(*feature)[i].first = feature_names_map_[(*feature)[i].first]; (*feature)[i].first = feature_names_map_[(*feature)[i].first];
++i; ++i;
} else { } else {
//move the non-used features to the end of the feature vector // move the non-used features to the end of the feature vector
std::swap((*feature)[i], (*feature)[--j]); std::swap((*feature)[i], (*feature)[--j]);
} }
} }
...@@ -181,8 +180,8 @@ public: ...@@ -181,8 +180,8 @@ public:
} }
}; };
std::function<void(data_size_t, const std::vector<std::string>&)> process_fun = [&] std::function<void(data_size_t, const std::vector<std::string>&)> process_fun = [&]
(data_size_t, const std::vector<std::string>& lines) { (data_size_t, const std::vector<std::string>& lines) {
std::vector<std::pair<int, double>> oneline_features; std::vector<std::pair<int, double>> oneline_features;
std::vector<std::string> result_to_write(lines.size()); std::vector<std::string> result_to_write(lines.size());
OMP_INIT_EX(); OMP_INIT_EX();
...@@ -209,7 +208,6 @@ public: ...@@ -209,7 +208,6 @@ public:
} }
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()); int loop_size = static_cast<int>(features.size());
for (int i = 0; i < loop_size; ++i) { for (int i = 0; i < loop_size; ++i) {
......
...@@ -78,7 +78,7 @@ public: ...@@ -78,7 +78,7 @@ public:
*out_len = static_cast<int64_t>(train_score_updater_->num_data()) * num_class_; *out_len = static_cast<int64_t>(train_score_updater_->num_data()) * num_class_;
return train_score_updater_->score(); return train_score_updater_->score();
} }
bool EvalAndCheckEarlyStopping() override { bool EvalAndCheckEarlyStopping() override {
GBDT::OutputMetric(iter_); GBDT::OutputMetric(iter_);
return false; return false;
......
...@@ -30,7 +30,6 @@ num_iteration_for_pred_(0), ...@@ -30,7 +30,6 @@ num_iteration_for_pred_(0),
shrinkage_rate_(0.1f), shrinkage_rate_(0.1f),
num_init_iteration_(0), num_init_iteration_(0),
need_re_bagging_(false) { need_re_bagging_(false) {
#pragma omp parallel #pragma omp parallel
#pragma omp master #pragma omp master
{ {
...@@ -41,7 +40,6 @@ need_re_bagging_(false) { ...@@ -41,7 +40,6 @@ need_re_bagging_(false) {
} }
GBDT::~GBDT() { GBDT::~GBDT() {
} }
void GBDT::Init(const Config* config, const Dataset* train_data, const ObjectiveFunction* objective_function, void GBDT::Init(const Config* config, const Dataset* train_data, const ObjectiveFunction* objective_function,
...@@ -57,7 +55,7 @@ void GBDT::Init(const Config* config, const Dataset* train_data, const Objective ...@@ -57,7 +55,7 @@ void GBDT::Init(const Config* config, const Dataset* train_data, const Objective
shrinkage_rate_ = config_->learning_rate; shrinkage_rate_ = config_->learning_rate;
std::string forced_splits_path = config->forcedsplits_filename; std::string forced_splits_path = config->forcedsplits_filename;
//load forced_splits file // load forced_splits file
if (forced_splits_path != "") { if (forced_splits_path != "") {
std::ifstream forced_splits_file(forced_splits_path.c_str()); std::ifstream forced_splits_file(forced_splits_path.c_str());
std::stringstream buffer; std::stringstream buffer;
...@@ -188,7 +186,7 @@ void GBDT::Bagging(int iter) { ...@@ -188,7 +186,7 @@ void GBDT::Bagging(int iter) {
data_size_t inner_size = (num_data_ + num_threads_ - 1) / num_threads_; data_size_t inner_size = (num_data_ + num_threads_ - 1) / num_threads_;
if (inner_size < min_inner_size) { inner_size = min_inner_size; } if (inner_size < min_inner_size) { inner_size = min_inner_size; }
OMP_INIT_EX(); OMP_INIT_EX();
#pragma omp parallel for schedule(static,1) #pragma omp parallel for schedule(static, 1)
for (int i = 0; i < num_threads_; ++i) { for (int i = 0; i < num_threads_; ++i) {
OMP_LOOP_EX_BEGIN(); OMP_LOOP_EX_BEGIN();
left_cnts_buf_[i] = 0; left_cnts_buf_[i] = 0;
...@@ -451,7 +449,6 @@ bool GBDT::EvalAndCheckEarlyStopping() { ...@@ -451,7 +449,6 @@ bool GBDT::EvalAndCheckEarlyStopping() {
} }
void GBDT::UpdateScore(const Tree* tree, const int cur_tree_id) { void GBDT::UpdateScore(const Tree* tree, const int cur_tree_id) {
// update training score // update training score
if (!is_use_subset_) { if (!is_use_subset_) {
train_score_updater_->AddScore(tree_learner_.get(), tree, cur_tree_id); train_score_updater_->AddScore(tree_learner_.get(), tree, cur_tree_id);
...@@ -624,7 +621,6 @@ void GBDT::GetPredictAt(int data_idx, double* out_result, int64_t* out_len) { ...@@ -624,7 +621,6 @@ void GBDT::GetPredictAt(int data_idx, double* out_result, int64_t* out_len) {
void GBDT::ResetTrainingData(const Dataset* train_data, const ObjectiveFunction* objective_function, void GBDT::ResetTrainingData(const Dataset* train_data, const ObjectiveFunction* objective_function,
const std::vector<const Metric*>& training_metrics) { const std::vector<const Metric*>& training_metrics) {
if (train_data != train_data_ && !train_data_->CheckAlign(*train_data)) { if (train_data != train_data_ && !train_data_->CheckAlign(*train_data)) {
Log::Fatal("Cannot reset training data, since new training data has different bin mappers"); Log::Fatal("Cannot reset training data, since new training data has different bin mappers");
} }
......
...@@ -25,7 +25,6 @@ namespace LightGBM { ...@@ -25,7 +25,6 @@ namespace LightGBM {
*/ */
class GBDT : public GBDTBase { class GBDT : public GBDTBase {
public: public:
/*! /*!
* \brief Constructor * \brief Constructor
*/ */
...@@ -212,7 +211,7 @@ public: ...@@ -212,7 +211,7 @@ public:
num_preb_in_one_row *= max_iteration; num_preb_in_one_row *= max_iteration;
} }
} else if (is_pred_contrib) { } else if (is_pred_contrib) {
num_preb_in_one_row = num_tree_per_iteration_ * (max_feature_idx_ + 2); // +1 for 0-based indexing, +1 for baseline num_preb_in_one_row = num_tree_per_iteration_ * (max_feature_idx_ + 2); // +1 for 0-based indexing, +1 for baseline
} }
return num_preb_in_one_row; return num_preb_in_one_row;
} }
...@@ -356,7 +355,6 @@ public: ...@@ -356,7 +355,6 @@ public:
virtual const char* SubModelName() const override { return "tree"; } virtual const char* SubModelName() const override { return "tree"; }
protected: protected:
/*! /*!
* \brief Print eval result and check early stopping * \brief Print eval result and check early stopping
*/ */
...@@ -488,7 +486,6 @@ protected: ...@@ -488,7 +486,6 @@ protected:
std::string loaded_parameter_; std::string loaded_parameter_;
Json forced_splits_json_; Json forced_splits_json_;
}; };
} // namespace LightGBM } // namespace LightGBM
......
...@@ -194,7 +194,7 @@ std::string GBDT::ModelToIfElse(int num_iteration) const { ...@@ -194,7 +194,7 @@ std::string GBDT::ModelToIfElse(int num_iteration) const {
str_buf << "\t" << "}" << '\n'; str_buf << "\t" << "}" << '\n';
str_buf << "}" << '\n'; str_buf << "}" << '\n';
//PredictLeafIndexByMap // PredictLeafIndexByMap
str_buf << "double (*PredictTreeLeafByMapPtr[])(const std::unordered_map<int, double>&) = { "; str_buf << "double (*PredictTreeLeafByMapPtr[])(const std::unordered_map<int, double>&) = { ";
for (int i = 0; i < num_used_model; ++i) { for (int i = 0; i < num_used_model; ++i) {
if (i > 0) { if (i > 0) {
...@@ -511,7 +511,6 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) { ...@@ -511,7 +511,6 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) {
} }
std::vector<double> GBDT::FeatureImportance(int num_iteration, int importance_type) const { std::vector<double> GBDT::FeatureImportance(int num_iteration, int importance_type) const {
int num_used_model = static_cast<int>(models_.size()); int num_used_model = static_cast<int>(models_.size());
if (num_iteration > 0) { if (num_iteration > 0) {
num_iteration += 0; num_iteration += 0;
......
...@@ -29,7 +29,6 @@ public: ...@@ -29,7 +29,6 @@ public:
* \brief Constructor * \brief Constructor
*/ */
GOSS() : GBDT() { GOSS() : GBDT() {
} }
~GOSS() { ~GOSS() {
...@@ -86,7 +85,7 @@ public: ...@@ -86,7 +85,7 @@ public:
} }
data_size_t BaggingHelper(Random& cur_rand, data_size_t start, data_size_t cnt, data_size_t* buffer, data_size_t* buffer_right) { data_size_t BaggingHelper(Random& cur_rand, data_size_t start, data_size_t cnt, data_size_t* buffer, data_size_t* buffer_right) {
if (cnt <= 0) { if (cnt <= 0) {
return 0; return 0;
} }
std::vector<score_t> tmp_gradients(cnt, 0.0f); std::vector<score_t> tmp_gradients(cnt, 0.0f);
......
...@@ -15,7 +15,7 @@ PredictionEarlyStopInstance CreateNone(const PredictionEarlyStopConfig&) { ...@@ -15,7 +15,7 @@ PredictionEarlyStopInstance CreateNone(const PredictionEarlyStopConfig&) {
[](const double*, int) { [](const double*, int) {
return false; return false;
}, },
std::numeric_limits<int>::max() // make sure the lambda is almost never called std::numeric_limits<int>::max() // make sure the lambda is almost never called
}; };
} }
...@@ -69,7 +69,7 @@ PredictionEarlyStopInstance CreateBinary(const PredictionEarlyStopConfig& config ...@@ -69,7 +69,7 @@ PredictionEarlyStopInstance CreateBinary(const PredictionEarlyStopConfig& config
}; };
} }
} } // namespace
namespace LightGBM { namespace LightGBM {
...@@ -86,4 +86,4 @@ PredictionEarlyStopInstance CreatePredictionEarlyStopInstance(const std::string& ...@@ -86,4 +86,4 @@ PredictionEarlyStopInstance CreatePredictionEarlyStopInstance(const std::string&
} }
} }
} } // namespace LightGBM
...@@ -17,7 +17,6 @@ namespace LightGBM { ...@@ -17,7 +17,6 @@ namespace LightGBM {
*/ */
class RF : public GBDT { class RF : public GBDT {
public: public:
RF() : GBDT() { RF() : GBDT() {
average_output_ = true; average_output_ = true;
} }
...@@ -106,7 +105,6 @@ public: ...@@ -106,7 +105,6 @@ public:
std::unique_ptr<Tree> new_tree(new Tree(2)); std::unique_ptr<Tree> new_tree(new Tree(2));
size_t bias = static_cast<size_t>(cur_tree_id)* num_data_; size_t bias = static_cast<size_t>(cur_tree_id)* num_data_;
if (class_need_train_[cur_tree_id]) { if (class_need_train_[cur_tree_id]) {
auto grad = gradients + bias; auto grad = gradients + bias;
auto hess = hessians + bias; auto hess = hessians + bias;
...@@ -202,12 +200,10 @@ public: ...@@ -202,12 +200,10 @@ public:
}; };
private: private:
std::vector<score_t> tmp_grad_; std::vector<score_t> tmp_grad_;
std::vector<score_t> tmp_hess_; std::vector<score_t> tmp_hess_;
std::vector<double> init_scores_; std::vector<double> init_scores_;
}; };
} // namespace LightGBM } // namespace LightGBM
#endif // LIGHTGBM_BOOSTING_RF_H_ #endif // LIGHTGBM_BOOSTING_RF_H_
\ No newline at end of file
...@@ -46,7 +46,6 @@ public: ...@@ -46,7 +46,6 @@ public:
} }
/*! \brief Destructor */ /*! \brief Destructor */
~ScoreUpdater() { ~ScoreUpdater() {
} }
inline bool has_init_score() const { return has_init_score_; } inline bool has_init_score() const { return has_init_score_; }
...@@ -109,6 +108,7 @@ public: ...@@ -109,6 +108,7 @@ public:
ScoreUpdater& operator=(const ScoreUpdater&) = delete; ScoreUpdater& operator=(const ScoreUpdater&) = delete;
/*! \brief Disable copy */ /*! \brief Disable copy */
ScoreUpdater(const ScoreUpdater&) = delete; ScoreUpdater(const ScoreUpdater&) = delete;
private: private:
/*! \brief Number of total data */ /*! \brief Number of total data */
data_size_t num_data_; data_size_t num_data_;
......
...@@ -37,7 +37,6 @@ inline int LGBM_APIHandleException(const std::string& ex) { ...@@ -37,7 +37,6 @@ inline int LGBM_APIHandleException(const std::string& ex) {
} }
#define API_BEGIN() try { #define API_BEGIN() try {
#define API_END() } \ #define API_END() } \
catch(std::exception& ex) { return LGBM_APIHandleException(ex); } \ catch(std::exception& ex) { return LGBM_APIHandleException(ex); } \
catch(std::string& ex) { return LGBM_APIHandleException(ex); } \ catch(std::string& ex) { return LGBM_APIHandleException(ex); } \
...@@ -77,7 +76,6 @@ public: ...@@ -77,7 +76,6 @@ public:
} }
boosting_->Init(&config_, train_data_, objective_fun_.get(), boosting_->Init(&config_, train_data_, objective_fun_.get(),
Common::ConstPtrInVectorWrapper<Metric>(train_metric_)); Common::ConstPtrInVectorWrapper<Metric>(train_metric_));
} }
void MergeFrom(const Booster* other) { void MergeFrom(const Booster* other) {
...@@ -86,7 +84,6 @@ public: ...@@ -86,7 +84,6 @@ public:
} }
~Booster() { ~Booster() {
} }
void CreateObjectiveAndMetrics() { void CreateObjectiveAndMetrics() {
...@@ -158,7 +155,6 @@ public: ...@@ -158,7 +155,6 @@ public:
} }
boosting_->ResetConfig(&config_); boosting_->ResetConfig(&config_);
} }
void AddValidData(const Dataset* valid_data) { void AddValidData(const Dataset* valid_data) {
...@@ -275,7 +271,7 @@ public: ...@@ -275,7 +271,7 @@ public:
return boosting_->SaveModelToString(start_iteration, num_iteration); return boosting_->SaveModelToString(start_iteration, num_iteration);
} }
std::string DumpModel(int start_iteration,int num_iteration) { std::string DumpModel(int start_iteration, int num_iteration) {
return boosting_->DumpModel(start_iteration, num_iteration); return boosting_->DumpModel(start_iteration, num_iteration);
} }
...@@ -328,7 +324,6 @@ public: ...@@ -328,7 +324,6 @@ public:
const Boosting* GetBoosting() const { return boosting_.get(); } const Boosting* GetBoosting() const { return boosting_.get(); }
private: private:
const Dataset* train_data_; const Dataset* train_data_;
std::unique_ptr<Boosting> boosting_; std::unique_ptr<Boosting> boosting_;
/*! \brief All configs */ /*! \brief All configs */
...@@ -343,7 +338,7 @@ private: ...@@ -343,7 +338,7 @@ private:
std::mutex mutex_; std::mutex mutex_;
}; };
} } // namespace LightGBM
using namespace LightGBM; using namespace LightGBM;
...@@ -394,7 +389,7 @@ int LGBM_DatasetCreateFromFile(const char* filename, ...@@ -394,7 +389,7 @@ int LGBM_DatasetCreateFromFile(const char* filename,
if (config.num_threads > 0) { if (config.num_threads > 0) {
omp_set_num_threads(config.num_threads); omp_set_num_threads(config.num_threads);
} }
DatasetLoader loader(config,nullptr, 1, filename); DatasetLoader loader(config, nullptr, 1, filename);
if (reference == nullptr) { if (reference == nullptr) {
if (Network::num_machines() == 1) { if (Network::num_machines() == 1) {
*out = loader.LoadFromFile(filename, ""); *out = loader.LoadFromFile(filename, "");
...@@ -545,7 +540,7 @@ int LGBM_DatasetCreateFromMats(int32_t nmat, ...@@ -545,7 +540,7 @@ int LGBM_DatasetCreateFromMats(int32_t nmat,
for (int j = 0; j < nmat; ++j) { for (int j = 0; j < nmat; ++j) {
get_row_fun.push_back(RowFunctionFromDenseMatric(data[j], nrow[j], ncol, data_type, is_row_major)); get_row_fun.push_back(RowFunctionFromDenseMatric(data[j], nrow[j], ncol, data_type, is_row_major));
} }
if (reference == nullptr) { if (reference == nullptr) {
// sample data first // sample data first
Random rand(config.data_random_seed); Random rand(config.data_random_seed);
...@@ -563,7 +558,7 @@ int LGBM_DatasetCreateFromMats(int32_t nmat, ...@@ -563,7 +558,7 @@ int LGBM_DatasetCreateFromMats(int32_t nmat,
offset += nrow[j]; offset += nrow[j];
++j; ++j;
} }
auto row = get_row_fun[j](static_cast<int>(idx - offset)); auto row = get_row_fun[j](static_cast<int>(idx - offset));
for (size_t k = 0; k < row.size(); ++k) { for (size_t k = 0; k < row.size(); ++k) {
if (std::fabs(row[k]) > kZeroThreshold || std::isnan(row[k])) { if (std::fabs(row[k]) > kZeroThreshold || std::isnan(row[k])) {
...@@ -1249,7 +1244,7 @@ int LGBM_BoosterSaveModel(BoosterHandle handle, ...@@ -1249,7 +1244,7 @@ int LGBM_BoosterSaveModel(BoosterHandle handle,
int LGBM_BoosterSaveModelToString(BoosterHandle handle, int LGBM_BoosterSaveModelToString(BoosterHandle handle,
int start_iteration, int start_iteration,
int num_iteration, int num_iteration,
int64_t buffer_len, int64_t buffer_len,
int64_t* out_len, int64_t* out_len,
char* out_str) { char* out_str) {
API_BEGIN(); API_BEGIN();
......
...@@ -44,7 +44,6 @@ namespace LightGBM { ...@@ -44,7 +44,6 @@ namespace LightGBM {
} }
BinMapper::~BinMapper() { BinMapper::~BinMapper() {
} }
bool NeedFilter(const std::vector<int>& cnt_in_bin, int total_cnt, int filter_cnt, BinType bin_type) { bool NeedFilter(const std::vector<int>& cnt_in_bin, int total_cnt, int filter_cnt, BinType bin_type) {
......
...@@ -19,7 +19,7 @@ void Config::KV2Map(std::unordered_map<std::string, std::string>& params, const ...@@ -19,7 +19,7 @@ void Config::KV2Map(std::unordered_map<std::string, std::string>& params, const
std::string value = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[1])); std::string value = Common::RemoveQuotationSymbol(Common::Trim(tmp_strs[1]));
if (key.size() > 0) { if (key.size() > 0) {
auto value_search = params.find(key); auto value_search = params.find(key);
if (value_search == params.end()) { // not set if (value_search == params.end()) { // not set
params.emplace(key, value); params.emplace(key, value);
} else { } else {
Log::Warning("%s is set=%s, %s=%s will be ignored. Current value: %s=%s", Log::Warning("%s is set=%s, %s=%s will be ignored. Current value: %s=%s",
...@@ -151,7 +151,6 @@ void GetTreeLearnerType(const std::unordered_map<std::string, std::string>& para ...@@ -151,7 +151,6 @@ void GetTreeLearnerType(const std::unordered_map<std::string, std::string>& para
} }
void Config::Set(const std::unordered_map<std::string, std::string>& params) { void Config::Set(const std::unordered_map<std::string, std::string>& params) {
// generate seeds by seed. // generate seeds by seed.
if (GetInt(params, "seed", &seed)) { if (GetInt(params, "seed", &seed)) {
Random rand(seed); Random rand(seed);
...@@ -202,10 +201,10 @@ bool CheckMultiClassObjective(const std::string& objective) { ...@@ -202,10 +201,10 @@ bool CheckMultiClassObjective(const std::string& objective) {
void Config::CheckParamConflict() { void Config::CheckParamConflict() {
// check if objective, metric, and num_class match // check if objective, metric, and num_class match
int num_class_check = num_class; int num_class_check = num_class;
bool objective_custom = objective == std::string("none") || objective == std::string("null") bool objective_custom = objective == std::string("none") || objective == std::string("null")
|| objective == std::string("custom") || objective == std::string("na"); || objective == std::string("custom") || objective == std::string("na");
bool objective_type_multiclass = CheckMultiClassObjective(objective) || (objective_custom && num_class_check > 1); bool objective_type_multiclass = CheckMultiClassObjective(objective) || (objective_custom && num_class_check > 1);
if (objective_type_multiclass) { if (objective_type_multiclass) {
if (num_class_check <= 1) { if (num_class_check <= 1) {
Log::Fatal("Number of classes should be specified and greater than 1 for multiclass training"); Log::Fatal("Number of classes should be specified and greater than 1 for multiclass training");
...@@ -216,7 +215,7 @@ void Config::CheckParamConflict() { ...@@ -216,7 +215,7 @@ void Config::CheckParamConflict() {
} }
} }
for (std::string metric_type : metric) { for (std::string metric_type : metric) {
bool metric_custom_or_none = metric_type == std::string("none") || metric_type == std::string("null") bool metric_custom_or_none = metric_type == std::string("none") || metric_type == std::string("null")
|| metric_type == std::string("custom") || metric_type == std::string("na"); || metric_type == std::string("custom") || metric_type == std::string("na");
bool metric_type_multiclass = (CheckMultiClassObjective(metric_type) bool metric_type_multiclass = (CheckMultiClassObjective(metric_type)
|| metric_type == std::string("multi_logloss") || metric_type == std::string("multi_logloss")
...@@ -259,7 +258,7 @@ void Config::CheckParamConflict() { ...@@ -259,7 +258,7 @@ void Config::CheckParamConflict() {
// Check max_depth and num_leaves // Check max_depth and num_leaves
if (max_depth > 0) { if (max_depth > 0) {
int full_num_leaves = static_cast<int>(std::pow(2, max_depth)); int full_num_leaves = static_cast<int>(std::pow(2, max_depth));
if (full_num_leaves > num_leaves if (full_num_leaves > num_leaves
&& num_leaves == kDefaultNumLeaves) { && num_leaves == kDefaultNumLeaves) {
Log::Warning("Accuracy may be bad since you didn't set num_leaves and 2^max_depth > num_leaves"); Log::Warning("Accuracy may be bad since you didn't set num_leaves and 2^max_depth > num_leaves");
} }
......
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