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