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

cpplint whitespaces and new lines (#1986)

parent 6f548ada
......@@ -524,7 +524,7 @@ void Config::GetMembersFromString(const std::unordered_map<std::string, std::str
std::string Config::SaveMembersToString() const {
std::stringstream str_buf;
str_buf << "[data: " << data << "]\n";
str_buf << "[valid: " << Common::Join(valid,",") << "]\n";
str_buf << "[valid: " << Common::Join(valid, ",") << "]\n";
str_buf << "[num_iterations: " << num_iterations << "]\n";
str_buf << "[learning_rate: " << learning_rate << "]\n";
str_buf << "[num_leaves: " << num_leaves << "]\n";
......@@ -556,8 +556,8 @@ std::string Config::SaveMembersToString() const {
str_buf << "[cat_smooth: " << cat_smooth << "]\n";
str_buf << "[max_cat_to_onehot: " << max_cat_to_onehot << "]\n";
str_buf << "[top_k: " << top_k << "]\n";
str_buf << "[monotone_constraints: " << Common::Join(Common::ArrayCast<int8_t, int>(monotone_constraints),",") << "]\n";
str_buf << "[feature_contri: " << Common::Join(feature_contri,",") << "]\n";
str_buf << "[monotone_constraints: " << Common::Join(Common::ArrayCast<int8_t, int>(monotone_constraints), ",") << "]\n";
str_buf << "[feature_contri: " << Common::Join(feature_contri, ",") << "]\n";
str_buf << "[forcedsplits_filename: " << forcedsplits_filename << "]\n";
str_buf << "[refit_decay_rate: " << refit_decay_rate << "]\n";
str_buf << "[verbosity: " << verbosity << "]\n";
......@@ -571,7 +571,7 @@ std::string Config::SaveMembersToString() const {
str_buf << "[input_model: " << input_model << "]\n";
str_buf << "[output_result: " << output_result << "]\n";
str_buf << "[initscore_filename: " << initscore_filename << "]\n";
str_buf << "[valid_data_initscores: " << Common::Join(valid_data_initscores,",") << "]\n";
str_buf << "[valid_data_initscores: " << Common::Join(valid_data_initscores, ",") << "]\n";
str_buf << "[pre_partition: " << pre_partition << "]\n";
str_buf << "[enable_bundle: " << enable_bundle << "]\n";
str_buf << "[max_conflict_rate: " << max_conflict_rate << "]\n";
......@@ -608,10 +608,10 @@ std::string Config::SaveMembersToString() const {
str_buf << "[poisson_max_delta_step: " << poisson_max_delta_step << "]\n";
str_buf << "[tweedie_variance_power: " << tweedie_variance_power << "]\n";
str_buf << "[max_position: " << max_position << "]\n";
str_buf << "[label_gain: " << Common::Join(label_gain,",") << "]\n";
str_buf << "[label_gain: " << Common::Join(label_gain, ",") << "]\n";
str_buf << "[metric_freq: " << metric_freq << "]\n";
str_buf << "[is_provide_training_metric: " << is_provide_training_metric << "]\n";
str_buf << "[eval_at: " << Common::Join(eval_at,",") << "]\n";
str_buf << "[eval_at: " << Common::Join(eval_at, ",") << "]\n";
str_buf << "[num_machines: " << num_machines << "]\n";
str_buf << "[local_listen_port: " << local_listen_port << "]\n";
str_buf << "[time_out: " << time_out << "]\n";
......
......@@ -86,7 +86,7 @@ std::vector<std::vector<int>> FindGroups(const std::vector<std::unique_ptr<BinMa
bool need_new_group = true;
std::vector<int> available_groups;
for (int gid = 0; gid < static_cast<int>(features_in_group.size()); ++gid) {
if (group_non_zero_cnt[gid] + cur_non_zero_cnt <= total_sample_cnt + max_error_cnt){
if (group_non_zero_cnt[gid] + cur_non_zero_cnt <= total_sample_cnt + max_error_cnt) {
if (!is_use_gpu || group_num_bin[gid] + bin_mappers[fidx]->num_bin() + (bin_mappers[fidx]->GetDefaultBin() == 0 ? -1 : 0)
<= gpu_max_bin_per_group) {
available_groups.push_back(gid);
......@@ -188,7 +188,7 @@ std::vector<std::vector<int>> FastFeatureBundling(std::vector<std::unique_ptr<Bi
cnt_non_zero += static_cast<int>(num_data * (1.0f - bin_mappers[fidx]->sparse_rate()));
}
double sparse_rate = 1.0f - static_cast<double>(cnt_non_zero) / (num_data);
// take apart small sparse group, due it will not gain on speed
// take apart small sparse group, due it will not gain on speed
if (sparse_rate >= sparse_threshold && is_enable_sparse) {
for (size_t j = 0; j < features_in_group[i].size(); ++j) {
const int fidx = features_in_group[i][j];
......@@ -216,7 +216,6 @@ void Dataset::Construct(
const int* num_per_col,
size_t total_sample_cnt,
const Config& io_config) {
num_total_features_ = static_cast<int>(bin_mappers.size());
sparse_threshold_ = io_config.sparse_threshold;
// get num_features
......@@ -699,7 +698,6 @@ void Dataset::ConstructHistograms(const std::vector<int8_t>& is_feature_used,
score_t* ordered_gradients, score_t* ordered_hessians,
bool is_constant_hessian,
HistogramBinEntry* hist_data) const {
if (leaf_idx < 0 || num_data < 0 || hist_data == nullptr) {
return;
}
......
......@@ -18,7 +18,6 @@ DatasetLoader::DatasetLoader(const Config& io_config, const PredictFunction& pre
}
DatasetLoader::~DatasetLoader() {
}
void DatasetLoader::SetHeader(const char* filename) {
......@@ -382,12 +381,12 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
}
mem_ptr += sizeof(int) * (dataset->num_groups_);
if(!config_.monotone_constraints.empty()) {
if (!config_.monotone_constraints.empty()) {
CHECK(static_cast<size_t>(dataset->num_total_features_) == config_.monotone_constraints.size());
dataset->monotone_types_.resize(dataset->num_features_);
for(int i = 0; i < dataset->num_total_features_; ++i){
for (int i = 0; i < dataset->num_total_features_; ++i) {
int inner_fidx = dataset->InnerFeatureIndex(i);
if(inner_fidx >= 0) {
if (inner_fidx >= 0) {
dataset->monotone_types_[inner_fidx] = config_.monotone_constraints[i];
}
}
......@@ -405,12 +404,12 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
dataset->monotone_types_.clear();
}
if(!config_.feature_contri.empty()) {
if (!config_.feature_contri.empty()) {
CHECK(static_cast<size_t>(dataset->num_total_features_) == config_.feature_contri.size());
dataset->feature_penalty_.resize(dataset->num_features_);
for(int i = 0; i < dataset->num_total_features_; ++i){
for (int i = 0; i < dataset->num_total_features_; ++i) {
int inner_fidx = dataset->InnerFeatureIndex(i);
if(inner_fidx >= 0) {
if (inner_fidx >= 0) {
dataset->feature_penalty_[inner_fidx] = config_.feature_contri[i];
}
}
......@@ -526,8 +525,7 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
dataset->feature_groups_.emplace_back(std::unique_ptr<FeatureGroup>(
new FeatureGroup(buffer.data(),
*num_global_data,
*used_data_indices)
));
*used_data_indices)));
}
dataset->feature_groups_.shrink_to_fit();
dataset->is_finish_load_ = true;
......@@ -782,8 +780,8 @@ std::vector<std::string> DatasetLoader::SampleTextDataFromFile(const char* filen
[this, rank, num_machines, &qid, &query_boundaries, &is_query_used, num_queries]
(data_size_t line_idx) {
if (qid >= num_queries) {
Log::Fatal("Query id exceeds the range of the query file, \
please ensure the query file is correct");
Log::Fatal("Query id exceeds the range of the query file, "
"please ensure the query file is correct");
}
if (line_idx >= query_boundaries[qid + 1]) {
// if is new query
......@@ -801,7 +799,6 @@ std::vector<std::string> DatasetLoader::SampleTextDataFromFile(const char* filen
}
void DatasetLoader::ConstructBinMappersFromTextData(int rank, int num_machines, const std::vector<std::string>& sample_data, const Parser* parser, Dataset* dataset) {
std::vector<std::vector<double>> sample_values;
std::vector<std::vector<int>> sample_indices;
std::vector<std::pair<int, double>> oneline_features;
......@@ -1143,7 +1140,6 @@ std::string DatasetLoader::CheckCanLoadFromBin(const char* filename) {
} else {
return std::string();
}
}
}
} // namespace LightGBM
......@@ -45,7 +45,6 @@ public:
}
~Dense4bitsBin() {
}
void Push(int, data_size_t idx, uint32_t value) override {
......@@ -72,11 +71,9 @@ public:
void ConstructHistogram(const data_size_t* data_indices, data_size_t num_data,
const score_t* ordered_gradients, const score_t* ordered_hessians,
HistogramBinEntry* out) const override {
const data_size_t rest = num_data & 0x3;
data_size_t i = 0;
for (; i < num_data - rest; i += 4) {
const data_size_t idx0 = data_indices[i];
const auto bin0 = (data_[idx0 >> 1] >> ((idx0 & 1) << 2)) & 0xf;
......@@ -103,7 +100,6 @@ public:
++out[bin1].cnt;
++out[bin2].cnt;
++out[bin3].cnt;
}
for (; i < num_data; ++i) {
......@@ -121,7 +117,6 @@ public:
const data_size_t rest = num_data & 0x3;
data_size_t i = 0;
for (; i < num_data - rest; i += 4) {
const auto bin0 = (data_[i >> 1]) & 0xf;
const auto bin1 = (data_[i >> 1] >> 4) & 0xf;
const auto bin2 = (data_[(i >> 1) + 1]) & 0xf;
......
......@@ -8,7 +8,7 @@
#include <hdfs.h>
#endif
namespace LightGBM{
namespace LightGBM {
struct LocalFile : VirtualFileReader, VirtualFileWriter {
LocalFile(const std::string& filename, const std::string& mode) : filename_(filename), mode_(mode) {}
......@@ -148,7 +148,7 @@ std::unordered_map<std::string, hdfsFS> HDFSFile::fs_cache_ = std::unordered_map
#define WITH_HDFS(x) x
#else
#define WITH_HDFS(x) Log::Fatal("HDFS support is not enabled")
#endif // USE_HDFS
#endif // USE_HDFS
std::unique_ptr<VirtualFileReader> VirtualFileReader::Make(const std::string& filename) {
if (0 == filename.find(kHdfsProto)) {
......
......@@ -148,7 +148,6 @@ void Json::dump(string &out) const {
template <Json::Type tag, typename T>
class Value : public JsonValue {
protected:
// Constructors
explicit Value(const T &value) : m_value(value) {}
explicit Value(T &&value) : m_value(move(value)) {}
......@@ -345,7 +344,6 @@ namespace {
* Object that tracks all state of an in-progress parse.
*/
struct JsonParser final {
/* State
*/
const string &str;
......@@ -397,7 +395,7 @@ struct JsonParser final {
}
comment_found = true;
}
else if (str[i] == '*') { // multiline comment
else if (str[i] == '*') { // multiline comment
i++;
if (i > str.size()-2)
return fail("Unexpected end of input inside multi-line comment", false);
......@@ -422,14 +420,14 @@ struct JsonParser final {
*/
void consume_garbage() {
consume_whitespace();
if(strategy == JsonParse::COMMENTS) {
if (strategy == JsonParse::COMMENTS) {
bool comment_found = false;
do {
comment_found = consume_comment();
if (failed) return;
consume_whitespace();
}
while(comment_found);
while (comment_found);
}
}
......@@ -726,7 +724,7 @@ struct JsonParser final {
return fail("Expected value, got " + esc(ch));
}
};
}//namespace {
} // namespace
Json Json::parse(const string &in, string &err, JsonParse strategy) {
JsonParser parser { in, 0, err, false, strategy };
......@@ -784,4 +782,4 @@ bool Json::has_shape(const shape & types, string & err) const {
return true;
}
} // namespace json11
} // namespace json11
......@@ -125,7 +125,6 @@ void Metadata::Init(const Metadata& fullset, const data_size_t* used_indices, da
} else {
num_queries_ = 0;
}
}
void Metadata::PartitionLabel(const std::vector<data_size_t>& used_indices) {
......@@ -516,7 +515,6 @@ void Metadata::SaveBinaryToFile(const VirtualFileWriter* writer) const {
if (!query_boundaries_.empty()) {
writer->Write(query_boundaries_.data(), sizeof(data_size_t) * (num_queries_ + 1));
}
}
size_t Metadata::SizesInByte() const {
......
......@@ -87,7 +87,6 @@ public:
data_size_t i = start;
// use data on current leaf to construct histogram
for (; i < end - rest; i += 4) {
const VAL_T bin0 = ordered_pair_[i].bin;
const VAL_T bin1 = ordered_pair_[i + 1].bin;
const VAL_T bin2 = ordered_pair_[i + 2].bin;
......@@ -119,7 +118,6 @@ public:
}
for (; i < end; ++i) {
const VAL_T bin0 = ordered_pair_[i].bin;
const auto g0 = gradient[ordered_pair_[i].ridx];
......@@ -129,7 +127,6 @@ public:
out[bin0].sum_hessians += h0;
++out[bin0].cnt;
}
}
void ConstructHistogram(int leaf, const score_t* gradient,
......@@ -141,7 +138,6 @@ public:
data_size_t i = start;
// use data on current leaf to construct histogram
for (; i < end - rest; i += 4) {
const VAL_T bin0 = ordered_pair_[i].bin;
const VAL_T bin1 = ordered_pair_[i + 1].bin;
const VAL_T bin2 = ordered_pair_[i + 2].bin;
......
......@@ -44,6 +44,7 @@ public:
inline int TotalColumns() const override {
return total_columns_;
}
private:
int label_idx_ = 0;
int total_columns_ = -1;
......@@ -79,6 +80,7 @@ public:
inline int TotalColumns() const override {
return total_columns_;
}
private:
int label_idx_ = 0;
int total_columns_ = -1;
......@@ -118,6 +120,7 @@ public:
inline int TotalColumns() const override {
return -1;
}
private:
int label_idx_ = 0;
};
......
......@@ -41,7 +41,7 @@ public:
inline uint32_t RawGet(data_size_t idx) override;
inline VAL_T InnerRawGet(data_size_t idx);
inline uint32_t Get( data_size_t idx) override {
inline uint32_t Get(data_size_t idx) override {
VAL_T ret = InnerRawGet(idx);
if (ret >= min_bin_ && ret <= max_bin_) {
return ret - min_bin_ + bias_;
......@@ -51,6 +51,7 @@ public:
}
inline void Reset(data_size_t idx) override;
private:
const SparseBin<VAL_T>* bin_data_;
data_size_t cur_pos_;
......@@ -82,7 +83,6 @@ public:
}
~SparseBin() {
}
void ReSize(data_size_t num_data) override {
......@@ -188,7 +188,7 @@ public:
if ((default_left && missing_type == MissingType::Zero) || (default_bin <= threshold && missing_type != MissingType::Zero)) {
default_indices = lte_indices;
default_count = &lte_count;
}
}
for (data_size_t i = 0; i < num_data; ++i) {
const data_size_t idx = data_indices[i];
const VAL_T bin = iterator.InnerRawGet(idx);
......@@ -200,7 +200,7 @@ public:
lte_indices[lte_count++] = idx;
}
}
}
}
return lte_count;
}
......
......@@ -17,7 +17,6 @@ namespace LightGBM {
Tree::Tree(int max_leaves)
:max_leaves_(max_leaves) {
left_child_.resize(max_leaves_ - 1);
right_child_.resize(max_leaves_ - 1);
split_feature_inner_.resize(max_leaves_ - 1);
......@@ -45,7 +44,6 @@ Tree::Tree(int max_leaves)
}
Tree::~Tree() {
}
int Tree::Split(int leaf, int feature, int real_feature, uint32_t threshold_bin,
......@@ -379,7 +377,7 @@ std::string Tree::ToIfElse(int index, bool predict_leaf_index) const {
}
str_buf << " }" << '\n';
//Predict func by Map to ifelse
// Predict func by Map to ifelse
str_buf << "double PredictTree" << index;
if (predict_leaf_index) {
str_buf << "LeafByMap";
......@@ -480,7 +478,7 @@ Tree::Tree(const char* str, size_t* used_len) {
while (read_line < max_num_line) {
if (*p == '\r' || *p == '\n') break;
auto start = p;
while (*p != '=') ++p;
while (*p != '=') ++p;
std::string key(start, p - start);
++p;
start = p;
......@@ -652,7 +650,6 @@ void Tree::TreeSHAP(const double *feature_values, double *phi,
int node, int unique_depth,
PathElement *parent_unique_path, double parent_zero_fraction,
double parent_one_fraction, int parent_feature_index) const {
// extend the unique path
PathElement* unique_path = parent_unique_path + unique_depth;
if (unique_depth > 0) std::copy(parent_unique_path, parent_unique_path + unique_depth, unique_path);
......
......@@ -19,7 +19,6 @@
#define R_API_BEGIN() \
try {
#define R_API_END() } \
catch(std::exception& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.what()); return call_state;} \
catch(std::string& ex) { R_INT_PTR(call_state)[0] = -1; LGBM_SetLastError(ex.c_str()); return call_state; } \
......@@ -54,7 +53,6 @@ LGBM_SE LGBM_DatasetCreateFromFile_R(LGBM_SE filename,
LGBM_SE reference,
LGBM_SE out,
LGBM_SE call_state) {
R_API_BEGIN();
DatasetHandle handle = nullptr;
CHECK_CALL(LGBM_DatasetCreateFromFile(R_CHAR_PTR(filename), R_CHAR_PTR(parameters),
......@@ -96,7 +94,6 @@ LGBM_SE LGBM_DatasetCreateFromMat_R(LGBM_SE data,
LGBM_SE reference,
LGBM_SE out,
LGBM_SE call_state) {
R_API_BEGIN();
int32_t nrow = static_cast<int32_t>(R_AS_INT(num_row));
int32_t ncol = static_cast<int32_t>(R_AS_INT(num_col));
......@@ -114,7 +111,6 @@ LGBM_SE LGBM_DatasetGetSubset_R(LGBM_SE handle,
LGBM_SE parameters,
LGBM_SE out,
LGBM_SE call_state) {
R_API_BEGIN();
int len = R_AS_INT(len_used_row_indices);
std::vector<int> idxvec(len);
......@@ -151,7 +147,6 @@ LGBM_SE LGBM_DatasetGetFeatureNames_R(LGBM_SE handle,
LGBM_SE actual_len,
LGBM_SE feature_names,
LGBM_SE call_state) {
R_API_BEGIN();
int len = 0;
CHECK_CALL(LGBM_DatasetGetNumFeature(R_GET_PTR(handle), &len));
......@@ -204,7 +199,7 @@ LGBM_SE LGBM_DatasetSetField_R(LGBM_SE handle,
vec[i] = static_cast<int32_t>(R_INT_PTR(field_data)[i]);
}
CHECK_CALL(LGBM_DatasetSetField(R_GET_PTR(handle), name, vec.data(), len, C_API_DTYPE_INT32));
} else if(!strcmp("init_score", name)) {
} else if (!strcmp("init_score", name)) {
CHECK_CALL(LGBM_DatasetSetField(R_GET_PTR(handle), name, R_REAL_PTR(field_data), len, C_API_DTYPE_FLOAT64));
} else {
std::vector<float> vec(len);
......@@ -221,7 +216,6 @@ LGBM_SE LGBM_DatasetGetField_R(LGBM_SE handle,
LGBM_SE field_name,
LGBM_SE field_data,
LGBM_SE call_state) {
R_API_BEGIN();
const char* name = R_CHAR_PTR(field_name);
int out_len = 0;
......@@ -256,7 +250,6 @@ LGBM_SE LGBM_DatasetGetFieldSize_R(LGBM_SE handle,
LGBM_SE field_name,
LGBM_SE out,
LGBM_SE call_state) {
R_API_BEGIN();
const char* name = R_CHAR_PTR(field_name);
int out_len = 0;
......@@ -323,7 +316,6 @@ LGBM_SE LGBM_BoosterCreate_R(LGBM_SE train_data,
LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename,
LGBM_SE out,
LGBM_SE call_state) {
R_API_BEGIN();
int out_num_iterations = 0;
BoosterHandle handle = nullptr;
......@@ -335,7 +327,6 @@ LGBM_SE LGBM_BoosterCreateFromModelfile_R(LGBM_SE filename,
LGBM_SE LGBM_BoosterLoadModelFromString_R(LGBM_SE model_str,
LGBM_SE out,
LGBM_SE call_state) {
R_API_BEGIN();
int out_num_iterations = 0;
BoosterHandle handle = nullptr;
......@@ -422,7 +413,6 @@ LGBM_SE LGBM_BoosterRollbackOneIter_R(LGBM_SE handle,
LGBM_SE LGBM_BoosterGetCurrentIteration_R(LGBM_SE handle,
LGBM_SE out,
LGBM_SE call_state) {
int out_iteration;
R_API_BEGIN();
CHECK_CALL(LGBM_BoosterGetCurrentIteration(R_GET_PTR(handle), &out_iteration));
......@@ -435,7 +425,6 @@ LGBM_SE LGBM_BoosterGetEvalNames_R(LGBM_SE handle,
LGBM_SE actual_len,
LGBM_SE eval_names,
LGBM_SE call_state) {
R_API_BEGIN();
int len;
CHECK_CALL(LGBM_BoosterGetEvalCounts(R_GET_PTR(handle), &len));
......@@ -552,7 +541,6 @@ LGBM_SE LGBM_BoosterPredictForCSC_R(LGBM_SE handle,
LGBM_SE parameter,
LGBM_SE out_result,
LGBM_SE call_state) {
R_API_BEGIN();
int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib);
......@@ -583,7 +571,6 @@ LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle,
LGBM_SE parameter,
LGBM_SE out_result,
LGBM_SE call_state) {
R_API_BEGIN();
int pred_type = GetPredictType(is_rawscore, is_leafidx, is_predcontrib);
......
......@@ -20,11 +20,9 @@ template<typename PointWiseLossCalculator>
class BinaryMetric: public Metric {
public:
explicit BinaryMetric(const Config&) {
}
virtual ~BinaryMetric() {
}
void Init(const Metadata& metadata, data_size_t num_data) override {
......@@ -157,7 +155,6 @@ public:
class AUCMetric: public Metric {
public:
explicit AUCMetric(const Config&) {
}
virtual ~AUCMetric() {
......
......@@ -20,11 +20,9 @@ public:
}
virtual ~MulticlassMetric() {
}
void Init(const Metadata& metadata, data_size_t num_data) override {
name_.emplace_back(PointWiseLossCalculator::Name());
num_data_ = num_data;
// get label
......
......@@ -19,7 +19,6 @@ public:
}
virtual ~RegressionMetric() {
}
const std::vector<std::string>& GetName() const override {
......@@ -87,7 +86,6 @@ public:
}
double loss = PointWiseLossCalculator::AverageLoss(sum_loss, sum_weights_);
return std::vector<double>(1, loss);
}
inline static double AverageLoss(double sum_loss, double sum_weights) {
......@@ -259,7 +257,7 @@ public:
const double theta = -1.0 / score;
const double a = psi;
const double b = -Common::SafeLog(-theta);
const double c = 1. / psi * Common::SafeLog(label / psi) - Common::SafeLog(label) - 0; // 0 = std::lgamma(1.0 / psi) = std::lgamma(1.0);
const double c = 1. / psi * Common::SafeLog(label / psi) - Common::SafeLog(label) - 0; // 0 = std::lgamma(1.0 / psi) = std::lgamma(1.0);
return -((label * theta - b) / a + c);
}
inline static const char* Name() {
......
......@@ -66,7 +66,7 @@ namespace LightGBM {
//
class CrossEntropyMetric : public Metric {
public:
explicit CrossEntropyMetric(const Config&) {}
explicit CrossEntropyMetric(const Config&) {}
virtual ~CrossEntropyMetric() {}
void Init(const Metadata& metadata, data_size_t num_data) override {
......@@ -105,12 +105,12 @@ public:
if (weights_ == nullptr) {
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for (data_size_t i = 0; i < num_data_; ++i) {
sum_loss += XentLoss(label_[i], score[i]); // NOTE: does not work unless score is a probability
sum_loss += XentLoss(label_[i], score[i]); // NOTE: does not work unless score is a probability
}
} else {
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for (data_size_t i = 0; i < num_data_; ++i) {
sum_loss += XentLoss(label_[i], score[i]) * weights_[i]; // NOTE: does not work unless score is a probability
sum_loss += XentLoss(label_[i], score[i]) * weights_[i]; // NOTE: does not work unless score is a probability
}
}
} else {
......@@ -139,7 +139,7 @@ public:
}
double factor_to_bigger_better() const override {
return -1.0f; // negative means smaller loss is better, positive means larger loss is better
return -1.0f; // negative means smaller loss is better, positive means larger loss is better
}
private:
......@@ -182,7 +182,6 @@ public:
Log::Fatal("[%s:%s]: (metric) all weights must be positive", GetName()[0].c_str(), __func__);
}
}
}
std::vector<double> Eval(const double* score, const ObjectiveFunction* objective) const override {
......@@ -191,13 +190,13 @@ public:
if (weights_ == nullptr) {
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for (data_size_t i = 0; i < num_data_; ++i) {
double hhat = std::log(1.0f + std::exp(score[i])); // auto-convert
double hhat = std::log(1.0f + std::exp(score[i])); // auto-convert
sum_loss += XentLambdaLoss(label_[i], 1.0f, hhat);
}
} else {
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for (data_size_t i = 0; i < num_data_; ++i) {
double hhat = std::log(1.0f + std::exp(score[i])); // auto-convert
double hhat = std::log(1.0f + std::exp(score[i])); // auto-convert
sum_loss += XentLambdaLoss(label_[i], weights_[i], hhat);
}
}
......@@ -206,14 +205,14 @@ public:
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for (data_size_t i = 0; i < num_data_; ++i) {
double hhat = 0;
objective->ConvertOutput(&score[i], &hhat); // NOTE: this only works if objective = "xentlambda"
objective->ConvertOutput(&score[i], &hhat); // NOTE: this only works if objective = "xentlambda"
sum_loss += XentLambdaLoss(label_[i], 1.0f, hhat);
}
} else {
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for (data_size_t i = 0; i < num_data_; ++i) {
double hhat = 0;
objective->ConvertOutput(&score[i], &hhat); // NOTE: this only works if objective = "xentlambda"
objective->ConvertOutput(&score[i], &hhat); // NOTE: this only works if objective = "xentlambda"
sum_loss += XentLambdaLoss(label_[i], weights_[i], hhat);
}
}
......@@ -300,12 +299,12 @@ public:
if (weights_ == nullptr) {
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for (data_size_t i = 0; i < num_data_; ++i) {
sum_loss += XentLoss(label_[i], score[i]); // NOTE: does not work unless score is a probability
sum_loss += XentLoss(label_[i], score[i]); // NOTE: does not work unless score is a probability
}
} else {
#pragma omp parallel for schedule(static) reduction(+:sum_loss)
for (data_size_t i = 0; i < num_data_; ++i) {
sum_loss += XentLoss(label_[i], score[i]) * weights_[i]; // NOTE: does not work unless score is a probability
sum_loss += XentLoss(label_[i], score[i]) * weights_[i]; // NOTE: does not work unless score is a probability
}
}
} else {
......@@ -352,6 +351,6 @@ private:
std::vector<std::string> name_;
};
} // end namespace LightGBM
} // end namespace LightGBM
#endif // end #ifndef LIGHTGBM_METRIC_XENTROPY_METRIC_HPP_
#endif // end #ifndef LIGHTGBM_METRIC_XENTROPY_METRIC_HPP_
......@@ -222,9 +222,8 @@ inline void Linkers::Recv(int rank, char* data, int len) const {
int recv_cnt = 0;
while (recv_cnt < len) {
recv_cnt += linkers_[rank]->Recv(data + recv_cnt,
//len - recv_cnt
std::min(len - recv_cnt, SocketConfig::kMaxReceiveSize)
);
// len - recv_cnt
std::min(len - recv_cnt, SocketConfig::kMaxReceiveSize));
}
}
......
......@@ -29,4 +29,4 @@ Linkers::~Linkers() {
} // namespace LightGBM
#endif // USE_MPI
#endif // USE_MPI
......@@ -117,7 +117,6 @@ void Linkers::ParseMachineList(const std::string& machines, const std::string& f
Log::Warning("World size is larger than the machine_list size, change world size to %d", client_ips_.size());
num_machines_ = static_cast<int>(client_ips_.size());
}
}
void Linkers::TryBind(int port) {
......
......@@ -137,7 +137,7 @@ void Network::Allgather(char* input, const comm_size_t* block_start, const comm_
if (allgather_ext_fun_ != nullptr) {
return allgather_ext_fun_(input, block_len[rank_], block_start, block_len, num_machines_, output, all_size);
}
const comm_size_t kRingThreshold = 10 * 1024 * 1024; // 10MB
const comm_size_t kRingThreshold = 10 * 1024 * 1024; // 10MB
const int kRingNodeThreshold = 64;
if (all_size > kRingThreshold && num_machines_ < kRingNodeThreshold) {
// when num_machines is small and data is large
......@@ -234,7 +234,7 @@ void Network::ReduceScatter(char* input, comm_size_t input_size, int type_size,
if (reduce_scatter_ext_fun_ != nullptr) {
return reduce_scatter_ext_fun_(input, input_size, type_size, block_start, block_len, num_machines_, output, output_size, reducer);
}
const comm_size_t kRingThreshold = 10 * 1024 * 1024; // 10MB
const comm_size_t kRingThreshold = 10 * 1024 * 1024; // 10MB
if (recursive_halving_map_.is_power_of_2 || input_size < kRingThreshold) {
ReduceScatterRecursiveHalving(input, input_size, type_size, block_start, block_len, output, output_size, reducer);
} else {
......
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