Commit 899151fc authored by Nikita Titov's avatar Nikita Titov Committed by Guolin Ke
Browse files

[python] decode error description (#1362)

* decode error description

* added break line char in log massages
parent 79d27770
...@@ -498,11 +498,11 @@ struct ParameterAlias { ...@@ -498,11 +498,11 @@ struct ParameterAlias {
// set priority by length & alphabetically to ensure reproducible behavior // set priority by length & alphabetically to ensure reproducible behavior
if (alias_set->second.size() < pair.first.size() || if (alias_set->second.size() < pair.first.size() ||
(alias_set->second.size() == pair.first.size() && alias_set->second < pair.first)) { (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.", Log::Warning("%s is set with %s=%s, %s=%s will be ignored. Current value: %s=%s",
alias->second.c_str(), alias_set->second.c_str(), params->at(alias_set->second).c_str(), alias->second.c_str(), alias_set->second.c_str(), params->at(alias_set->second).c_str(),
pair.first.c_str(), pair.second.c_str(), alias->second.c_str(), params->at(alias_set->second).c_str()); pair.first.c_str(), pair.second.c_str(), alias->second.c_str(), params->at(alias_set->second).c_str());
} else { } else {
Log::Warning("%s is set with %s=%s, will be overridden by %s=%s. Current value: %s=%s.", Log::Warning("%s is set with %s=%s, will be overridden by %s=%s. Current value: %s=%s",
alias->second.c_str(), alias_set->second.c_str(), params->at(alias_set->second).c_str(), alias->second.c_str(), alias_set->second.c_str(), params->at(alias_set->second).c_str(),
pair.first.c_str(), pair.second.c_str(), alias->second.c_str(), pair.second.c_str()); pair.first.c_str(), pair.second.c_str(), alias->second.c_str(), pair.second.c_str());
tmp_map[alias->second] = pair.first; tmp_map[alias->second] = pair.first;
...@@ -520,7 +520,7 @@ struct ParameterAlias { ...@@ -520,7 +520,7 @@ struct ParameterAlias {
params->emplace(pair.first, params->at(pair.second)); params->emplace(pair.first, params->at(pair.second));
params->erase(pair.second); params->erase(pair.second);
} 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",
pair.first.c_str(), alias->second.c_str(), pair.second.c_str(), params->at(pair.second).c_str(), pair.first.c_str(), alias->second.c_str(), pair.second.c_str(), params->at(pair.second).c_str(),
pair.first.c_str(), alias->second.c_str()); pair.first.c_str(), alias->second.c_str());
} }
......
...@@ -77,4 +77,4 @@ private: ...@@ -77,4 +77,4 @@ private:
} }
#endif // LIGHTGBM_DATASET_LOADER_H_ #endif // LIGHTGBM_DATASET_LOADER_H_
\ No newline at end of file
...@@ -324,4 +324,3 @@ private: ...@@ -324,4 +324,3 @@ private:
} // namespace LightGBM } // namespace LightGBM
#endif // LightGBM_UTILS_TEXT_READER_H_ #endif // LightGBM_UTILS_TEXT_READER_H_
...@@ -13,9 +13,10 @@ from tempfile import NamedTemporaryFile ...@@ -13,9 +13,10 @@ from tempfile import NamedTemporaryFile
import numpy as np import numpy as np
import scipy.sparse import scipy.sparse
from .compat import (DataFrame, LGBMDeprecationWarning, Series, integer_types, from .compat import (DataFrame, LGBMDeprecationWarning, Series,
json, json_default_with_numpy, numeric_types, range_, decode_string, integer_types,
string_type) json, json_default_with_numpy,
numeric_types, range_, string_type)
from .libpath import find_lib_path from .libpath import find_lib_path
...@@ -45,7 +46,7 @@ def _safe_call(ret): ...@@ -45,7 +46,7 @@ def _safe_call(ret):
return value from API calls return value from API calls
""" """
if ret != 0: if ret != 0:
raise LightGBMError(_LIB.LGBM_GetLastError()) raise LightGBMError(decode_string(_LIB.LGBM_GetLastError()))
def is_numeric(obj): def is_numeric(obj):
......
...@@ -20,6 +20,9 @@ if is_py3: ...@@ -20,6 +20,9 @@ if is_py3:
def argc_(func): def argc_(func):
"""return number of arguments of a function""" """return number of arguments of a function"""
return len(inspect.signature(func).parameters) return len(inspect.signature(func).parameters)
def decode_string(bytestring):
return bytestring.decode('utf-8')
else: else:
string_type = basestring string_type = basestring
numeric_types = (int, long, float, bool) numeric_types = (int, long, float, bool)
...@@ -30,6 +33,9 @@ else: ...@@ -30,6 +33,9 @@ else:
"""return number of arguments of a function""" """return number of arguments of a function"""
return len(inspect.getargspec(func).args) return len(inspect.getargspec(func).args)
def decode_string(bytestring):
return bytestring
"""json""" """json"""
try: try:
import simplejson as json import simplejson as json
......
...@@ -130,12 +130,12 @@ public: ...@@ -130,12 +130,12 @@ public:
void Predict(const char* data_filename, const char* result_filename, bool has_header) { void Predict(const char* data_filename, const char* result_filename, bool has_header) {
auto writer = VirtualFileWriter::Make(result_filename); auto writer = VirtualFileWriter::Make(result_filename);
if (!writer->Init()) { if (!writer->Init()) {
Log::Fatal("Prediction results file %s cannot be found.", result_filename); Log::Fatal("Prediction results file %s cannot be found", result_filename);
} }
auto parser = std::unique_ptr<Parser>(Parser::CreateParser(data_filename, has_header, boosting_->MaxFeatureIdx() + 1, boosting_->LabelIdx())); auto parser = std::unique_ptr<Parser>(Parser::CreateParser(data_filename, has_header, boosting_->MaxFeatureIdx() + 1, boosting_->LabelIdx()));
if (parser == nullptr) { if (parser == nullptr) {
Log::Fatal("Could not recognize the data format of data file %s.", data_filename); Log::Fatal("Could not recognize the data format of data file %s", data_filename);
} }
TextReader<data_size_t> predict_data_reader(data_filename, has_header); TextReader<data_size_t> predict_data_reader(data_filename, has_header);
......
...@@ -23,7 +23,7 @@ bool Boosting::LoadFileToBoosting(Boosting* boosting, const char* filename) { ...@@ -23,7 +23,7 @@ bool Boosting::LoadFileToBoosting(Boosting* boosting, const char* filename) {
} }
} }
std::chrono::duration<double, std::milli> delta = (std::chrono::steady_clock::now() - start_time); std::chrono::duration<double, std::milli> delta = (std::chrono::steady_clock::now() - start_time);
Log::Debug("time for loading model: %f seconds", 1e-3*delta); Log::Debug("Time for loading model: %f seconds", 1e-3*delta);
return true; return true;
} }
...@@ -52,11 +52,11 @@ Boosting* Boosting::CreateBoosting(const std::string& type, const char* filename ...@@ -52,11 +52,11 @@ Boosting* Boosting::CreateBoosting(const std::string& type, const char* filename
} else if (type == std::string("rf")) { } else if (type == std::string("rf")) {
return new RF(); return new RF();
} else { } else {
Log::Fatal("unknown boosting type %s", type.c_str()); Log::Fatal("Unknown boosting type %s", type.c_str());
} }
LoadFileToBoosting(ret.get(), filename); LoadFileToBoosting(ret.get(), filename);
} else { } else {
Log::Fatal("unknown model format or submodel type in model file %s", filename); Log::Fatal("Unknown model format or submodel type in model file %s", filename);
} }
return ret.release(); return ret.release();
} }
......
...@@ -171,7 +171,7 @@ void GBDT::Init(const BoostingConfig* config, const Dataset* train_data, const O ...@@ -171,7 +171,7 @@ void GBDT::Init(const BoostingConfig* config, const Dataset* train_data, const O
void GBDT::AddValidDataset(const Dataset* valid_data, void GBDT::AddValidDataset(const Dataset* valid_data,
const std::vector<const Metric*>& valid_metrics) { const std::vector<const Metric*>& valid_metrics) {
if (!train_data_->CheckAlign(*valid_data)) { if (!train_data_->CheckAlign(*valid_data)) {
Log::Fatal("cannot add validation data, since it has different bin mappers with training data"); Log::Fatal("Cannot add validation data, since it has different bin mappers with training data");
} }
// for a validation dataset, we need its score and metric // for a validation dataset, we need its score and metric
auto new_score_updater = std::unique_ptr<ScoreUpdater>(new ScoreUpdater(valid_data, num_tree_per_iteration_)); auto new_score_updater = std::unique_ptr<ScoreUpdater>(new ScoreUpdater(valid_data, num_tree_per_iteration_));
...@@ -377,7 +377,7 @@ double GBDT::BoostFromAverage() { ...@@ -377,7 +377,7 @@ double GBDT::BoostFromAverage() {
} else if (std::string(objective_function_->GetName()) == std::string("regression_l1") } else if (std::string(objective_function_->GetName()) == std::string("regression_l1")
|| std::string(objective_function_->GetName()) == std::string("quantile") || std::string(objective_function_->GetName()) == std::string("quantile")
|| std::string(objective_function_->GetName()) == std::string("mape")) { || std::string(objective_function_->GetName()) == std::string("mape")) {
Log::Warning("Disable boost_from_average in %s may cause the slow convergence.", objective_function_->GetName()); Log::Warning("Disable boost_from_average in %s may cause the slow convergence", objective_function_->GetName());
} }
} }
return 0.0f; return 0.0f;
...@@ -469,7 +469,7 @@ bool GBDT::TrainOneIter(const score_t* gradients, const score_t* hessians) { ...@@ -469,7 +469,7 @@ bool GBDT::TrainOneIter(const score_t* gradients, const score_t* hessians) {
} }
if (!should_continue) { if (!should_continue) {
Log::Warning("Stopped training because there are no more leaves that meet the split requirements."); Log::Warning("Stopped training because there are no more leaves that meet the split requirements");
for (int cur_tree_id = 0; cur_tree_id < num_tree_per_iteration_; ++cur_tree_id) { for (int cur_tree_id = 0; cur_tree_id < num_tree_per_iteration_; ++cur_tree_id) {
models_.pop_back(); models_.pop_back();
} }
...@@ -730,7 +730,7 @@ void GBDT::ResetTrainingData(const Dataset* train_data, const ObjectiveFunction* ...@@ -730,7 +730,7 @@ void GBDT::ResetTrainingData(const Dataset* train_data, const ObjectiveFunction*
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");
} }
objective_function_ = objective_function; objective_function_ = objective_function;
...@@ -825,7 +825,7 @@ void GBDT::ResetBaggingConfig(const BoostingConfig* config, bool is_change_datas ...@@ -825,7 +825,7 @@ void GBDT::ResetBaggingConfig(const BoostingConfig* config, bool is_change_datas
tmp_subset_->CopyFeatureMapperFrom(train_data_); tmp_subset_->CopyFeatureMapperFrom(train_data_);
} }
is_use_subset_ = true; is_use_subset_ = true;
Log::Debug("use subset for bagging"); Log::Debug("Use subset for bagging");
} }
if (is_change_dataset) { if (is_change_dataset) {
......
...@@ -393,7 +393,7 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) { ...@@ -393,7 +393,7 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) {
return false; return false;
} }
} else { } else {
Log::Fatal("Model file doesn't contain feature names"); Log::Fatal("Model file doesn't contain feature_names");
return false; return false;
} }
...@@ -404,7 +404,7 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) { ...@@ -404,7 +404,7 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) {
return false; return false;
} }
} else { } else {
Log::Fatal("Model file doesn't contain feature infos"); Log::Fatal("Model file doesn't contain feature_infos");
return false; return false;
} }
...@@ -491,7 +491,7 @@ std::vector<double> GBDT::FeatureImportance(int num_iteration, int importance_ty ...@@ -491,7 +491,7 @@ std::vector<double> GBDT::FeatureImportance(int num_iteration, int importance_ty
} }
} }
} else { } else {
Log::Fatal("Unknown importance type: only support split=0 and gain=1."); Log::Fatal("Unknown importance type: only support split=0 and gain=1");
} }
return feature_importances; return feature_importances;
} }
......
...@@ -60,9 +60,9 @@ public: ...@@ -60,9 +60,9 @@ public:
CHECK(gbdt_config_->top_rate + gbdt_config_->other_rate <= 1.0f); CHECK(gbdt_config_->top_rate + gbdt_config_->other_rate <= 1.0f);
CHECK(gbdt_config_->top_rate > 0.0f && gbdt_config_->other_rate > 0.0f); CHECK(gbdt_config_->top_rate > 0.0f && gbdt_config_->other_rate > 0.0f);
if (gbdt_config_->bagging_freq > 0 && gbdt_config_->bagging_fraction != 1.0f) { if (gbdt_config_->bagging_freq > 0 && gbdt_config_->bagging_fraction != 1.0f) {
Log::Fatal("cannot use bagging in GOSS"); Log::Fatal("Cannot use bagging in GOSS");
} }
Log::Info("using GOSS"); Log::Info("Using GOSS");
bag_data_indices_.resize(num_data_); bag_data_indices_.resize(num_data_);
tmp_indices_.resize(num_data_); tmp_indices_.resize(num_data_);
......
...@@ -35,7 +35,7 @@ public: ...@@ -35,7 +35,7 @@ public:
if (init_score != nullptr) { if (init_score != nullptr) {
if ((data->metadata().num_init_score() % num_data_) != 0 if ((data->metadata().num_init_score() % num_data_) != 0
|| (data->metadata().num_init_score() / num_data_) != num_tree_per_iteration) { || (data->metadata().num_init_score() / num_data_) != num_tree_per_iteration) {
Log::Fatal("number of class for initial score error"); Log::Fatal("Number of class for initial score error");
} }
has_init_score_ = true; has_init_score_ = true;
#pragma omp parallel for schedule(static) #pragma omp parallel for schedule(static)
......
...@@ -42,8 +42,8 @@ public: ...@@ -42,8 +42,8 @@ public:
} }
// create boosting // create boosting
if (config_.io_config.input_model.size() > 0) { if (config_.io_config.input_model.size() > 0) {
Log::Warning("continued train from model is not support for c_api, \ Log::Warning("Continued train from model is not supported for c_api,\n"
please use continued train with input score"); "please use continued train with input score");
} }
boosting_.reset(Boosting::CreateBoosting(config_.boosting_type, nullptr)); boosting_.reset(Boosting::CreateBoosting(config_.boosting_type, nullptr));
...@@ -52,10 +52,10 @@ public: ...@@ -52,10 +52,10 @@ public:
CreateObjectiveAndMetrics(); CreateObjectiveAndMetrics();
// initialize the boosting // initialize the boosting
if (config_.boosting_config.tree_learner_type == std::string("feature")) { if (config_.boosting_config.tree_learner_type == std::string("feature")) {
Log::Fatal("Do not support feature parallel in c api."); Log::Fatal("Do not support feature parallel in c api");
} }
if (Network::num_machines() == 1 && config_.boosting_config.tree_learner_type != std::string("serial")) { if (Network::num_machines() == 1 && config_.boosting_config.tree_learner_type != std::string("serial")) {
Log::Warning("Only find one worker, will switch to serial tree learner."); Log::Warning("Only find one worker, will switch to serial tree learner");
config_.boosting_config.tree_learner_type = "serial"; config_.boosting_config.tree_learner_type = "serial";
} }
boosting_->Init(&config_.boosting_config, train_data_, objective_fun_.get(), boosting_->Init(&config_.boosting_config, train_data_, objective_fun_.get(),
...@@ -112,13 +112,13 @@ public: ...@@ -112,13 +112,13 @@ public:
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
auto param = ConfigBase::Str2Map(parameters); auto param = ConfigBase::Str2Map(parameters);
if (param.count("num_class")) { if (param.count("num_class")) {
Log::Fatal("cannot change num class during training"); Log::Fatal("Cannot change num_class during training");
} }
if (param.count("boosting_type")) { if (param.count("boosting_type")) {
Log::Fatal("cannot change boosting_type during training"); Log::Fatal("Cannot change boosting_type during training");
} }
if (param.count("metric")) { if (param.count("metric")) {
Log::Fatal("cannot change metric during training"); Log::Fatal("Cannot change metric during training");
} }
config_.Set(param); config_.Set(param);
...@@ -757,7 +757,7 @@ int LGBM_DatasetSetField(DatasetHandle handle, ...@@ -757,7 +757,7 @@ int LGBM_DatasetSetField(DatasetHandle handle,
} else if (type == C_API_DTYPE_FLOAT64) { } else if (type == C_API_DTYPE_FLOAT64) {
is_success = dataset->SetDoubleField(field_name, reinterpret_cast<const double*>(field_data), static_cast<int32_t>(num_element)); is_success = dataset->SetDoubleField(field_name, reinterpret_cast<const double*>(field_data), static_cast<int32_t>(num_element));
} }
if (!is_success) { throw std::runtime_error("Input data type erorr or field not found"); } if (!is_success) { throw std::runtime_error("Input data type error or field not found"); }
API_END(); API_END();
} }
...@@ -901,7 +901,7 @@ int LGBM_BoosterUpdateOneIterCustom(BoosterHandle handle, ...@@ -901,7 +901,7 @@ int LGBM_BoosterUpdateOneIterCustom(BoosterHandle handle,
API_BEGIN(); API_BEGIN();
Booster* ref_booster = reinterpret_cast<Booster*>(handle); Booster* ref_booster = reinterpret_cast<Booster*>(handle);
#ifdef SCORE_T_USE_DOUBLE #ifdef SCORE_T_USE_DOUBLE
Log::Fatal("Don't support Custom loss function when enable SCORE_T_USE_DOUBLE."); Log::Fatal("Don't support custom loss function when SCORE_T_USE_DOUBLE is enabled");
#else #else
if (ref_booster->TrainOneIter(grad, hess)) { if (ref_booster->TrainOneIter(grad, hess)) {
*is_finished = 1; *is_finished = 1;
...@@ -1275,7 +1275,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_ ...@@ -1275,7 +1275,7 @@ RowFunctionFromDenseMatric(const void* data, int num_row, int num_col, int data_
}; };
} }
} }
throw std::runtime_error("unknown data type in RowFunctionFromDenseMatric"); throw std::runtime_error("Unknown data type in RowFunctionFromDenseMatric");
} }
std::function<std::vector<std::pair<int, double>>(int row_idx)> std::function<std::vector<std::pair<int, double>>(int row_idx)>
...@@ -1349,7 +1349,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices, ...@@ -1349,7 +1349,7 @@ RowFunctionFromCSR(const void* indptr, int indptr_type, const int32_t* indices,
}; };
} }
} }
throw std::runtime_error("unknown data type in RowFunctionFromCSR"); throw std::runtime_error("Unknown data type in RowFunctionFromCSR");
} }
std::function<std::pair<int, double>(int idx)> std::function<std::pair<int, double>(int idx)>
...@@ -1414,7 +1414,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind ...@@ -1414,7 +1414,7 @@ IterateFunctionFromCSC(const void* col_ptr, int col_ptr_type, const int32_t* ind
}; };
} }
} }
throw std::runtime_error("unknown data type in CSC matrix"); throw std::runtime_error("Unknown data type in CSC matrix");
} }
CSC_RowIterator::CSC_RowIterator(const void* col_ptr, int col_ptr_type, const int32_t* indices, CSC_RowIterator::CSC_RowIterator(const void* col_ptr, int col_ptr_type, const int32_t* indices,
......
...@@ -22,7 +22,7 @@ void ConfigBase::KV2Map(std::unordered_map<std::string, std::string>& params, co ...@@ -22,7 +22,7 @@ void ConfigBase::KV2Map(std::unordered_map<std::string, std::string>& params, co
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",
key.c_str(), value_search->second.c_str(), key.c_str(), value.c_str(), key.c_str(), value_search->second.c_str(), key.c_str(), value.c_str(),
key.c_str(), value_search->second.c_str()); key.c_str(), value_search->second.c_str());
} }
...@@ -249,8 +249,9 @@ void OverallConfig::CheckParamConflict() { ...@@ -249,8 +249,9 @@ void OverallConfig::CheckParamConflict() {
is_parallel_find_bin = true; is_parallel_find_bin = true;
if (boosting_config.tree_config.histogram_pool_size >= 0 if (boosting_config.tree_config.histogram_pool_size >= 0
&& boosting_config.tree_learner_type == std::string("data")) { && boosting_config.tree_learner_type == std::string("data")) {
Log::Warning("Histogram LRU queue was enabled (histogram_pool_size=%f). Will disable this to reduce communication costs" Log::Warning("Histogram LRU queue was enabled (histogram_pool_size=%f).\n"
, boosting_config.tree_config.histogram_pool_size); "Will disable this to reduce communication costs",
boosting_config.tree_config.histogram_pool_size);
// Change pool size to -1 (no limit) when using data parallel to reduce communication costs // Change pool size to -1 (no limit) when using data parallel to reduce communication costs
boosting_config.tree_config.histogram_pool_size = -1; boosting_config.tree_config.histogram_pool_size = -1;
} }
...@@ -260,7 +261,7 @@ void OverallConfig::CheckParamConflict() { ...@@ -260,7 +261,7 @@ void OverallConfig::CheckParamConflict() {
int full_num_leaves = static_cast<int>(std::pow(2, boosting_config.tree_config.max_depth)); int full_num_leaves = static_cast<int>(std::pow(2, boosting_config.tree_config.max_depth));
if (full_num_leaves > boosting_config.tree_config.num_leaves if (full_num_leaves > boosting_config.tree_config.num_leaves
&& boosting_config.tree_config.num_leaves == kDefaultNumLeaves) { && boosting_config.tree_config.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");
} }
} }
} }
......
...@@ -226,10 +226,10 @@ void Dataset::Construct( ...@@ -226,10 +226,10 @@ void Dataset::Construct(
} }
} }
if (used_features.empty()) { if (used_features.empty()) {
Log::Fatal("Cannot construct Dataset since there are not useful features. \ Log::Fatal("Cannot construct Dataset since there are not useful features.\n"
It should be at least two unique rows. \ "It should be at least two unique rows.\n"
If the num_row (num_data) is small, you can set min_data=1 and min_data_in_bin=1 to fix this. \ "If the num_row (num_data) is small, you can set min_data=1 and min_data_in_bin=1 to fix this.\n"
Otherwise please make sure you are using the right dataset."); "Otherwise please make sure you are using the right dataset");
} }
auto features_in_group = NoGroup(used_features); auto features_in_group = NoGroup(used_features);
...@@ -440,13 +440,13 @@ bool Dataset::SetFloatField(const char* field_name, const float* field_data, dat ...@@ -440,13 +440,13 @@ bool Dataset::SetFloatField(const char* field_name, const float* field_data, dat
name = Common::Trim(name); name = Common::Trim(name);
if (name == std::string("label") || name == std::string("target")) { if (name == std::string("label") || name == std::string("target")) {
#ifdef LABEL_T_USE_DOUBLE #ifdef LABEL_T_USE_DOUBLE
Log::Fatal("Don't Support LABEL_T_USE_DOUBLE."); Log::Fatal("Don't support LABEL_T_USE_DOUBLE");
#else #else
metadata_.SetLabel(field_data, num_element); metadata_.SetLabel(field_data, num_element);
#endif #endif
} else if (name == std::string("weight") || name == std::string("weights")) { } else if (name == std::string("weight") || name == std::string("weights")) {
#ifdef LABEL_T_USE_DOUBLE #ifdef LABEL_T_USE_DOUBLE
Log::Fatal("Don't Support LABEL_T_USE_DOUBLE."); Log::Fatal("Don't support LABEL_T_USE_DOUBLE");
#else #else
metadata_.SetWeights(field_data, num_element); metadata_.SetWeights(field_data, num_element);
#endif #endif
...@@ -483,14 +483,14 @@ bool Dataset::GetFloatField(const char* field_name, data_size_t* out_len, const ...@@ -483,14 +483,14 @@ bool Dataset::GetFloatField(const char* field_name, data_size_t* out_len, const
name = Common::Trim(name); name = Common::Trim(name);
if (name == std::string("label") || name == std::string("target")) { if (name == std::string("label") || name == std::string("target")) {
#ifdef LABEL_T_USE_DOUBLE #ifdef LABEL_T_USE_DOUBLE
Log::Fatal("Don't Support LABEL_T_USE_DOUBLE."); Log::Fatal("Don't support LABEL_T_USE_DOUBLE");
#else #else
*out_ptr = metadata_.label(); *out_ptr = metadata_.label();
*out_len = num_data_; *out_len = num_data_;
#endif #endif
} else if (name == std::string("weight") || name == std::string("weights")) { } else if (name == std::string("weight") || name == std::string("weights")) {
#ifdef LABEL_T_USE_DOUBLE #ifdef LABEL_T_USE_DOUBLE
Log::Fatal("Don't Support LABEL_T_USE_DOUBLE."); Log::Fatal("Don't support LABEL_T_USE_DOUBLE");
#else #else
*out_ptr = metadata_.weights(); *out_ptr = metadata_.weights();
*out_len = num_data_; *out_len = num_data_;
...@@ -528,7 +528,7 @@ bool Dataset::GetIntField(const char* field_name, data_size_t* out_len, const in ...@@ -528,7 +528,7 @@ bool Dataset::GetIntField(const char* field_name, data_size_t* out_len, const in
void Dataset::SaveBinaryFile(const char* bin_filename) { void Dataset::SaveBinaryFile(const char* bin_filename) {
if (bin_filename != nullptr if (bin_filename != nullptr
&& std::string(bin_filename) == data_filename_) { && std::string(bin_filename) == data_filename_) {
Log::Warning("Bianry file %s already existed", bin_filename); Log::Warning("Bianry file %s already exists", bin_filename);
return; return;
} }
// if not pass a filename, just append ".bin" of original file // if not pass a filename, just append ".bin" of original file
...@@ -541,7 +541,7 @@ void Dataset::SaveBinaryFile(const char* bin_filename) { ...@@ -541,7 +541,7 @@ void Dataset::SaveBinaryFile(const char* bin_filename) {
if (VirtualFileWriter::Exists(bin_filename)) { if (VirtualFileWriter::Exists(bin_filename)) {
is_file_existed = true; is_file_existed = true;
Log::Warning("File %s existed, cannot save binary to it", bin_filename); Log::Warning("File %s exists, cannot save binary to it", bin_filename);
} }
if (!is_file_existed) { if (!is_file_existed) {
......
...@@ -46,14 +46,14 @@ void DatasetLoader::SetHeader(const char* filename) { ...@@ -46,14 +46,14 @@ void DatasetLoader::SetHeader(const char* filename) {
if (label_idx_ >= 0) { if (label_idx_ >= 0) {
Log::Info("Using column %s as label", name.c_str()); Log::Info("Using column %s as label", name.c_str());
} else { } else {
Log::Fatal("Could not find label column %s in data file \ Log::Fatal("Could not find label column %s in data file \n"
or data file doesn't contain header", name.c_str()); "or data file doesn't contain header", name.c_str());
} }
} else { } else {
if (!Common::AtoiAndCheck(io_config_.label_column.c_str(), &label_idx_)) { if (!Common::AtoiAndCheck(io_config_.label_column.c_str(), &label_idx_)) {
Log::Fatal("label_column is not a number, \ Log::Fatal("label_column is not a number,\n"
if you want to use a column name, \ "if you want to use a column name,\n"
please add the prefix \"name:\" to the column name"); "please add the prefix \"name:\" to the column name");
} }
Log::Info("Using column number %d as label", label_idx_); Log::Info("Using column number %d as label", label_idx_);
} }
...@@ -83,9 +83,9 @@ void DatasetLoader::SetHeader(const char* filename) { ...@@ -83,9 +83,9 @@ void DatasetLoader::SetHeader(const char* filename) {
for (auto token : Common::Split(io_config_.ignore_column.c_str(), ',')) { for (auto token : Common::Split(io_config_.ignore_column.c_str(), ',')) {
int tmp = 0; int tmp = 0;
if (!Common::AtoiAndCheck(token.c_str(), &tmp)) { if (!Common::AtoiAndCheck(token.c_str(), &tmp)) {
Log::Fatal("ignore_column is not a number, \ Log::Fatal("ignore_column is not a number,\n"
if you want to use a column name, \ "if you want to use a column name,\n"
please add the prefix \"name:\" to the column name"); "please add the prefix \"name:\" to the column name");
} }
ignore_features_.emplace(tmp); ignore_features_.emplace(tmp);
} }
...@@ -103,9 +103,9 @@ void DatasetLoader::SetHeader(const char* filename) { ...@@ -103,9 +103,9 @@ void DatasetLoader::SetHeader(const char* filename) {
} }
} else { } else {
if (!Common::AtoiAndCheck(io_config_.weight_column.c_str(), &weight_idx_)) { if (!Common::AtoiAndCheck(io_config_.weight_column.c_str(), &weight_idx_)) {
Log::Fatal("weight_column is not a number, \ Log::Fatal("weight_column is not a number,\n"
if you want to use a column name, \ "if you want to use a column name,\n"
please add the prefix \"name:\" to the column name"); "please add the prefix \"name:\" to the column name");
} }
Log::Info("Using column number %d as weight", weight_idx_); Log::Info("Using column number %d as weight", weight_idx_);
} }
...@@ -123,9 +123,9 @@ void DatasetLoader::SetHeader(const char* filename) { ...@@ -123,9 +123,9 @@ void DatasetLoader::SetHeader(const char* filename) {
} }
} else { } else {
if (!Common::AtoiAndCheck(io_config_.group_column.c_str(), &group_idx_)) { if (!Common::AtoiAndCheck(io_config_.group_column.c_str(), &group_idx_)) {
Log::Fatal("group_column is not a number, \ Log::Fatal("group_column is not a number,\n"
if you want to use a column name, \ "if you want to use a column name,\n"
please add the prefix \"name:\" to the column name"); "please add the prefix \"name:\" to the column name");
} }
Log::Info("Using column number %d as group/query id", group_idx_); Log::Info("Using column number %d as group/query id", group_idx_);
} }
...@@ -147,9 +147,9 @@ void DatasetLoader::SetHeader(const char* filename) { ...@@ -147,9 +147,9 @@ void DatasetLoader::SetHeader(const char* filename) {
for (auto token : Common::Split(io_config_.categorical_column.c_str(), ',')) { for (auto token : Common::Split(io_config_.categorical_column.c_str(), ',')) {
int tmp = 0; int tmp = 0;
if (!Common::AtoiAndCheck(token.c_str(), &tmp)) { if (!Common::AtoiAndCheck(token.c_str(), &tmp)) {
Log::Fatal("categorical_column is not a number, \ Log::Fatal("categorical_column is not a number,\n"
if you want to use a column name, \ "if you want to use a column name,\n"
please add the prefix \"name:\" to the column name"); "please add the prefix \"name:\" to the column name");
} }
categorical_features_.emplace(tmp); categorical_features_.emplace(tmp);
} }
...@@ -161,8 +161,8 @@ Dataset* DatasetLoader::LoadFromFile(const char* filename, const char* initscore ...@@ -161,8 +161,8 @@ Dataset* DatasetLoader::LoadFromFile(const char* filename, const char* initscore
// don't support query id in data file when training in parallel // don't support query id in data file when training in parallel
if (num_machines > 1 && !io_config_.is_pre_partition) { if (num_machines > 1 && !io_config_.is_pre_partition) {
if (group_idx_ > 0) { if (group_idx_ > 0) {
Log::Fatal("Using a query id without pre-partitioning the data file is not supported for parallel training. \ Log::Fatal("Using a query id without pre-partitioning the data file is not supported for parallel training.\n"
Please use an additional query file or pre-partition the data"); "Please use an additional query file or pre-partition the data");
} }
} }
auto dataset = std::unique_ptr<Dataset>(new Dataset()); auto dataset = std::unique_ptr<Dataset>(new Dataset());
...@@ -282,7 +282,7 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b ...@@ -282,7 +282,7 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
Log::Fatal("Binary file error: token has the wrong size"); Log::Fatal("Binary file error: token has the wrong size");
} }
if (std::string(buffer.data()) != std::string(Dataset::binary_file_token)) { if (std::string(buffer.data()) != std::string(Dataset::binary_file_token)) {
Log::Fatal("input file is not LightGBM binary file"); Log::Fatal("Input file is not LightGBM binary file");
} }
// read size of header // read size of header
...@@ -437,7 +437,8 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b ...@@ -437,7 +437,8 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
bool is_query_used = false; bool is_query_used = false;
for (data_size_t i = 0; i < dataset->num_data_; ++i) { for (data_size_t i = 0; i < dataset->num_data_; ++i) {
if (qid >= num_queries) { if (qid >= num_queries) {
Log::Fatal("Current query exceeds the range of the query file, please ensure the query file is correct"); Log::Fatal("Current query exceeds the range of the query file,\n"
"please ensure the query file is correct");
} }
if (i >= query_boundaries[qid + 1]) { if (i >= query_boundaries[qid + 1]) {
// if is new query // if is new query
...@@ -642,7 +643,7 @@ void DatasetLoader::CheckDataset(const Dataset* dataset) { ...@@ -642,7 +643,7 @@ void DatasetLoader::CheckDataset(const Dataset* dataset) {
last_sub_feature = sub_feature; last_sub_feature = sub_feature;
} }
if (!is_feature_order_by_group) { if (!is_feature_order_by_group) {
Log::Fatal("feature in dataset should order by group"); Log::Fatal("Features in dataset should be ordered by group");
} }
} }
...@@ -676,7 +677,8 @@ std::vector<std::string> DatasetLoader::LoadTextDataToMemory(const char* filenam ...@@ -676,7 +677,8 @@ std::vector<std::string> DatasetLoader::LoadTextDataToMemory(const char* filenam
[this, rank, num_machines, &qid, &query_boundaries, &is_query_used, num_queries] [this, rank, num_machines, &qid, &query_boundaries, &is_query_used, num_queries]
(data_size_t line_idx) { (data_size_t line_idx) {
if (qid >= num_queries) { if (qid >= num_queries) {
Log::Fatal("Current query exceeds the range of the query file, please ensure the query file is correct"); Log::Fatal("Current query exceeds the range of the query file,\n"
"please ensure the query file is correct");
} }
if (line_idx >= query_boundaries[qid + 1]) { if (line_idx >= query_boundaries[qid + 1]) {
// if is new query // if is new query
...@@ -1081,7 +1083,7 @@ std::string DatasetLoader::CheckCanLoadFromBin(const char* filename) { ...@@ -1081,7 +1083,7 @@ std::string DatasetLoader::CheckCanLoadFromBin(const char* filename) {
bin_filename = std::string(filename); bin_filename = std::string(filename);
reader = VirtualFileReader::Make(bin_filename.c_str()); reader = VirtualFileReader::Make(bin_filename.c_str());
if (!reader->Init()) { if (!reader->Init()) {
Log::Fatal("cannot open data file %s", bin_filename.c_str()); Log::Fatal("Cannot open data file %s", bin_filename.c_str());
} }
} }
......
...@@ -104,7 +104,7 @@ private: ...@@ -104,7 +104,7 @@ private:
} else if (ret == 0) { } else if (ret == 0) {
break; break;
} else if (errno != EINTR) { } else if (errno != EINTR) {
Log::Fatal("Failed hdfs file operation [%s]", strerror(errno)); Log::Fatal("Failed HDFS file operation [%s]", strerror(errno));
} }
} }
return bytes - remain; return bytes - remain;
...@@ -113,7 +113,7 @@ private: ...@@ -113,7 +113,7 @@ private:
static hdfsFS GetHDFSFileSystem(const std::string& uri) { static hdfsFS GetHDFSFileSystem(const std::string& uri) {
size_t end = uri.find("/", kHdfsProto.length()); size_t end = uri.find("/", kHdfsProto.length());
if (uri.find(kHdfsProto) != 0 || end == std::string::npos) { if (uri.find(kHdfsProto) != 0 || end == std::string::npos) {
Log::Warning("Bad hdfs uri, no namenode found [%s]", uri.c_str()); Log::Warning("Bad HDFS uri, no namenode found [%s]", uri.c_str());
return NULL; return NULL;
} }
std::string hostport = uri.substr(kHdfsProto.length(), end - kHdfsProto.length()); std::string hostport = uri.substr(kHdfsProto.length(), end - kHdfsProto.length());
...@@ -131,7 +131,7 @@ private: ...@@ -131,7 +131,7 @@ private:
iss >> port; iss >> port;
hdfsFS fs = iss.eof() ? hdfsConnect(host.c_str(), port) : NULL; hdfsFS fs = iss.eof() ? hdfsConnect(host.c_str(), port) : NULL;
if (fs == NULL) { if (fs == NULL) {
Log::Warning("Could not connect to hdfs namenode [%s]", hostport.c_str()); Log::Warning("Could not connect to HDFS namenode [%s]", hostport.c_str());
} }
return fs; return fs;
} }
...@@ -147,7 +147,7 @@ std::unordered_map<std::string, hdfsFS> HDFSFile::fs_cache_ = std::unordered_map ...@@ -147,7 +147,7 @@ std::unordered_map<std::string, hdfsFS> HDFSFile::fs_cache_ = std::unordered_map
#define WITH_HDFS(x) x #define WITH_HDFS(x) x
#else #else
#define WITH_HDFS(x) Log::Fatal("HDFS Support not enabled.") #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) { std::unique_ptr<VirtualFileReader> VirtualFileReader::Make(const std::string& filename) {
......
...@@ -388,7 +388,7 @@ struct JsonParser final { ...@@ -388,7 +388,7 @@ struct JsonParser final {
if (str[i] == '/') { if (str[i] == '/') {
i++; i++;
if (i == str.size()) if (i == str.size())
return fail("unexpected end of input after start of comment", false); return fail("Unexpected end of input after start of comment", false);
if (str[i] == '/') { // inline comment if (str[i] == '/') { // inline comment
i++; i++;
// advance until next line, or end of input // advance until next line, or end of input
...@@ -400,19 +400,18 @@ struct JsonParser final { ...@@ -400,19 +400,18 @@ struct JsonParser final {
else if (str[i] == '*') { // multiline comment else if (str[i] == '*') { // multiline comment
i++; i++;
if (i > str.size()-2) if (i > str.size()-2)
return fail("unexpected end of input inside multi-line comment", false); return fail("Unexpected end of input inside multi-line comment", false);
// advance until closing tokens // advance until closing tokens
while (!(str[i] == '*' && str[i+1] == '/')) { while (!(str[i] == '*' && str[i+1] == '/')) {
i++; i++;
if (i > str.size()-2) if (i > str.size()-2)
return fail( return fail("Unexpected end of input inside multi-line comment", false);
"unexpected end of input inside multi-line comment", false);
} }
i += 2; i += 2;
comment_found = true; comment_found = true;
} }
else else
return fail("malformed comment", false); return fail("Malformed comment", false);
} }
return comment_found; return comment_found;
} }
...@@ -443,7 +442,7 @@ struct JsonParser final { ...@@ -443,7 +442,7 @@ struct JsonParser final {
consume_garbage(); consume_garbage();
if (failed) return (char)0; if (failed) return (char)0;
if (i == str.size()) if (i == str.size())
return fail("unexpected end of input", (char)0); return fail("Unexpected end of input", (char)0);
return str[i++]; return str[i++];
} }
...@@ -482,7 +481,7 @@ struct JsonParser final { ...@@ -482,7 +481,7 @@ struct JsonParser final {
long last_escaped_codepoint = -1; long last_escaped_codepoint = -1;
while (true) { while (true) {
if (i == str.size()) if (i == str.size())
return fail("unexpected end of input in string", ""); return fail("Unexpected end of input in string", "");
char ch = str[i++]; char ch = str[i++];
...@@ -492,7 +491,7 @@ struct JsonParser final { ...@@ -492,7 +491,7 @@ struct JsonParser final {
} }
if (in_range(ch, 0, 0x1f)) if (in_range(ch, 0, 0x1f))
return fail("unescaped " + esc(ch) + " in string", ""); return fail("Unescaped " + esc(ch) + " in string", "");
// The usual case: non-escaped characters // The usual case: non-escaped characters
if (ch != '\\') { if (ch != '\\') {
...@@ -504,7 +503,7 @@ struct JsonParser final { ...@@ -504,7 +503,7 @@ struct JsonParser final {
// Handle escapes // Handle escapes
if (i == str.size()) if (i == str.size())
return fail("unexpected end of input in string", ""); return fail("Unexpected end of input in string", "");
ch = str[i++]; ch = str[i++];
...@@ -515,12 +514,12 @@ struct JsonParser final { ...@@ -515,12 +514,12 @@ struct JsonParser final {
// relies on std::string returning the terminating NUL when // relies on std::string returning the terminating NUL when
// accessing str[length]. Checking here reduces brittleness. // accessing str[length]. Checking here reduces brittleness.
if (esc.length() < 4) { if (esc.length() < 4) {
return fail("bad \\u escape: " + esc, ""); return fail("Bad \\u escape: " + esc, "");
} }
for (size_t j = 0; j < 4; j++) { for (size_t j = 0; j < 4; j++) {
if (!in_range(esc[j], 'a', 'f') && !in_range(esc[j], 'A', 'F') if (!in_range(esc[j], 'a', 'f') && !in_range(esc[j], 'A', 'F')
&& !in_range(esc[j], '0', '9')) && !in_range(esc[j], '0', '9'))
return fail("bad \\u escape: " + esc, ""); return fail("Bad \\u escape: " + esc, "");
} }
long codepoint = strtol(esc.data(), nullptr, 16); long codepoint = strtol(esc.data(), nullptr, 16);
...@@ -561,7 +560,7 @@ struct JsonParser final { ...@@ -561,7 +560,7 @@ struct JsonParser final {
} else if (ch == '"' || ch == '\\' || ch == '/') { } else if (ch == '"' || ch == '\\' || ch == '/') {
out += ch; out += ch;
} else { } else {
return fail("invalid escape character " + esc(ch), ""); return fail("Invalid escape character " + esc(ch), "");
} }
} }
} }
...@@ -580,13 +579,13 @@ struct JsonParser final { ...@@ -580,13 +579,13 @@ struct JsonParser final {
if (str[i] == '0') { if (str[i] == '0') {
i++; i++;
if (in_range(str[i], '0', '9')) if (in_range(str[i], '0', '9'))
return fail("leading 0s not permitted in numbers"); return fail("Leading 0s not permitted in numbers");
} else if (in_range(str[i], '1', '9')) { } else if (in_range(str[i], '1', '9')) {
i++; i++;
while (in_range(str[i], '0', '9')) while (in_range(str[i], '0', '9'))
i++; i++;
} else { } else {
return fail("invalid " + esc(str[i]) + " in number"); return fail("Invalid " + esc(str[i]) + " in number");
} }
if (str[i] != '.' && str[i] != 'e' && str[i] != 'E' if (str[i] != '.' && str[i] != 'e' && str[i] != 'E'
...@@ -598,7 +597,7 @@ struct JsonParser final { ...@@ -598,7 +597,7 @@ struct JsonParser final {
if (str[i] == '.') { if (str[i] == '.') {
i++; i++;
if (!in_range(str[i], '0', '9')) if (!in_range(str[i], '0', '9'))
return fail("at least one digit required in fractional part"); return fail("At least one digit required in fractional part");
while (in_range(str[i], '0', '9')) while (in_range(str[i], '0', '9'))
i++; i++;
...@@ -612,7 +611,7 @@ struct JsonParser final { ...@@ -612,7 +611,7 @@ struct JsonParser final {
i++; i++;
if (!in_range(str[i], '0', '9')) if (!in_range(str[i], '0', '9'))
return fail("at least one digit required in exponent"); return fail("At least one digit required in exponent");
while (in_range(str[i], '0', '9')) while (in_range(str[i], '0', '9'))
i++; i++;
...@@ -633,7 +632,7 @@ struct JsonParser final { ...@@ -633,7 +632,7 @@ struct JsonParser final {
i += expected.length(); i += expected.length();
return res; return res;
} else { } else {
return fail("parse error: expected " + expected + ", got " + str.substr(i, expected.length())); return fail("Parse error: expected " + expected + ", got " + str.substr(i, expected.length()));
} }
} }
...@@ -643,7 +642,7 @@ struct JsonParser final { ...@@ -643,7 +642,7 @@ struct JsonParser final {
*/ */
Json parse_json(int depth) { Json parse_json(int depth) {
if (depth > max_depth) { if (depth > max_depth) {
return fail("exceeded maximum nesting depth"); return fail("Exceeded maximum nesting depth");
} }
char ch = get_next_token(); char ch = get_next_token();
...@@ -675,7 +674,7 @@ struct JsonParser final { ...@@ -675,7 +674,7 @@ struct JsonParser final {
while (1) { while (1) {
if (ch != '"') if (ch != '"')
return fail("expected '\"' in object, got " + esc(ch)); return fail("Expected '\"' in object, got " + esc(ch));
string key = parse_string(); string key = parse_string();
if (failed) if (failed)
...@@ -683,7 +682,7 @@ struct JsonParser final { ...@@ -683,7 +682,7 @@ struct JsonParser final {
ch = get_next_token(); ch = get_next_token();
if (ch != ':') if (ch != ':')
return fail("expected ':' in object, got " + esc(ch)); return fail("Expected ':' in object, got " + esc(ch));
data[std::move(key)] = parse_json(depth + 1); data[std::move(key)] = parse_json(depth + 1);
if (failed) if (failed)
...@@ -693,7 +692,7 @@ struct JsonParser final { ...@@ -693,7 +692,7 @@ struct JsonParser final {
if (ch == '}') if (ch == '}')
break; break;
if (ch != ',') if (ch != ',')
return fail("expected ',' in object, got " + esc(ch)); return fail("Expected ',' in object, got " + esc(ch));
ch = get_next_token(); ch = get_next_token();
} }
...@@ -716,7 +715,7 @@ struct JsonParser final { ...@@ -716,7 +715,7 @@ struct JsonParser final {
if (ch == ']') if (ch == ']')
break; break;
if (ch != ',') if (ch != ',')
return fail("expected ',' in list, got " + esc(ch)); return fail("Expected ',' in list, got " + esc(ch));
ch = get_next_token(); ch = get_next_token();
(void)ch; (void)ch;
...@@ -724,7 +723,7 @@ struct JsonParser final { ...@@ -724,7 +723,7 @@ struct JsonParser final {
return data; return data;
} }
return fail("expected value, got " + esc(ch)); return fail("Expected value, got " + esc(ch));
} }
}; };
}//namespace { }//namespace {
...@@ -738,7 +737,7 @@ Json Json::parse(const string &in, string &err, JsonParse strategy) { ...@@ -738,7 +737,7 @@ Json Json::parse(const string &in, string &err, JsonParse strategy) {
if (parser.failed) if (parser.failed)
return Json(); return Json();
if (parser.i != in.size()) if (parser.i != in.size())
return parser.fail("unexpected trailing " + esc(in[parser.i])); return parser.fail("Unexpected trailing " + esc(in[parser.i]));
return result; return result;
} }
...@@ -771,13 +770,13 @@ vector<Json> Json::parse_multi(const string &in, ...@@ -771,13 +770,13 @@ vector<Json> Json::parse_multi(const string &in,
bool Json::has_shape(const shape & types, string & err) const { bool Json::has_shape(const shape & types, string & err) const {
if (!is_object()) { if (!is_object()) {
err = "expected JSON object, got " + dump(); err = "Expected JSON object, got " + dump();
return false; return false;
} }
for (auto & item : types) { for (auto & item : types) {
if ((*this)[item.first].type() != item.second) { if ((*this)[item.first].type() != item.second) {
err = "bad type for " + item.first + " in " + dump(); err = "Bad type for " + item.first + " in " + dump();
return false; return false;
} }
} }
......
...@@ -308,7 +308,7 @@ void Metadata::SetLabel(const label_t* label, data_size_t len) { ...@@ -308,7 +308,7 @@ void Metadata::SetLabel(const label_t* label, data_size_t len) {
Log::Fatal("label cannot be nullptr"); Log::Fatal("label cannot be nullptr");
} }
if (num_data_ != len) { if (num_data_ != len) {
Log::Fatal("len of label is not same with #data"); Log::Fatal("Length of label is not same with #data");
} }
if (!label_.empty()) { label_.clear(); } if (!label_.empty()) { label_.clear(); }
label_ = std::vector<label_t>(num_data_); label_ = std::vector<label_t>(num_data_);
...@@ -327,7 +327,7 @@ void Metadata::SetWeights(const label_t* weights, data_size_t len) { ...@@ -327,7 +327,7 @@ void Metadata::SetWeights(const label_t* weights, data_size_t len) {
return; return;
} }
if (num_data_ != len) { if (num_data_ != len) {
Log::Fatal("len of weights is not same with #data"); Log::Fatal("Length of weights is not same with #data");
} }
if (!weights_.empty()) { weights_.clear(); } if (!weights_.empty()) { weights_.clear(); }
num_weights_ = num_data_; num_weights_ = num_data_;
...@@ -354,7 +354,7 @@ void Metadata::SetQuery(const data_size_t* query, data_size_t len) { ...@@ -354,7 +354,7 @@ void Metadata::SetQuery(const data_size_t* query, data_size_t len) {
sum += query[i]; sum += query[i];
} }
if (num_data_ != sum) { if (num_data_ != sum) {
Log::Fatal("sum of query counts is not same with #data"); Log::Fatal("Sum of query counts is not same with #data");
} }
if (!query_boundaries_.empty()) { query_boundaries_.clear(); } if (!query_boundaries_.empty()) { query_boundaries_.clear(); }
num_queries_ = len; num_queries_ = len;
...@@ -424,7 +424,7 @@ void Metadata::LoadInitialScore(const char* initscore_file) { ...@@ -424,7 +424,7 @@ void Metadata::LoadInitialScore(const char* initscore_file) {
double tmp = 0.0f; double tmp = 0.0f;
oneline_init_score = Common::Split(reader.Lines()[i].c_str(), '\t'); oneline_init_score = Common::Split(reader.Lines()[i].c_str(), '\t');
if (static_cast<int>(oneline_init_score.size()) != num_class) { if (static_cast<int>(oneline_init_score.size()) != num_class) {
Log::Fatal("Invalid initial score file. Redundant or insufficient columns."); Log::Fatal("Invalid initial score file. Redundant or insufficient columns");
} }
for (int k = 0; k < num_class; ++k) { for (int k = 0; k < num_class; ++k) {
Common::Atof(oneline_init_score[k].c_str(), &tmp); Common::Atof(oneline_init_score[k].c_str(), &tmp);
......
...@@ -87,7 +87,7 @@ void getline(std::stringstream& ss, std::string& line, const VirtualFileReader* ...@@ -87,7 +87,7 @@ void getline(std::stringstream& ss, std::string& line, const VirtualFileReader*
Parser* Parser::CreateParser(const char* filename, bool has_header, int num_features, int label_idx) { Parser* Parser::CreateParser(const char* filename, bool has_header, int num_features, int label_idx) {
auto reader = VirtualFileReader::Make(filename); auto reader = VirtualFileReader::Make(filename);
if (!reader->Init()) { if (!reader->Init()) {
Log::Fatal("Data file %s doesn't exist'", filename); Log::Fatal("Data file %s doesn't exist", filename);
} }
std::string line1, line2; std::string line1, line2;
size_t buffer_size = 64 * 1024; size_t buffer_size = 64 * 1024;
......
...@@ -493,13 +493,13 @@ Tree::Tree(const char* str, size_t* used_len) { ...@@ -493,13 +493,13 @@ Tree::Tree(const char* str, size_t* used_len) {
*used_len = p - str; *used_len = p - str;
if (key_vals.count("num_leaves") <= 0) { if (key_vals.count("num_leaves") <= 0) {
Log::Fatal("Tree model should contain num_leaves field."); Log::Fatal("Tree model should contain num_leaves field");
} }
Common::Atoi(key_vals["num_leaves"].c_str(), &num_leaves_); Common::Atoi(key_vals["num_leaves"].c_str(), &num_leaves_);
if (key_vals.count("num_cat") <= 0) { if (key_vals.count("num_cat") <= 0) {
Log::Fatal("Tree model should contain num_cat field."); Log::Fatal("Tree model should contain num_cat field");
} }
Common::Atoi(key_vals["num_cat"].c_str(), &num_cat_); Common::Atoi(key_vals["num_cat"].c_str(), &num_cat_);
...@@ -576,7 +576,7 @@ Tree::Tree(const char* str, size_t* used_len) { ...@@ -576,7 +576,7 @@ Tree::Tree(const char* str, size_t* used_len) {
if (key_vals.count("cat_threshold")) { if (key_vals.count("cat_threshold")) {
cat_threshold_ = Common::StringToArrayFast<uint32_t>(key_vals["cat_threshold"], cat_boundaries_.back()); cat_threshold_ = Common::StringToArrayFast<uint32_t>(key_vals["cat_threshold"], cat_boundaries_.back());
} else { } else {
Log::Fatal("Tree model should contain cat_threshold field."); Log::Fatal("Tree model should contain cat_threshold field");
} }
} }
......
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