"git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "429148309a7912754b89dfda78f01f39df17be3f"
Commit 90127b52 authored by Nikita Titov's avatar Nikita Titov Committed by Guolin Ke
Browse files

cpplint whitespaces and new lines (#1986)

parent 6f548ada
......@@ -298,9 +298,9 @@ def gen_parameter_code(config_hpp, config_out_cpp):
name = y["name"][0]
if "vector" in param_type:
if "int8" in param_type:
str_to_write += " str_buf << \"[%s: \" << Common::Join(Common::ArrayCast<int8_t, int>(%s),\",\") << \"]\\n\";\n" % (name, name)
str_to_write += " str_buf << \"[%s: \" << Common::Join(Common::ArrayCast<int8_t, int>(%s), \",\") << \"]\\n\";\n" % (name, name)
else:
str_to_write += " str_buf << \"[%s: \" << Common::Join(%s,\",\") << \"]\\n\";\n" % (name, name)
str_to_write += " str_buf << \"[%s: \" << Common::Join(%s, \",\") << \"]\\n\";\n" % (name, name)
else:
str_to_write += " str_buf << \"[%s: \" << %s << \"]\\n\";\n" % (name, name)
# tails
......
......@@ -185,4 +185,4 @@ inline void* R_GET_PTR(LGBM_SE x) {
#endif
#endif // R_OBJECT_HELPER_H_
#endif // R_OBJECT_HELPER_H_
......@@ -33,7 +33,6 @@ public:
inline void Run();
private:
/*! \brief Load parameters from command line and config file*/
void LoadParameters(int argc, char** argv);
......
......@@ -143,7 +143,7 @@ public:
* \param use_missing True to enable missing value handle
* \param zero_as_missing True to use zero as missing value
*/
void FindBin(double* values, int num_values, size_t total_sample_cnt, int max_bin, int min_data_in_bin, int min_split_data, BinType bin_type,
void FindBin(double* values, int num_values, size_t total_sample_cnt, int max_bin, int min_data_in_bin, int min_split_data, BinType bin_type,
bool use_missing, bool zero_as_missing);
/*!
......@@ -384,7 +384,7 @@ public:
* \param gt_indices After called this function. The greater data indices will store on this object.
* \return The number of less than or equal data.
*/
virtual data_size_t Split(uint32_t min_bin, uint32_t max_bin,
virtual data_size_t Split(uint32_t min_bin, uint32_t max_bin,
uint32_t default_bin, MissingType missing_type, bool default_left, uint32_t threshold,
data_size_t* data_indices, data_size_t num_data,
data_size_t* lte_indices, data_size_t* gt_indices) const = 0;
......
......@@ -291,7 +291,6 @@ public:
* \return The boosting object
*/
static Boosting* CreateBoosting(const std::string& type, const char* filename);
};
class GBDTBase : public Boosting {
......
......@@ -813,13 +813,13 @@ LIGHTGBM_C_EXPORT int LGBM_NetworkInit(const char* machines,
*/
LIGHTGBM_C_EXPORT int LGBM_NetworkFree();
LIGHTGBM_C_EXPORT int LGBM_NetworkInitWithFunctions(int num_machines, int rank,
void* reduce_scatter_ext_fun,
LIGHTGBM_C_EXPORT int LGBM_NetworkInitWithFunctions(int num_machines, int rank,
void* reduce_scatter_ext_fun,
void* allgather_ext_fun);
#if defined(_MSC_VER)
#define THREAD_LOCAL __declspec(thread)
#define THREAD_LOCAL __declspec(thread)
#else
#define THREAD_LOCAL thread_local
#endif
......@@ -831,4 +831,4 @@ inline void LGBM_SetLastError(const char* msg) {
std::strcpy(LastErrorMsg(), msg);
}
#endif // LIGHTGBM_C_API_H_
#endif // LIGHTGBM_C_API_H_
......@@ -337,7 +337,7 @@ public:
// desc = used for the categorical features
// desc = this can reduce the effect of noises in categorical features, especially for categories with few data
double cat_smooth = 10.0;
// check = >0
// desc = when number of categories of one feature smaller than or equal to ``max_cat_to_onehot``, one-vs-other split algorithm will be used
int max_cat_to_onehot = 4;
......@@ -362,7 +362,7 @@ public:
// desc = used to control feature's split gain, will use ``gain[i] = max(0, feature_contri[i]) * gain[i]`` to replace the split gain of i-th feature
// desc = you need to specify all features in order
std::vector<double> feature_contri;
// alias = fs, forced_splits_filename, forced_splits_file, forced_splits
// desc = path to a ``.json`` file that specifies splits to force at the top of every decision tree before best-first learning commences
// desc = ``.json`` file can be arbitrarily nested, and each split contains ``feature``, ``threshold`` fields, as well as ``left`` and ``right`` fields representing subsplits
......@@ -771,6 +771,7 @@ public:
LIGHTGBM_EXPORT void Set(const std::unordered_map<std::string, std::string>& params);
static std::unordered_map<std::string, std::string> alias_table;
static std::unordered_set<std::string> parameter_set;
private:
void CheckParamConflict();
void GetMembersFromString(const std::unordered_map<std::string, std::string>& params);
......@@ -837,10 +838,10 @@ struct ParameterAlias {
std::unordered_map<std::string, std::string> tmp_map;
for (const auto& pair : *params) {
auto alias = Config::alias_table.find(pair.first);
if (alias != Config::alias_table.end()) { // found alias
if (alias != Config::alias_table.end()) { // found alias
auto alias_set = tmp_map.find(alias->second);
if (alias_set != tmp_map.end()) { // alias already set
// set priority by length & alphabetically to ensure reproducible behavior
if (alias_set != tmp_map.end()) { // alias already set
// set priority by length & alphabetically to ensure reproducible behavior
if (alias_set->second.size() < pair.first.size() ||
(alias_set->second.size() == pair.first.size() && alias_set->second < pair.first)) {
Log::Warning("%s is set with %s=%s, %s=%s will be ignored. Current value: %s=%s",
......@@ -852,7 +853,7 @@ struct ParameterAlias {
pair.first.c_str(), pair.second.c_str(), alias->second.c_str(), pair.second.c_str());
tmp_map[alias->second] = pair.first;
}
} else { // alias not set
} else { // alias not set
tmp_map.emplace(alias->second, pair.first);
}
} else if (Config::parameter_set.find(pair.first) == Config::parameter_set.end()) {
......@@ -861,7 +862,7 @@ struct ParameterAlias {
}
for (const auto& pair : tmp_map) {
auto alias = params->find(pair.first);
if (alias == params->end()) { // not find
if (alias == params->end()) { // not find
params->emplace(pair.first, params->at(pair.second));
params->erase(pair.second);
} else {
......
......@@ -117,8 +117,7 @@ public:
* \param idx Index of this record
* \param value Label value of this record
*/
inline void SetLabelAt(data_size_t idx, label_t value)
{
inline void SetLabelAt(data_size_t idx, label_t value) {
label_[idx] = value;
}
......@@ -127,8 +126,7 @@ public:
* \param idx Index of this record
* \param value Weight value of this record
*/
inline void SetWeightAt(data_size_t idx, label_t value)
{
inline void SetWeightAt(data_size_t idx, label_t value) {
weights_[idx] = value;
}
......@@ -137,8 +135,7 @@ public:
* \param idx Index of this record
* \param value Query Id value of this record
*/
inline void SetQueryAt(data_size_t idx, data_size_t value)
{
inline void SetQueryAt(data_size_t idx, data_size_t value) {
queries_[idx] = static_cast<data_size_t>(value);
}
......@@ -251,7 +248,6 @@ private:
/*! \brief Interface for Parser */
class Parser {
public:
/*! \brief virtual destructor */
virtual ~Parser() {}
......@@ -463,7 +459,7 @@ public:
return false;
}
}
inline int FeatureGroupNumBin(int group) const {
return feature_groups_[group]->num_total_bin_;
}
......@@ -478,7 +474,7 @@ public:
const int group = feature2group_[i];
return feature_groups_[group]->bin_data_.get();
}
inline const Bin* FeatureGroupBin(int group) const {
return feature_groups_[group]->bin_data_.get();
}
......@@ -496,7 +492,7 @@ public:
inline BinIterator* FeatureGroupIterator(int group) const {
return feature_groups_[group]->FeatureGroupIterator();
}
inline double RealThreshold(int i, uint32_t threshold) const {
const int group = feature2group_[i];
const int sub_feature = feature2subfeature_[i];
......@@ -550,13 +546,13 @@ public:
feature_names_ = std::vector<std::string>(feature_names);
// replace ' ' in feature_names with '_'
bool spaceInFeatureName = false;
for (auto& feature_name: feature_names_){
if (feature_name.find(' ') != std::string::npos){
for (auto& feature_name : feature_names_) {
if (feature_name.find(' ') != std::string::npos) {
spaceInFeatureName = true;
std::replace(feature_name.begin(), feature_name.end(), ' ', '_');
}
}
if (spaceInFeatureName){
if (spaceInFeatureName) {
Log::Warning("Find whitespaces in feature_names, replace with underlines");
}
}
......
......@@ -7,7 +7,6 @@ namespace LightGBM {
class DatasetLoader {
public:
LIGHTGBM_EXPORT DatasetLoader(const Config& io_config, const PredictFunction& predict_fun, int num_class, const char* filename);
LIGHTGBM_EXPORT ~DatasetLoader();
......@@ -30,7 +29,6 @@ public:
DatasetLoader(const DatasetLoader&) = delete;
private:
Dataset* LoadFromBinFile(const char* data_filename, const char* bin_filename, int rank, int num_machines, int* num_global_data, std::vector<data_size_t>* used_data_indices);
void SetHeader(const char* filename);
......@@ -77,4 +75,4 @@ private:
}
#endif // LIGHTGBM_DATASET_LOADER_H_
#endif // LIGHTGBM_DATASET_LOADER_H_
......@@ -14,7 +14,7 @@
#define LIGHTGBM_EXPORT __declspec(dllexport)
#define LIGHTGBM_C_EXPORT LIGHTGBM_EXTERN_C __declspec(dllexport)
#else
#define LIGHTGBM_EXPORT
#define LIGHTGBM_EXPORT
#define LIGHTGBM_C_EXPORT LIGHTGBM_EXTERN_C
#endif
......
......@@ -145,7 +145,7 @@ public:
uint32_t default_bin = bin_mappers_[sub_feature]->GetDefaultBin();
return bin_data_->GetIterator(min_bin, max_bin, default_bin);
}
/*!
* \brief Returns a BinIterator that can access the entire feature group's raw data.
* The RawGet() function of the iterator should be called for best efficiency.
......@@ -176,7 +176,6 @@ public:
} else {
return bin_data_->SplitCategorical(min_bin, max_bin, default_bin, threshold, num_threshold, data_indices, num_data, lte_indices, gt_indices);
}
}
/*!
* \brief From bin to feature value
......
......@@ -57,7 +57,7 @@
#include <initializer_list>
#ifdef _MSC_VER
#if _MSC_VER <= 1800 // VS 2013
#if _MSC_VER <= 1800 // VS 2013
#ifndef noexcept
#define noexcept throw()
#endif
......@@ -88,18 +88,18 @@ public:
typedef std::map<std::string, Json> object;
// Constructors for the various types of JSON value.
Json() noexcept; // NUL
Json(std::nullptr_t) noexcept; // NUL
Json(double value); // NUMBER
Json(int value); // NUMBER
Json(bool value); // BOOL
Json(const std::string &value); // STRING
Json(std::string &&value); // STRING
Json(const char * value); // STRING
Json(const array &values); // ARRAY
Json(array &&values); // ARRAY
Json(const object &values); // OBJECT
Json(object &&values); // OBJECT
Json() noexcept; // NUL
Json(std::nullptr_t) noexcept; // NUL
Json(double value); // NUMBER
Json(int value); // NUMBER
Json(bool value); // BOOL
Json(const std::string &value); // STRING
Json(std::string &&value); // STRING
Json(const char * value); // STRING
Json(const array &values); // ARRAY
Json(array &&values); // ARRAY
Json(const object &values); // OBJECT
Json(object &&values); // OBJECT
// Implicit constructor: anything with a to_json() function.
template <class T, class = decltype(&T::to_json)>
......@@ -229,4 +229,4 @@ protected:
virtual ~JsonValue() {}
};
} // namespace json11
} // namespace json11
......@@ -242,7 +242,7 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename,
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterLoadModelFromString_R(LGBM_SE model_str,
LGBM_SE out,
LGBM_SE call_state);
/*!
* \brief Merge model in two boosters to first handle
* \param handle handle, will merge other handle to this
......@@ -522,4 +522,4 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle,
LGBM_SE out_str,
LGBM_SE call_state);
#endif // LIGHTGBM_R_H_
#endif // LIGHTGBM_R_H_
......@@ -51,7 +51,6 @@ public:
* \param config Config for metric
*/
LIGHTGBM_EXPORT static Metric* CreateMetric(const std::string& type, const Config& config);
};
/*!
......@@ -59,7 +58,6 @@ public:
*/
class DCGCalculator {
public:
static void DefaultEvalAt(std::vector<int>* eval_at);
static void DefaultLabelGain(std::vector<double>* label_gain);
/*!
......
......@@ -257,7 +257,6 @@ public:
}
private:
static void AllgatherBruck(char* input, const comm_size_t* block_start, const comm_size_t* block_len, char* output, comm_size_t all_size);
static void AllgatherRecursiveDoubling(char* input, const comm_size_t* block_start, const comm_size_t* block_len, char* output, comm_size_t all_size);
......
......@@ -29,4 +29,4 @@ LIGHTGBM_EXPORT PredictionEarlyStopInstance CreatePredictionEarlyStopInstance(co
} // namespace LightGBM
#endif // LIGHTGBM_PREDICTION_EARLY_STOP_H_
#endif // LIGHTGBM_PREDICTION_EARLY_STOP_H_
......@@ -204,7 +204,6 @@ public:
void RecomputeMaxDepth();
private:
std::string NumericalDecisionIfElse(int node) const;
std::string CategoricalDecisionIfElse(int node) const;
......@@ -332,7 +331,7 @@ private:
PathElement(int i, double z, double o, double w) : feature_index(i), zero_fraction(z), one_fraction(o), pweight(w) {}
};
/*! \brief Polynomial time algorithm for SHAP values (https://arxiv.org/abs/1706.06060) */
/*! \brief Polynomial time algorithm for SHAP values (https://arxiv.org/abs/1706.06060)*/
void TreeSHAP(const double *feature_values, double *phi,
int node, int unique_depth,
PathElement *parent_unique_path, double parent_zero_fraction,
......
......@@ -47,7 +47,7 @@ public:
* \param is_constant_hessian True if all hessians share the same value
* \return A trained tree
*/
virtual Tree* Train(const score_t* gradients, const score_t* hessians, bool is_constant_hessian,
virtual Tree* Train(const score_t* gradients, const score_t* hessians, bool is_constant_hessian,
Json& forced_split_json) = 0;
/*!
......
......@@ -22,7 +22,7 @@ public:
}
int step = std::max(1, (static_cast<int>(array.size()) + num_threads - 1) / num_threads);
std::vector<size_t> arg_maxs(num_threads, 0);
#pragma omp parallel for schedule(static,1)
#pragma omp parallel for schedule(static, 1)
for (int i = 0; i < num_threads; ++i) {
size_t start = step * i;
if (start >= array.size()) { continue; }
......@@ -124,7 +124,7 @@ public:
for (int k = end - 2; k >= q; k--, i++) { std::swap(ref[i], ref[k]); }
*l = j;
*r = i;
};
}
// Note: k refer to index here. e.g. k=0 means get the max number.
inline static int ArgMaxAtK(std::vector<VAL_T>* arr, int start, int end, int k) {
......@@ -184,7 +184,6 @@ public:
}
return true;
}
};
} // namespace LightGBM
......
......@@ -317,16 +317,16 @@ inline static unsigned CountDecimalDigit32(uint32_t n) {
inline static void Uint32ToStr(uint32_t value, char* buffer) {
const char kDigitsLut[200] = {
'0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9',
'1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9',
'2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9',
'3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9',
'4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9',
'5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9',
'6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9',
'7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9',
'8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9',
'9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9'
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
'1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
'2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
'3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
'4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
'5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
'6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
'7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
'8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
'9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'
};
unsigned digit = CountDecimalDigit32(value);
buffer += digit;
......@@ -358,7 +358,7 @@ inline static void Int32ToStr(int32_t value, char* buffer) {
Uint32ToStr(u, buffer);
}
inline static void DoubleToStr(double value, char* buffer, size_t
inline static void DoubleToStr(double value, char* buffer, size_t
#ifdef _MSC_VER
buffer_len
#endif
......@@ -395,14 +395,14 @@ inline static std::vector<T2> ArrayCast(const std::vector<T>& arr) {
template<typename T, bool is_float, bool is_unsign>
struct __TToStringHelperFast {
void operator()(T value, char* buffer, size_t ) const {
void operator()(T value, char* buffer, size_t) const {
Int32ToStr(value, buffer);
}
};
template<typename T>
struct __TToStringHelperFast<T, true, false> {
void operator()(T value, char* buffer, size_t
void operator()(T value, char* buffer, size_t
#ifdef _MSC_VER
buf_len
#endif
......@@ -417,7 +417,7 @@ struct __TToStringHelperFast<T, true, false> {
template<typename T>
struct __TToStringHelperFast<T, false, true> {
void operator()(T value, char* buffer, size_t ) const {
void operator()(T value, char* buffer, size_t) const {
Uint32ToStr(value, buffer);
}
};
......@@ -512,7 +512,7 @@ struct __StringToTHelperFast<T, true> {
const char* operator()(const char*p, T* out) const {
double tmp = 0.0f;
auto ret = Atof(p, &tmp);
*out= static_cast<T>(tmp);
*out = static_cast<T>(tmp);
return ret;
}
};
......@@ -637,7 +637,6 @@ inline static void SortForPair(std::vector<T1>& keys, std::vector<T2>& values, s
keys[i] = arr[i].first;
values[i] = arr[i].second;
}
}
template <typename T>
......@@ -661,7 +660,7 @@ inline static std::vector<int> VectorSize(const std::vector<std::vector<T>>& dat
inline static double AvoidInf(double x) {
if (x >= 1e300) {
return 1e300;
} else if(x <= -1e300) {
} else if (x <= -1e300) {
return -1e300;
} else {
return x;
......@@ -700,7 +699,7 @@ static void ParallelSort(_RanIt _First, _RanIt _Last, _Pr _Pred, _VTRanIt*) {
size_t inner_size = (len + num_threads - 1) / num_threads;
inner_size = std::max(inner_size, kMinInnerLen);
num_threads = static_cast<int>((len + inner_size - 1) / inner_size);
#pragma omp parallel for schedule(static,1)
#pragma omp parallel for schedule(static, 1)
for (int i = 0; i < num_threads; ++i) {
size_t left = inner_size*i;
size_t right = left + inner_size;
......@@ -716,7 +715,7 @@ static void ParallelSort(_RanIt _First, _RanIt _Last, _Pr _Pred, _VTRanIt*) {
// Recursive merge
while (s < len) {
int loop_size = static_cast<int>((len + s * 2 - 1) / (s * 2));
#pragma omp parallel for schedule(static,1)
#pragma omp parallel for schedule(static, 1)
for (int i = 0; i < loop_size; ++i) {
size_t left = i * 2 * s;
size_t mid = left + s;
......@@ -738,7 +737,7 @@ static void ParallelSort(_RanIt _First, _RanIt _Last, _Pr _Pred) {
// Check that all y[] are in interval [ymin, ymax] (end points included); throws error if not
template <typename T>
inline static void CheckElementsIntervalClosed(const T *y, T ymin, T ymax, int ny, const char *callername) {
auto fatal_msg = [&y, &ymin, &ymax, &callername](int i) {
auto fatal_msg = [&y, &ymin, &ymax, &callername](int i) {
std::ostringstream os;
os << "[%s]: does not tolerate element [#%i = " << y[i] << "] outside [" << ymin << ", " << ymax << "]";
Log::Fatal(os.str().c_str(), callername, i);
......@@ -758,7 +757,7 @@ inline static void CheckElementsIntervalClosed(const T *y, T ymin, T ymax, int n
}
}
}
if (ny & 1) { // odd
if (ny & 1) { // odd
if (y[ny - 1] < ymin || y[ny - 1] > ymax) {
fatal_msg(ny - 1);
}
......@@ -773,12 +772,12 @@ inline static void ObtainMinMaxSum(const T1 *w, int nw, T1 *mi, T1 *ma, T2 *su)
T1 maxw;
T1 sumw;
int i;
if (nw & 1) { // odd
if (nw & 1) { // odd
minw = w[0];
maxw = w[0];
sumw = w[0];
i = 2;
} else { // even
} else { // even
if (w[0] < w[1]) {
minw = w[0];
maxw = w[1];
......
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