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 {
// set priority by length & alphabetically to ensure reproducible behavior
if (alias_set->second.size() < pair.first.size() ||
(alias_set->second.size() == pair.first.size() && alias_set->second < pair.first)) {
Log::Warning("%s is set with %s=%s, %s=%s will be ignored. Current value: %s=%s.",
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(),
pair.first.c_str(), pair.second.c_str(), alias->second.c_str(), params->at(alias_set->second).c_str());
} 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(),
pair.first.c_str(), pair.second.c_str(), alias->second.c_str(), pair.second.c_str());
tmp_map[alias->second] = pair.first;
......@@ -520,7 +520,7 @@ struct ParameterAlias {
params->emplace(pair.first, params->at(pair.second));
params->erase(pair.second);
} 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());
}
......
......@@ -77,4 +77,4 @@ private:
}
#endif // LIGHTGBM_DATASET_LOADER_H_
\ No newline at end of file
#endif // LIGHTGBM_DATASET_LOADER_H_
......@@ -324,4 +324,3 @@ private:
} // namespace LightGBM
#endif // LightGBM_UTILS_TEXT_READER_H_
......@@ -13,9 +13,10 @@ from tempfile import NamedTemporaryFile
import numpy as np
import scipy.sparse
from .compat import (DataFrame, LGBMDeprecationWarning, Series, integer_types,
json, json_default_with_numpy, numeric_types, range_,
string_type)
from .compat import (DataFrame, LGBMDeprecationWarning, Series,
decode_string, integer_types,
json, json_default_with_numpy,
numeric_types, range_, string_type)
from .libpath import find_lib_path
......@@ -45,7 +46,7 @@ def _safe_call(ret):
return value from API calls
"""
if ret != 0:
raise LightGBMError(_LIB.LGBM_GetLastError())
raise LightGBMError(decode_string(_LIB.LGBM_GetLastError()))
def is_numeric(obj):
......
......@@ -20,6 +20,9 @@ if is_py3:
def argc_(func):
"""return number of arguments of a function"""
return len(inspect.signature(func).parameters)
def decode_string(bytestring):
return bytestring.decode('utf-8')
else:
string_type = basestring
numeric_types = (int, long, float, bool)
......@@ -30,6 +33,9 @@ else:
"""return number of arguments of a function"""
return len(inspect.getargspec(func).args)
def decode_string(bytestring):
return bytestring
"""json"""
try:
import simplejson as json
......
......@@ -130,12 +130,12 @@ public:
void Predict(const char* data_filename, const char* result_filename, bool has_header) {
auto writer = VirtualFileWriter::Make(result_filename);
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()));
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);
......
......@@ -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);
Log::Debug("time for loading model: %f seconds", 1e-3*delta);
Log::Debug("Time for loading model: %f seconds", 1e-3*delta);
return true;
}
......@@ -52,11 +52,11 @@ Boosting* Boosting::CreateBoosting(const std::string& type, const char* filename
} else if (type == std::string("rf")) {
return new RF();
} else {
Log::Fatal("unknown boosting type %s", type.c_str());
Log::Fatal("Unknown boosting type %s", type.c_str());
}
LoadFileToBoosting(ret.get(), filename);
} 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();
}
......
......@@ -171,7 +171,7 @@ void GBDT::Init(const BoostingConfig* config, const Dataset* train_data, const O
void GBDT::AddValidDataset(const Dataset* valid_data,
const std::vector<const Metric*>& valid_metrics) {
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
auto new_score_updater = std::unique_ptr<ScoreUpdater>(new ScoreUpdater(valid_data, num_tree_per_iteration_));
......@@ -377,7 +377,7 @@ double GBDT::BoostFromAverage() {
} 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("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;
......@@ -469,7 +469,7 @@ bool GBDT::TrainOneIter(const score_t* gradients, const score_t* hessians) {
}
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) {
models_.pop_back();
}
......@@ -730,7 +730,7 @@ void GBDT::ResetTrainingData(const Dataset* train_data, const ObjectiveFunction*
const std::vector<const Metric*>& training_metrics) {
if (train_data != train_data_ && !train_data_->CheckAlign(*train_data)) {
Log::Fatal("cannot reset training data, since new training data has different bin mappers");
Log::Fatal("Cannot reset training data, since new training data has different bin mappers");
}
objective_function_ = objective_function;
......@@ -825,7 +825,7 @@ void GBDT::ResetBaggingConfig(const BoostingConfig* config, bool is_change_datas
tmp_subset_->CopyFeatureMapperFrom(train_data_);
}
is_use_subset_ = true;
Log::Debug("use subset for bagging");
Log::Debug("Use subset for bagging");
}
if (is_change_dataset) {
......
......@@ -393,7 +393,7 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) {
return false;
}
} else {
Log::Fatal("Model file doesn't contain feature names");
Log::Fatal("Model file doesn't contain feature_names");
return false;
}
......@@ -404,7 +404,7 @@ bool GBDT::LoadModelFromString(const char* buffer, size_t len) {
return false;
}
} else {
Log::Fatal("Model file doesn't contain feature infos");
Log::Fatal("Model file doesn't contain feature_infos");
return false;
}
......@@ -491,7 +491,7 @@ std::vector<double> GBDT::FeatureImportance(int num_iteration, int importance_ty
}
}
} 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;
}
......
......@@ -60,9 +60,9 @@ public:
CHECK(gbdt_config_->top_rate + gbdt_config_->other_rate <= 1.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) {
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_);
tmp_indices_.resize(num_data_);
......
......@@ -35,7 +35,7 @@ public:
if (init_score != nullptr) {
if ((data->metadata().num_init_score() % num_data_) != 0
|| (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;
#pragma omp parallel for schedule(static)
......
......@@ -42,8 +42,8 @@ public:
}
// create boosting
if (config_.io_config.input_model.size() > 0) {
Log::Warning("continued train from model is not support for c_api, \
please use continued train with input score");
Log::Warning("Continued train from model is not supported for c_api,\n"
"please use continued train with input score");
}
boosting_.reset(Boosting::CreateBoosting(config_.boosting_type, nullptr));
......@@ -52,10 +52,10 @@ public:
CreateObjectiveAndMetrics();
// initialize the boosting
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")) {
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";
}
boosting_->Init(&config_.boosting_config, train_data_, objective_fun_.get(),
......@@ -112,13 +112,13 @@ public:
std::lock_guard<std::mutex> lock(mutex_);
auto param = ConfigBase::Str2Map(parameters);
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")) {
Log::Fatal("cannot change boosting_type during training");
Log::Fatal("Cannot change boosting_type during training");
}
if (param.count("metric")) {
Log::Fatal("cannot change metric during training");
Log::Fatal("Cannot change metric during training");
}
config_.Set(param);
......@@ -757,7 +757,7 @@ int LGBM_DatasetSetField(DatasetHandle handle,
} 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));
}
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();
}
......@@ -901,7 +901,7 @@ int LGBM_BoosterUpdateOneIterCustom(BoosterHandle handle,
API_BEGIN();
Booster* ref_booster = reinterpret_cast<Booster*>(handle);
#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
if (ref_booster->TrainOneIter(grad, hess)) {
*is_finished = 1;
......@@ -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)>
......@@ -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)>
......@@ -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,
......
......@@ -22,7 +22,7 @@ void ConfigBase::KV2Map(std::unordered_map<std::string, std::string>& params, co
if (value_search == params.end()) { // not set
params.emplace(key, value);
} else {
Log::Warning("%s is set=%s, %s=%s will be ignored. Current value: %s=%s.",
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());
}
......@@ -249,8 +249,9 @@ void OverallConfig::CheckParamConflict() {
is_parallel_find_bin = true;
if (boosting_config.tree_config.histogram_pool_size >= 0
&& 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"
, boosting_config.tree_config.histogram_pool_size);
Log::Warning("Histogram LRU queue was enabled (histogram_pool_size=%f).\n"
"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
boosting_config.tree_config.histogram_pool_size = -1;
}
......@@ -260,7 +261,7 @@ void OverallConfig::CheckParamConflict() {
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
&& 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(
}
}
if (used_features.empty()) {
Log::Fatal("Cannot construct Dataset since there are not useful features. \
It should be at least two unique rows. \
If the num_row (num_data) is small, you can set min_data=1 and min_data_in_bin=1 to fix this. \
Otherwise please make sure you are using the right dataset.");
Log::Fatal("Cannot construct Dataset since there are not useful features.\n"
"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.\n"
"Otherwise please make sure you are using the right dataset");
}
auto features_in_group = NoGroup(used_features);
......@@ -440,13 +440,13 @@ bool Dataset::SetFloatField(const char* field_name, const float* field_data, dat
name = Common::Trim(name);
if (name == std::string("label") || name == std::string("target")) {
#ifdef LABEL_T_USE_DOUBLE
Log::Fatal("Don't Support LABEL_T_USE_DOUBLE.");
Log::Fatal("Don't support LABEL_T_USE_DOUBLE");
#else
metadata_.SetLabel(field_data, num_element);
#endif
} else if (name == std::string("weight") || name == std::string("weights")) {
#ifdef LABEL_T_USE_DOUBLE
Log::Fatal("Don't Support LABEL_T_USE_DOUBLE.");
Log::Fatal("Don't support LABEL_T_USE_DOUBLE");
#else
metadata_.SetWeights(field_data, num_element);
#endif
......@@ -483,14 +483,14 @@ bool Dataset::GetFloatField(const char* field_name, data_size_t* out_len, const
name = Common::Trim(name);
if (name == std::string("label") || name == std::string("target")) {
#ifdef LABEL_T_USE_DOUBLE
Log::Fatal("Don't Support LABEL_T_USE_DOUBLE.");
Log::Fatal("Don't support LABEL_T_USE_DOUBLE");
#else
*out_ptr = metadata_.label();
*out_len = num_data_;
#endif
} else if (name == std::string("weight") || name == std::string("weights")) {
#ifdef LABEL_T_USE_DOUBLE
Log::Fatal("Don't Support LABEL_T_USE_DOUBLE.");
Log::Fatal("Don't support LABEL_T_USE_DOUBLE");
#else
*out_ptr = metadata_.weights();
*out_len = num_data_;
......@@ -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) {
if (bin_filename != nullptr
&& 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;
}
// if not pass a filename, just append ".bin" of original file
......@@ -541,7 +541,7 @@ void Dataset::SaveBinaryFile(const char* bin_filename) {
if (VirtualFileWriter::Exists(bin_filename)) {
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) {
......
......@@ -46,14 +46,14 @@ void DatasetLoader::SetHeader(const char* filename) {
if (label_idx_ >= 0) {
Log::Info("Using column %s as label", name.c_str());
} else {
Log::Fatal("Could not find label column %s in data file \
or data file doesn't contain header", name.c_str());
Log::Fatal("Could not find label column %s in data file \n"
"or data file doesn't contain header", name.c_str());
}
} else {
if (!Common::AtoiAndCheck(io_config_.label_column.c_str(), &label_idx_)) {
Log::Fatal("label_column is not a number, \
if you want to use a column name, \
please add the prefix \"name:\" to the column name");
Log::Fatal("label_column is not a number,\n"
"if you want to use a column name,\n"
"please add the prefix \"name:\" to the column name");
}
Log::Info("Using column number %d as label", label_idx_);
}
......@@ -83,9 +83,9 @@ void DatasetLoader::SetHeader(const char* filename) {
for (auto token : Common::Split(io_config_.ignore_column.c_str(), ',')) {
int tmp = 0;
if (!Common::AtoiAndCheck(token.c_str(), &tmp)) {
Log::Fatal("ignore_column is not a number, \
if you want to use a column name, \
please add the prefix \"name:\" to the column name");
Log::Fatal("ignore_column is not a number,\n"
"if you want to use a column name,\n"
"please add the prefix \"name:\" to the column name");
}
ignore_features_.emplace(tmp);
}
......@@ -103,9 +103,9 @@ void DatasetLoader::SetHeader(const char* filename) {
}
} else {
if (!Common::AtoiAndCheck(io_config_.weight_column.c_str(), &weight_idx_)) {
Log::Fatal("weight_column is not a number, \
if you want to use a column name, \
please add the prefix \"name:\" to the column name");
Log::Fatal("weight_column is not a number,\n"
"if you want to use a column name,\n"
"please add the prefix \"name:\" to the column name");
}
Log::Info("Using column number %d as weight", weight_idx_);
}
......@@ -123,9 +123,9 @@ void DatasetLoader::SetHeader(const char* filename) {
}
} else {
if (!Common::AtoiAndCheck(io_config_.group_column.c_str(), &group_idx_)) {
Log::Fatal("group_column is not a number, \
if you want to use a column name, \
please add the prefix \"name:\" to the column name");
Log::Fatal("group_column is not a number,\n"
"if you want to use a column name,\n"
"please add the prefix \"name:\" to the column name");
}
Log::Info("Using column number %d as group/query id", group_idx_);
}
......@@ -147,9 +147,9 @@ void DatasetLoader::SetHeader(const char* filename) {
for (auto token : Common::Split(io_config_.categorical_column.c_str(), ',')) {
int tmp = 0;
if (!Common::AtoiAndCheck(token.c_str(), &tmp)) {
Log::Fatal("categorical_column is not a number, \
if you want to use a column name, \
please add the prefix \"name:\" to the column name");
Log::Fatal("categorical_column is not a number,\n"
"if you want to use a column name,\n"
"please add the prefix \"name:\" to the column name");
}
categorical_features_.emplace(tmp);
}
......@@ -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
if (num_machines > 1 && !io_config_.is_pre_partition) {
if (group_idx_ > 0) {
Log::Fatal("Using a query id without pre-partitioning the data file is not supported for parallel training. \
Please use an additional query file or pre-partition the data");
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");
}
}
auto dataset = std::unique_ptr<Dataset>(new Dataset());
......@@ -282,7 +282,7 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
Log::Fatal("Binary file error: token has the wrong size");
}
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
......@@ -437,7 +437,8 @@ Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* b
bool is_query_used = false;
for (data_size_t i = 0; i < dataset->num_data_; ++i) {
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 is new query
......@@ -642,7 +643,7 @@ void DatasetLoader::CheckDataset(const Dataset* dataset) {
last_sub_feature = sub_feature;
}
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
[this, rank, num_machines, &qid, &query_boundaries, &is_query_used, num_queries]
(data_size_t line_idx) {
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 is new query
......@@ -1081,7 +1083,7 @@ std::string DatasetLoader::CheckCanLoadFromBin(const char* filename) {
bin_filename = std::string(filename);
reader = VirtualFileReader::Make(bin_filename.c_str());
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:
} else if (ret == 0) {
break;
} 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;
......@@ -113,7 +113,7 @@ private:
static hdfsFS GetHDFSFileSystem(const std::string& uri) {
size_t end = uri.find("/", kHdfsProto.length());
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;
}
std::string hostport = uri.substr(kHdfsProto.length(), end - kHdfsProto.length());
......@@ -131,7 +131,7 @@ private:
iss >> port;
hdfsFS fs = iss.eof() ? hdfsConnect(host.c_str(), port) : 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;
}
......@@ -147,7 +147,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 not enabled.")
#define WITH_HDFS(x) Log::Fatal("HDFS support is not enabled")
#endif // USE_HDFS
std::unique_ptr<VirtualFileReader> VirtualFileReader::Make(const std::string& filename) {
......
......@@ -388,7 +388,7 @@ struct JsonParser final {
if (str[i] == '/') {
i++;
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
i++;
// advance until next line, or end of input
......@@ -400,19 +400,18 @@ struct JsonParser final {
else if (str[i] == '*') { // multiline comment
i++;
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
while (!(str[i] == '*' && str[i+1] == '/')) {
i++;
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);
}
i += 2;
comment_found = true;
}
else
return fail("malformed comment", false);
return fail("Malformed comment", false);
}
return comment_found;
}
......@@ -443,7 +442,7 @@ struct JsonParser final {
consume_garbage();
if (failed) return (char)0;
if (i == str.size())
return fail("unexpected end of input", (char)0);
return fail("Unexpected end of input", (char)0);
return str[i++];
}
......@@ -482,7 +481,7 @@ struct JsonParser final {
long last_escaped_codepoint = -1;
while (true) {
if (i == str.size())
return fail("unexpected end of input in string", "");
return fail("Unexpected end of input in string", "");
char ch = str[i++];
......@@ -492,7 +491,7 @@ struct JsonParser final {
}
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
if (ch != '\\') {
......@@ -504,7 +503,7 @@ struct JsonParser final {
// Handle escapes
if (i == str.size())
return fail("unexpected end of input in string", "");
return fail("Unexpected end of input in string", "");
ch = str[i++];
......@@ -515,12 +514,12 @@ struct JsonParser final {
// relies on std::string returning the terminating NUL when
// accessing str[length]. Checking here reduces brittleness.
if (esc.length() < 4) {
return fail("bad \\u escape: " + esc, "");
return fail("Bad \\u escape: " + esc, "");
}
for (size_t j = 0; j < 4; j++) {
if (!in_range(esc[j], 'a', 'f') && !in_range(esc[j], 'A', 'F')
&& !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);
......@@ -561,7 +560,7 @@ struct JsonParser final {
} else if (ch == '"' || ch == '\\' || ch == '/') {
out += ch;
} else {
return fail("invalid escape character " + esc(ch), "");
return fail("Invalid escape character " + esc(ch), "");
}
}
}
......@@ -580,13 +579,13 @@ struct JsonParser final {
if (str[i] == '0') {
i++;
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')) {
i++;
while (in_range(str[i], '0', '9'))
i++;
} 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'
......@@ -598,7 +597,7 @@ struct JsonParser final {
if (str[i] == '.') {
i++;
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'))
i++;
......@@ -612,7 +611,7 @@ struct JsonParser final {
i++;
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'))
i++;
......@@ -633,7 +632,7 @@ struct JsonParser final {
i += expected.length();
return res;
} 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 {
*/
Json parse_json(int depth) {
if (depth > max_depth) {
return fail("exceeded maximum nesting depth");
return fail("Exceeded maximum nesting depth");
}
char ch = get_next_token();
......@@ -675,7 +674,7 @@ struct JsonParser final {
while (1) {
if (ch != '"')
return fail("expected '\"' in object, got " + esc(ch));
return fail("Expected '\"' in object, got " + esc(ch));
string key = parse_string();
if (failed)
......@@ -683,7 +682,7 @@ struct JsonParser final {
ch = get_next_token();
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);
if (failed)
......@@ -693,7 +692,7 @@ struct JsonParser final {
if (ch == '}')
break;
if (ch != ',')
return fail("expected ',' in object, got " + esc(ch));
return fail("Expected ',' in object, got " + esc(ch));
ch = get_next_token();
}
......@@ -716,7 +715,7 @@ struct JsonParser final {
if (ch == ']')
break;
if (ch != ',')
return fail("expected ',' in list, got " + esc(ch));
return fail("Expected ',' in list, got " + esc(ch));
ch = get_next_token();
(void)ch;
......@@ -724,7 +723,7 @@ struct JsonParser final {
return data;
}
return fail("expected value, got " + esc(ch));
return fail("Expected value, got " + esc(ch));
}
};
}//namespace {
......@@ -738,7 +737,7 @@ Json Json::parse(const string &in, string &err, JsonParse strategy) {
if (parser.failed)
return Json();
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;
}
......@@ -771,13 +770,13 @@ vector<Json> Json::parse_multi(const string &in,
bool Json::has_shape(const shape & types, string & err) const {
if (!is_object()) {
err = "expected JSON object, got " + dump();
err = "Expected JSON object, got " + dump();
return false;
}
for (auto & item : types) {
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;
}
}
......
......@@ -308,7 +308,7 @@ void Metadata::SetLabel(const label_t* label, data_size_t len) {
Log::Fatal("label cannot be nullptr");
}
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(); }
label_ = std::vector<label_t>(num_data_);
......@@ -327,7 +327,7 @@ void Metadata::SetWeights(const label_t* weights, data_size_t len) {
return;
}
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(); }
num_weights_ = num_data_;
......@@ -354,7 +354,7 @@ void Metadata::SetQuery(const data_size_t* query, data_size_t len) {
sum += query[i];
}
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(); }
num_queries_ = len;
......@@ -424,7 +424,7 @@ void Metadata::LoadInitialScore(const char* initscore_file) {
double tmp = 0.0f;
oneline_init_score = Common::Split(reader.Lines()[i].c_str(), '\t');
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) {
Common::Atof(oneline_init_score[k].c_str(), &tmp);
......
......@@ -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) {
auto reader = VirtualFileReader::Make(filename);
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;
size_t buffer_size = 64 * 1024;
......
......@@ -493,13 +493,13 @@ Tree::Tree(const char* str, size_t* used_len) {
*used_len = p - str;
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_);
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_);
......@@ -576,7 +576,7 @@ Tree::Tree(const char* str, size_t* used_len) {
if (key_vals.count("cat_threshold")) {
cat_threshold_ = Common::StringToArrayFast<uint32_t>(key_vals["cat_threshold"], cat_boundaries_.back());
} 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