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

cpplint whitespaces and new lines (#1986)

parent 6f548ada
......@@ -51,8 +51,7 @@ const int INVALID_SOCKET = -1;
#ifdef _WIN32
#ifndef _MSC_VER
// not using visual studio in windows
inline int inet_pton(int af, const char *src, void *dst)
{
inline int inet_pton(int af, const char *src, void *dst) {
struct sockaddr_storage ss;
int size = sizeof(ss);
char src_copy[INET6_ADDRSTRLEN + 1];
......
......@@ -19,7 +19,7 @@ public:
}
is_unbalance_ = config.is_unbalance;
scale_pos_weight_ = static_cast<double>(config.scale_pos_weight);
if(is_unbalance_ && std::fabs(scale_pos_weight_ - 1.0f) > 1e-6) {
if (is_unbalance_ && std::fabs(scale_pos_weight_ - 1.0f) > 1e-6) {
Log::Fatal("Cannot set is_unbalance and scale_pos_weight at the same time");
}
is_pos_ = is_pos;
......@@ -129,7 +129,7 @@ public:
double suml = 0.0f;
double sumw = 0.0f;
if (weights_ != nullptr) {
#pragma omp parallel for schedule(static) reduction(+:suml,sumw)
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
for (data_size_t i = 0; i < num_data_; ++i) {
suml += is_pos_(label_[i]) * weights_[i];
sumw += weights_[i];
......
......@@ -35,7 +35,6 @@ public:
}
~MulticlassSoftmax() {
}
void Init(const Metadata& metadata, data_size_t num_data) override {
......@@ -197,7 +196,6 @@ public:
}
~MulticlassOVA() {
}
void Init(const Metadata& metadata, data_size_t num_data) override {
......
......@@ -34,11 +34,9 @@ public:
}
explicit LambdarankNDCG(const std::vector<std::string>&) {
}
~LambdarankNDCG() {
}
void Init(const Metadata& metadata, data_size_t num_data) override {
num_data_ = num_data;
......
......@@ -146,7 +146,7 @@ public:
double suml = 0.0f;
double sumw = 0.0f;
if (weights_ != nullptr) {
#pragma omp parallel for schedule(static) reduction(+:suml,sumw)
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
for (data_size_t i = 0; i < num_data_; ++i) {
suml += label_[i] * weights_[i];
sumw += weights_[i];
......@@ -362,7 +362,6 @@ public:
}
explicit RegressionFairLoss(const std::vector<std::string>& strs): RegressionL2loss(strs) {
}
~RegressionFairLoss() {}
......@@ -414,7 +413,6 @@ public:
}
explicit RegressionPoissonLoss(const std::vector<std::string>& strs): RegressionL2loss(strs) {
}
~RegressionPoissonLoss() {}
......@@ -492,7 +490,6 @@ public:
}
explicit RegressionQuantileloss(const std::vector<std::string>& strs): RegressionL2loss(strs) {
}
~RegressionQuantileloss() {}
......@@ -620,7 +617,6 @@ public:
}
explicit RegressionMAPELOSS(const std::vector<std::string>& strs) : RegressionL1loss(strs) {
}
~RegressionMAPELOSS() {}
......@@ -727,7 +723,6 @@ public:
private:
std::vector<label_t> label_weight_;
};
......@@ -741,7 +736,6 @@ public:
}
explicit RegressionGammaLoss(const std::vector<std::string>& strs) : RegressionPoissonLoss(strs) {
}
~RegressionGammaLoss() {}
......@@ -766,7 +760,6 @@ public:
const char* GetName() const override {
return "gamma";
}
};
/*!
......@@ -779,7 +772,6 @@ public:
}
explicit RegressionTweedieLoss(const std::vector<std::string>& strs) : RegressionPoissonLoss(strs) {
}
~RegressionTweedieLoss() {}
......@@ -806,6 +798,7 @@ public:
const char* GetName() const override {
return "tweedie";
}
private:
double rho_;
};
......
......@@ -65,7 +65,6 @@ public:
Log::Fatal("[%s]: sum of weights is zero", GetName());
}
}
}
void GetGradients(const double* score, score_t* gradients, score_t* hessians) const override {
......@@ -108,7 +107,7 @@ public:
double suml = 0.0f;
double sumw = 0.0f;
if (weights_ != nullptr) {
#pragma omp parallel for schedule(static) reduction(+:suml,sumw)
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
for (data_size_t i = 0; i < num_data_; ++i) {
suml += label_[i] * weights_[i];
sumw += weights_[i];
......@@ -161,7 +160,6 @@ public:
Log::Info("[%s:%s]: (objective) labels passed interval [0, 1] check", GetName(), __func__);
if (weights_ != nullptr) {
Common::ObtainMinMaxSum(weights_, num_data_, &min_weight_, &max_weight_, (label_t*)nullptr);
if (min_weight_ <= 0.0f) {
Log::Fatal("[%s]: at least one weight is non-positive", GetName());
......@@ -235,7 +233,7 @@ public:
double suml = 0.0f;
double sumw = 0.0f;
if (weights_ != nullptr) {
#pragma omp parallel for schedule(static) reduction(+:suml,sumw)
#pragma omp parallel for schedule(static) reduction(+:suml, sumw)
for (data_size_t i = 0; i < num_data_; ++i) {
suml += label_[i] * weights_[i];
sumw += weights_[i];
......
......@@ -14,7 +14,6 @@ DataParallelTreeLearner<TREELEARNER_T>::DataParallelTreeLearner(const Config* co
template <typename TREELEARNER_T>
DataParallelTreeLearner<TREELEARNER_T>::~DataParallelTreeLearner() {
}
template <typename TREELEARNER_T>
......
......@@ -48,7 +48,6 @@ public:
temp_right_indices_.resize(num_data_);
}
~DataPartition() {
}
/*!
......
......@@ -9,8 +9,7 @@
#include <cstring>
#include <cmath>
namespace LightGBM
{
namespace LightGBM {
class FeatureMetainfo {
public:
......@@ -83,7 +82,6 @@ public:
void FindBestThresholdNumerical(double sum_gradient, double sum_hessian, data_size_t num_data, double min_constraint, double max_constraint,
SplitInfo* output) {
is_splittable_ = false;
double gain_shift = GetLeafSplitGain(sum_gradient, sum_hessian,
meta_->config->lambda_l1, meta_->config->lambda_l2, meta_->config->max_delta_step);
......@@ -336,7 +334,7 @@ public:
output->gain = kMinScore;
Log::Warning("'Forced Split' will be ignored since the gain getting worse. ");
return;
};
}
// update split information
output->threshold = threshold;
......@@ -452,7 +450,6 @@ public:
}
private:
static double GetSplitGains(double sum_left_gradients, double sum_left_hessians,
double sum_right_gradients, double sum_right_hessians,
double l1, double l2, double max_delta_step,
......@@ -502,7 +499,6 @@ private:
void FindBestThresholdSequence(double sum_gradient, double sum_hessian, data_size_t num_data, double min_constraint, double max_constraint,
double min_gain_shift, SplitInfo* output, int dir, bool skip_default_bin, bool use_na_as_missing) {
const int8_t bias = meta_->bias;
double best_sum_left_gradient = NAN;
......@@ -512,7 +508,6 @@ private:
uint32_t best_threshold = static_cast<uint32_t>(meta_->num_bin);
if (dir == -1) {
double sum_right_gradient = 0.0f;
double sum_right_hessian = kEpsilon;
data_size_t right_count = 0;
......@@ -522,7 +517,6 @@ private:
// from right to left, and we don't need data in bin0
for (; t >= t_end; --t) {
// need to skip default bin
if (skip_default_bin && (t + bias) == static_cast<int>(meta_->default_bin)) { continue; }
......@@ -581,7 +575,6 @@ private:
}
for (; t <= t_end; ++t) {
// need to skip default bin
if (skip_default_bin && (t + bias) == static_cast<int>(meta_->default_bin)) { continue; }
if (t >= 0) {
......@@ -645,7 +638,7 @@ private:
const FeatureMetainfo* meta_;
/*! \brief sum of gradient of each bin */
HistogramBinEntry* data_;
//std::vector<HistogramBinEntry> data_;
// std::vector<HistogramBinEntry> data_;
bool is_splittable_ = true;
std::function<void(double, double, data_size_t, double, double, SplitInfo*)> find_best_threshold_fun_;
......@@ -701,7 +694,7 @@ public:
if (feature_metas_.empty()) {
int num_feature = train_data->num_features();
feature_metas_.resize(num_feature);
#pragma omp parallel for schedule(static, 512) if(num_feature >= 1024)
#pragma omp parallel for schedule(static, 512) if (num_feature >= 1024)
for (int i = 0; i < num_feature; ++i) {
feature_metas_[i].num_bin = train_data->FeatureNumBin(i);
feature_metas_[i].default_bin = train_data->FeatureBinMapper(i)->GetDefaultBin();
......@@ -751,7 +744,7 @@ public:
void ResetConfig(const Config* config) {
int size = static_cast<int>(feature_metas_.size());
#pragma omp parallel for schedule(static, 512) if(size >= 1024)
#pragma omp parallel for schedule(static, 512) if (size >= 1024)
for (int i = 0; i < size; ++i) {
feature_metas_[i].config = config;
}
......@@ -810,6 +803,7 @@ public:
last_used_time_[slot] = ++cur_time_;
inverse_mapper_[slot] = dst_idx;
}
private:
std::vector<std::unique_ptr<FeatureHistogram[]>> pool_;
std::vector<std::vector<HistogramBinEntry>> data_;
......
......@@ -14,7 +14,6 @@ FeatureParallelTreeLearner<TREELEARNER_T>::FeatureParallelTreeLearner(const Conf
template <typename TREELEARNER_T>
FeatureParallelTreeLearner<TREELEARNER_T>::~FeatureParallelTreeLearner() {
}
template <typename TREELEARNER_T>
......
......@@ -56,8 +56,7 @@ void PrintHistograms(HistogramBinEntry* h, size_t size) {
printf("\nTotal examples: %lu\n", total);
}
union Float_t
{
union Float_t {
int64_t i;
double f;
static int64_t ulp_diff(Float_t a, Float_t b) {
......@@ -196,7 +195,7 @@ void GPUTreeLearner::WaitAndGetHistograms(HistogramBinEntry* histograms) {
// when the output is ready, the computation is done
histograms_wait_obj_.wait();
#pragma omp parallel for schedule(static)
for(int i = 0; i < num_dense_feature_groups_; ++i) {
for (int i = 0; i < num_dense_feature_groups_; ++i) {
if (!feature_masks_[i]) {
continue;
}
......@@ -596,7 +595,7 @@ void GPUTreeLearner::BuildGPUKernels() {
OMP_LOOP_EX_BEGIN();
boost::compute::program program;
std::ostringstream opts;
// compile the GPU kernel depending if double precision is used, constant hessian is used, etc
// compile the GPU kernel depending if double precision is used, constant hessian is used, etc.
opts << " -D POWER_FEATURE_WORKGROUPS=" << i
<< " -D USE_CONSTANT_BUF=" << use_constants << " -D USE_DP_FLOAT=" << int(config_->gpu_use_dp)
<< " -D CONST_HESSIAN=" << int(is_constant_hessian_)
......@@ -727,7 +726,7 @@ void GPUTreeLearner::InitGPU(int platform_id, int device_id) {
device_bin_size_ = 64;
dword_features_ = 4;
}
else if ( max_num_bin_ <= 256) {
else if (max_num_bin_ <= 256) {
kernel_source_ = kernel256_src_;
kernel_name_ = "histogram256";
device_bin_size_ = 256;
......@@ -736,10 +735,10 @@ void GPUTreeLearner::InitGPU(int platform_id, int device_id) {
else {
Log::Fatal("bin size %d cannot run on GPU", max_num_bin_);
}
if(max_num_bin_ == 65) {
if (max_num_bin_ == 65) {
Log::Warning("Setting max_bin to 63 is sugguested for best performance");
}
if(max_num_bin_ == 17) {
if (max_num_bin_ == 17) {
Log::Warning("Setting max_bin to 15 is sugguested for best performance");
}
ctx_ = boost::compute::context(dev_);
......@@ -774,7 +773,6 @@ void GPUTreeLearner::ResetTrainingData(const Dataset* train_data) {
}
void GPUTreeLearner::BeforeTrain() {
#if GPU_DEBUG >= 2
printf("Copying intial full gradients and hessians to device\n");
#endif
......@@ -861,7 +859,7 @@ bool GPUTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int ri
// copy indices to the GPU:
#if GPU_DEBUG >= 2
Log::Info("Copying indices, gradients and hessians to GPU...");
printf("Indices size %d being copied (left = %d, right = %d)\n", end - begin,num_data_in_left_child,num_data_in_right_child);
printf("Indices size %d being copied (left = %d, right = %d)\n", end - begin, num_data_in_left_child, num_data_in_right_child);
#endif
indices_future_ = boost::compute::copy_async(indices + begin, indices + end, device_data_indices_->begin(), queue_);
......@@ -893,7 +891,6 @@ bool GPUTreeLearner::ConstructGPUHistogramsAsync(
const data_size_t* data_indices, data_size_t num_data,
const score_t* gradients, const score_t* hessians,
score_t* ordered_gradients, score_t* ordered_hessians) {
if (num_data <= 0) {
return false;
}
......@@ -934,15 +931,15 @@ bool GPUTreeLearner::ConstructGPUHistogramsAsync(
}
// converted indices in is_feature_used to feature-group indices
std::vector<int8_t> is_feature_group_used(num_feature_groups_, 0);
#pragma omp parallel for schedule(static,1024) if (num_features_ >= 2048)
#pragma omp parallel for schedule(static, 1024) if (num_features_ >= 2048)
for (int i = 0; i < num_features_; ++i) {
if(is_feature_used[i]) {
if (is_feature_used[i]) {
is_feature_group_used[train_data_->Feature2Group(i)] = 1;
}
}
// construct the feature masks for dense feature-groups
int used_dense_feature_groups = 0;
#pragma omp parallel for schedule(static,1024) reduction(+:used_dense_feature_groups) if (num_dense_feature_groups_ >= 2048)
#pragma omp parallel for schedule(static, 1024) reduction(+:used_dense_feature_groups) if (num_dense_feature_groups_ >= 2048)
for (int i = 0; i < num_dense_feature_groups_; ++i) {
if (is_feature_group_used[dense_feature_group_map_[i]]) {
feature_masks_[i] = 1;
......
......@@ -63,6 +63,7 @@ protected:
void FindBestSplits() override;
void Split(Tree* tree, int best_Leaf, int* left_leaf, int* right_leaf) override;
void ConstructHistograms(const std::vector<int8_t>& is_feature_used, bool use_subtract) override;
private:
/*! \brief 4-byte feature tuple used by GPU kernels */
struct Feature4 {
......@@ -276,7 +277,7 @@ public:
}
};
}
} // namespace LightGBM
#endif // USE_GPU
......
......@@ -51,6 +51,7 @@ public:
~DataParallelTreeLearner();
void Init(const Dataset* train_data, bool is_constant_hessian) override;
void ResetConfig(const Config* config) override;
protected:
void BeforeTrain() override;
void FindBestSplits() override;
......@@ -104,6 +105,7 @@ public:
~VotingParallelTreeLearner() { }
void Init(const Dataset* train_data, bool is_constant_hessian) override;
void ResetConfig(const Config* config) override;
protected:
void BeforeTrain() override;
bool BeforeFindBestSplit(const Tree* tree, int left_leaf, int right_leaf) override;
......
......@@ -253,7 +253,6 @@ Tree* SerialTreeLearner::FitByExistingTree(const Tree* old_tree, const std::vect
}
void SerialTreeLearner::BeforeTrain() {
// reset histogram pool
histogram_pool_.ResetMap();
......@@ -322,7 +321,7 @@ void SerialTreeLearner::BeforeTrain() {
const data_size_t* indices = data_partition_->indices();
data_size_t begin = data_partition_->leaf_begin(0);
data_size_t end = begin + data_partition_->leaf_count(0);
#pragma omp parallel for schedule(static, 512) if(end - begin >= 1024)
#pragma omp parallel for schedule(static, 512) if (end - begin >= 1024)
for (data_size_t i = begin; i < end; ++i) {
is_data_in_leaf_[indices[i]] = 1;
}
......@@ -335,7 +334,7 @@ void SerialTreeLearner::BeforeTrain() {
OMP_LOOP_EX_END();
}
OMP_THROW_EX();
#pragma omp parallel for schedule(static, 512) if(end - begin >= 1024)
#pragma omp parallel for schedule(static, 512) if (end - begin >= 1024)
for (data_size_t i = begin; i < end; ++i) {
is_data_in_leaf_[indices[i]] = 0;
}
......@@ -401,7 +400,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int
end = begin + right_cnt;
mark = 0;
}
#pragma omp parallel for schedule(static, 512) if(end - begin >= 1024)
#pragma omp parallel for schedule(static, 512) if (end - begin >= 1024)
for (data_size_t i = begin; i < end; ++i) {
is_data_in_leaf_[indices[i]] = 1;
}
......@@ -414,7 +413,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int
OMP_LOOP_EX_END();
}
OMP_THROW_EX();
#pragma omp parallel for schedule(static, 512) if(end - begin >= 1024)
#pragma omp parallel for schedule(static, 512) if (end - begin >= 1024)
for (data_size_t i = begin; i < end; ++i) {
is_data_in_leaf_[indices[i]] = 0;
}
......@@ -427,7 +426,7 @@ bool SerialTreeLearner::BeforeFindBestSplit(const Tree* tree, int left_leaf, int
void SerialTreeLearner::FindBestSplits() {
std::vector<int8_t> is_feature_used(num_features_, 0);
#pragma omp parallel for schedule(static,1024) if (num_features_ >= 2048)
#pragma omp parallel for schedule(static, 1024) if (num_features_ >= 2048)
for (int feature_index = 0; feature_index < num_features_; ++feature_index) {
if (!is_feature_used_[feature_index]) continue;
if (parent_leaf_histogram_array_ != nullptr
......@@ -553,8 +552,7 @@ int32_t SerialTreeLearner::ForceSplits(Tree* tree, Json& forced_split_json, int*
bool left_smaller = true;
std::unordered_map<int, SplitInfo> forceSplitMap;
q.push(std::make_pair(forced_split_json, *left_leaf));
while(!q.empty()) {
while (!q.empty()) {
// before processing next node from queue, store info for current left/right leaf
// store "best split" for left and right, even if they might be overwritten by forced split
if (BeforeFindBestSplit(tree, *left_leaf, *right_leaf)) {
......
......@@ -106,7 +106,6 @@ protected:
int* right_leaf, int* cur_depth,
bool *aborted_last_force_split);
/*!
* \brief Get the number of data in a leaf
* \param leaf_idx The index of leaf
......
......@@ -185,7 +185,6 @@ public:
return local_feature == other_feature;
}
}
};
struct LightSplitInfo {
......@@ -280,7 +279,6 @@ public:
return local_feature == other_feature;
}
}
};
} // namespace LightGBM
......
......@@ -370,7 +370,6 @@ void VotingParallelTreeLearner<TREELEARNER_T>::FindBestSplits() {
template <typename TREELEARNER_T>
void VotingParallelTreeLearner<TREELEARNER_T>::FindBestSplitsFromHistograms(const std::vector<int8_t>&, bool) {
std::vector<SplitInfo> smaller_bests_per_thread(this->num_threads_);
std::vector<SplitInfo> larger_best_per_thread(this->num_threads_);
// find best split from local aggregated histograms
......@@ -506,4 +505,4 @@ void VotingParallelTreeLearner<TREELEARNER_T>::Split(Tree* tree, int best_Leaf,
// instantiate template classes, otherwise linker cannot find the code
template class VotingParallelTreeLearner<GPUTreeLearner>;
template class VotingParallelTreeLearner<SerialTreeLearner>;
} // namespace FTLBoost
} // namespace LightGBM
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