diff --git a/src/gbm/gblinear-inl.hpp b/src/gbm/gblinear-inl.hpp index a9d4c8d62..624f15c28 100644 --- a/src/gbm/gblinear-inl.hpp +++ b/src/gbm/gblinear-inl.hpp @@ -24,6 +24,7 @@ class GBLinear : public IGradBooster { } // set model parameters virtual void SetParam(const char *name, const char *val) { + using namespace std; if (!strncmp(name, "bst:", 4)) { param.SetParam(name + 4, val); } @@ -166,6 +167,7 @@ class GBLinear : public IGradBooster { learning_rate = 1.0f; } inline void SetParam(const char *name, const char *val) { + using namespace std; // sync-names if (!strcmp("eta", name)) learning_rate = static_cast(atof(val)); if (!strcmp("lambda", name)) reg_lambda = static_cast(atof(val)); @@ -207,9 +209,10 @@ class GBLinear : public IGradBooster { Param(void) { num_feature = 0; num_output_group = 1; - memset(reserved, 0, sizeof(reserved)); + std::memset(reserved, 0, sizeof(reserved)); } inline void SetParam(const char *name, const char *val) { + using namespace std; if (!strcmp(name, "bst:num_feature")) num_feature = atoi(val); if (!strcmp(name, "num_output_group")) num_output_group = atoi(val); } diff --git a/src/gbm/gbm.cpp b/src/gbm/gbm.cpp index 4713838e9..e280fdd4a 100644 --- a/src/gbm/gbm.cpp +++ b/src/gbm/gbm.cpp @@ -1,7 +1,6 @@ #define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_DEPRECATE #include -using namespace std; #include "./gbm.h" #include "./gbtree-inl.hpp" #include "./gblinear-inl.hpp" @@ -9,6 +8,7 @@ using namespace std; namespace xgboost { namespace gbm { IGradBooster* CreateGradBooster(const char *name) { + using namespace std; if (!strcmp("gbtree", name)) return new GBTree(); if (!strcmp("gblinear", name)) return new GBLinear(); utils::Error("unknown booster type: %s", name); diff --git a/src/gbm/gbtree-inl.hpp b/src/gbm/gbtree-inl.hpp index 8fea28727..ed52afa7d 100644 --- a/src/gbm/gbtree-inl.hpp +++ b/src/gbm/gbtree-inl.hpp @@ -23,6 +23,7 @@ class GBTree : public IGradBooster { this->Clear(); } virtual void SetParam(const char *name, const char *val) { + using namespace std; if (!strncmp(name, "bst:", 4)) { cfg.push_back(std::make_pair(std::string(name+4), std::string(val))); // set into updaters, if already intialized @@ -171,14 +172,14 @@ class GBTree : public IGradBooster { updaters.clear(); std::string tval = tparam.updater_seq; char *pstr; - pstr = strtok(&tval[0], ","); + pstr = std::strtok(&tval[0], ","); while (pstr != NULL) { updaters.push_back(tree::CreateUpdater(pstr)); for (size_t j = 0; j < cfg.size(); ++j) { // set parameters updaters.back()->SetParam(cfg[j].first.c_str(), cfg[j].second.c_str()); } - pstr = strtok(NULL, ","); + pstr = std::strtok(NULL, ","); } tparam.updater_initialized = 1; } @@ -279,6 +280,7 @@ class GBTree : public IGradBooster { updater_initialized = 0; } inline void SetParam(const char *name, const char *val){ + using namespace std; if (!strcmp(name, "updater") && strcmp(updater_seq.c_str(), val) != 0) { updater_seq = val; @@ -319,7 +321,7 @@ class GBTree : public IGradBooster { num_pbuffer = 0; num_output_group = 1; size_leaf_vector = 0; - memset(reserved, 0, sizeof(reserved)); + std::memset(reserved, 0, sizeof(reserved)); } /*! * \brief set parameters from outside @@ -327,6 +329,7 @@ class GBTree : public IGradBooster { * \param val value of the parameter */ inline void SetParam(const char *name, const char *val) { + using namespace std; if (!strcmp("num_pbuffer", name)) num_pbuffer = atol(val); if (!strcmp("num_output_group", name)) num_output_group = atol(val); if (!strcmp("bst:num_roots", name)) num_roots = atoi(val); diff --git a/src/io/io.cpp b/src/io/io.cpp index dead398f7..d251d7a96 100644 --- a/src/io/io.cpp +++ b/src/io/io.cpp @@ -1,7 +1,6 @@ #define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_DEPRECATE #include -using namespace std; #include "./io.h" #include "../utils/io.h" #include "../utils/utils.h" diff --git a/src/io/simple_dmatrix-inl.hpp b/src/io/simple_dmatrix-inl.hpp index 9a88a6bfa..374d621e9 100644 --- a/src/io/simple_dmatrix-inl.hpp +++ b/src/io/simple_dmatrix-inl.hpp @@ -55,8 +55,8 @@ class DMatrixSimple : public DataMatrix { RowBatch::Inst inst = batch[i]; row_data_.resize(row_data_.size() + inst.length); if (inst.length != 0) { - memcpy(&row_data_[row_ptr_.back()], inst.data, - sizeof(RowBatch::Entry) * inst.length); + std::memcpy(&row_data_[row_ptr_.back()], inst.data, + sizeof(RowBatch::Entry) * inst.length); } row_ptr_.push_back(row_ptr_.back() + inst.length); } @@ -82,6 +82,7 @@ class DMatrixSimple : public DataMatrix { * \param silent whether print information or not */ inline void LoadText(const char* fname, bool silent = false) { + using namespace std; this->Clear(); FILE* file = utils::FopenCheck(fname, "r"); float label; bool init = true; @@ -135,7 +136,7 @@ class DMatrixSimple : public DataMatrix { * \return whether loading is success */ inline bool LoadBinary(const char* fname, bool silent = false) { - FILE *fp = fopen64(fname, "rb"); + std::FILE *fp = fopen64(fname, "rb"); if (fp == NULL) return false; utils::FileStream fs(fp); this->LoadBinary(fs, silent, fname); @@ -208,6 +209,7 @@ class DMatrixSimple : public DataMatrix { * \param savebuffer whether do save binary buffer if it is text */ inline void CacheLoad(const char *fname, bool silent = false, bool savebuffer = true) { + using namespace std; size_t len = strlen(fname); if (len > 8 && !strcmp(fname + len - 7, ".buffer")) { if (!this->LoadBinary(fname, silent)) { diff --git a/src/learner/dmatrix.h b/src/learner/dmatrix.h index bef84900a..b58f7b2bb 100644 --- a/src/learner/dmatrix.h +++ b/src/learner/dmatrix.h @@ -90,6 +90,7 @@ struct MetaInfo { } // try to load group information from file, if exists inline bool TryLoadGroup(const char* fname, bool silent = false) { + using namespace std; FILE *fi = fopen64(fname, "r"); if (fi == NULL) return false; group_ptr.push_back(0); @@ -105,6 +106,7 @@ struct MetaInfo { return true; } inline std::vector& GetFloatInfo(const char *field) { + using namespace std; if (!strcmp(field, "label")) return labels; if (!strcmp(field, "weight")) return weights; if (!strcmp(field, "base_margin")) return base_margin; @@ -115,6 +117,7 @@ struct MetaInfo { return ((MetaInfo*)this)->GetFloatInfo(field); } inline std::vector &GetUIntInfo(const char *field) { + using namespace std; if (!strcmp(field, "root_index")) return info.root_index; if (!strcmp(field, "fold_index")) return info.fold_index; utils::Error("unknown field %s", field); @@ -125,6 +128,7 @@ struct MetaInfo { } // try to load weight information from file, if exists inline bool TryLoadFloatInfo(const char *field, const char* fname, bool silent = false) { + using namespace std; std::vector &data = this->GetFloatInfo(field); FILE *fi = fopen64(fname, "r"); if (fi == NULL) return false; diff --git a/src/learner/evaluation-inl.hpp b/src/learner/evaluation-inl.hpp index 52877e17b..fb0b8953d 100644 --- a/src/learner/evaluation-inl.hpp +++ b/src/learner/evaluation-inl.hpp @@ -147,10 +147,11 @@ struct EvalAMS : public IEvaluator { explicit EvalAMS(const char *name) { name_ = name; // note: ams@0 will automatically select which ratio to go - utils::Check(sscanf(name, "ams@%f", &ratio_) == 1, "invalid ams format"); + utils::Check(std::sscanf(name, "ams@%f", &ratio_) == 1, "invalid ams format"); } virtual float Eval(const std::vector &preds, const MetaInfo &info) const { + using namespace std; const bst_omp_uint ndata = static_cast(info.labels.size()); utils::Check(info.weights.size() == ndata, "we need weight to evaluate ams"); @@ -202,6 +203,7 @@ struct EvalAMS : public IEvaluator { struct EvalPrecisionRatio : public IEvaluator{ public: explicit EvalPrecisionRatio(const char *name) : name_(name) { + using namespace std; if (sscanf(name, "apratio@%f", &ratio_) == 1) { use_ap = 1; } else { @@ -342,6 +344,7 @@ struct EvalRankList : public IEvaluator { protected: explicit EvalRankList(const char *name) { + using namespace std; name_ = name; minus_ = false; if (sscanf(name, "%*[^@]@%u[-]?", &topn_) != 1) { @@ -388,7 +391,7 @@ struct EvalNDCG : public EvalRankList{ for (size_t i = 0; i < rec.size() && i < this->topn_; ++i) { const unsigned rel = rec[i].second; if (rel != 0) { - sumdcg += ((1 << rel) - 1) / log(i + 2.0); + sumdcg += ((1 << rel) - 1) / std::log(i + 2.0); } } return static_cast(sumdcg); diff --git a/src/learner/evaluation.h b/src/learner/evaluation.h index ec37e1f4a..f34d832c8 100644 --- a/src/learner/evaluation.h +++ b/src/learner/evaluation.h @@ -36,6 +36,7 @@ struct IEvaluator{ namespace xgboost { namespace learner { inline IEvaluator* CreateEvaluator(const char *name) { + using namespace std; if (!strcmp(name, "rmse")) return new EvalRMSE(); if (!strcmp(name, "error")) return new EvalError(); if (!strcmp(name, "merror")) return new EvalMatchError(); @@ -56,6 +57,7 @@ inline IEvaluator* CreateEvaluator(const char *name) { class EvalSet{ public: inline void AddEval(const char *name) { + using namespace std; for (size_t i = 0; i < evals_.size(); ++i) { if (!strcmp(name, evals_[i]->Name())) return; } diff --git a/src/learner/learner-inl.hpp b/src/learner/learner-inl.hpp index 5d7c9d06a..05519de8b 100644 --- a/src/learner/learner-inl.hpp +++ b/src/learner/learner-inl.hpp @@ -79,6 +79,7 @@ class BoostLearner { * \param val value of the parameter */ inline void SetParam(const char *name, const char *val) { + using namespace std; // in this version, bst: prefix is no longer required if (strncmp(name, "bst:", 4) != 0) { std::string n = "bst:"; n += name; @@ -290,7 +291,7 @@ class BoostLearner { base_score = 0.5f; num_feature = 0; num_class = 0; - memset(reserved, 0, sizeof(reserved)); + std::memset(reserved, 0, sizeof(reserved)); } /*! * \brief set parameters from outside @@ -298,6 +299,7 @@ class BoostLearner { * \param val value of the parameter */ inline void SetParam(const char *name, const char *val) { + using namespace std; if (!strcmp("base_score", name)) base_score = static_cast(atof(val)); if (!strcmp("num_class", name)) num_class = atoi(val); if (!strcmp("bst:num_feature", name)) num_feature = atoi(val); diff --git a/src/learner/objective-inl.hpp b/src/learner/objective-inl.hpp index 576549eac..96aacf12d 100644 --- a/src/learner/objective-inl.hpp +++ b/src/learner/objective-inl.hpp @@ -101,6 +101,7 @@ class RegLossObj : public IObjFunction{ } virtual ~RegLossObj(void) {} virtual void SetParam(const char *name, const char *val) { + using namespace std; if (!strcmp("scale_pos_weight", name)) { scale_pos_weight = static_cast(atof(val)); } @@ -156,6 +157,7 @@ class SoftmaxMultiClassObj : public IObjFunction { } virtual ~SoftmaxMultiClassObj(void) {} virtual void SetParam(const char *name, const char *val) { + using namespace std; if (!strcmp( "num_class", name )) nclass = atoi(val); } virtual void GetGradient(const std::vector &preds, @@ -247,6 +249,7 @@ class LambdaRankObj : public IObjFunction { } virtual ~LambdaRankObj(void) {} virtual void SetParam(const char *name, const char *val) { + using namespace std; if (!strcmp( "loss_type", name )) loss.loss_type = atoi(val); if (!strcmp( "fix_list_weight", name)) fix_list_weight = static_cast(atof(val)); if (!strcmp( "num_pairsample", name)) num_pairsample = atoi(val); diff --git a/src/learner/objective.h b/src/learner/objective.h index d741ba61f..6b11b7d18 100644 --- a/src/learner/objective.h +++ b/src/learner/objective.h @@ -67,6 +67,7 @@ namespace xgboost { namespace learner { /*! \brief factory funciton to create objective function by name */ inline IObjFunction* CreateObjFunction(const char *name) { + using namespace std; if (!strcmp("reg:linear", name)) return new RegLossObj(LossType::kLinearSquare); if (!strcmp("reg:logistic", name)) return new RegLossObj(LossType::kLogisticNeglik); if (!strcmp("binary:logistic", name)) return new RegLossObj(LossType::kLogisticClassify); diff --git a/src/tree/model.h b/src/tree/model.h index 6d885faa7..8049a1608 100644 --- a/src/tree/model.h +++ b/src/tree/model.h @@ -53,7 +53,7 @@ class TreeModel { Param(void) { max_depth = 0; size_leaf_vector = 0; - memset(reserved, 0, sizeof(reserved)); + std::memset(reserved, 0, sizeof(reserved)); } /*! * \brief set parameters from outside @@ -61,6 +61,7 @@ class TreeModel { * \param val value of the parameter */ inline void SetParam(const char *name, const char *val) { + using namespace std; if (!strcmp("num_roots", name)) num_roots = atoi(val); if (!strcmp("num_feature", name)) num_feature = atoi(val); if (!strcmp("size_leaf_vector", name)) size_leaf_vector = atoi(val); diff --git a/src/tree/param.h b/src/tree/param.h index 79bc162c3..04ea5277f 100644 --- a/src/tree/param.h +++ b/src/tree/param.h @@ -62,6 +62,7 @@ struct TrainParam{ * \param val value of the parameter */ inline void SetParam(const char *name, const char *val) { + using namespace std; // sync-names if (!strcmp(name, "gamma")) min_split_loss = static_cast(atof(val)); if (!strcmp(name, "eta")) learning_rate = static_cast(atof(val)); diff --git a/src/tree/updater.cpp b/src/tree/updater.cpp index 09b63eb49..2cb6552fe 100644 --- a/src/tree/updater.cpp +++ b/src/tree/updater.cpp @@ -1,7 +1,6 @@ #define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_DEPRECATE #include -using namespace std; #include "./updater.h" #include "./updater_prune-inl.hpp" #include "./updater_refresh-inl.hpp" @@ -10,6 +9,7 @@ using namespace std; namespace xgboost { namespace tree { IUpdater* CreateUpdater(const char *name) { + using namespace std; if (!strcmp(name, "prune")) return new TreePruner(); if (!strcmp(name, "refresh")) return new TreeRefresher(); if (!strcmp(name, "grow_colmaker")) return new ColMaker(); diff --git a/src/tree/updater_prune-inl.hpp b/src/tree/updater_prune-inl.hpp index 98fdf5ee4..726999f55 100644 --- a/src/tree/updater_prune-inl.hpp +++ b/src/tree/updater_prune-inl.hpp @@ -17,6 +17,7 @@ class TreePruner: public IUpdater { virtual ~TreePruner(void) {} // set training parameter virtual void SetParam(const char *name, const char *val) { + using namespace std; param.SetParam(name, val); if (!strcmp(name, "silent")) silent = atoi(val); } diff --git a/src/utils/fmap.h b/src/utils/fmap.h index f9437cc6c..607f37013 100644 --- a/src/utils/fmap.h +++ b/src/utils/fmap.h @@ -24,15 +24,15 @@ class FeatMap { // function definitions /*! \brief load feature map from text format */ inline void LoadText(const char *fname) { - FILE *fi = utils::FopenCheck(fname, "r"); + std::FILE *fi = utils::FopenCheck(fname, "r"); this->LoadText(fi); - fclose(fi); + std::fclose(fi); } /*! \brief load feature map from text format */ - inline void LoadText(FILE *fi) { + inline void LoadText(std::FILE *fi) { int fid; char fname[1256], ftype[1256]; - while (fscanf(fi, "%d\t%[^\t]\t%s\n", &fid, fname, ftype) == 3) { + while (std::fscanf(fi, "%d\t%[^\t]\t%s\n", &fid, fname, ftype) == 3) { this->PushBack(fid, fname, ftype); } } @@ -62,6 +62,7 @@ class FeatMap { private: inline static Type GetType(const char *tname) { + using namespace std; if (!strcmp("i", tname)) return kIndicator; if (!strcmp("q", tname)) return kQuantitive; if (!strcmp("int", tname)) return kInteger; diff --git a/src/utils/io.h b/src/utils/io.h index a15e2f0ce..026e3fec7 100644 --- a/src/utils/io.h +++ b/src/utils/io.h @@ -91,21 +91,21 @@ class IStream { /*! \brief implementation of file i/o stream */ class FileStream : public IStream { private: - FILE *fp; + std::FILE *fp; public: - explicit FileStream(FILE *fp) : fp(fp) { + explicit FileStream(std::FILE *fp) : fp(fp) { } virtual size_t Read(void *ptr, size_t size) { - return fread(ptr, size, 1, fp); + return std::fread(ptr, size, 1, fp); } virtual void Write(const void *ptr, size_t size) { - fwrite(ptr, size, 1, fp); + std::fwrite(ptr, size, 1, fp); } inline void Seek(size_t pos) { - fseek(fp, 0, SEEK_SET); + std::fseek(fp, 0, SEEK_SET); } inline void Close(void) { - fclose(fp); + std::fclose(fp); } }; diff --git a/src/utils/random.h b/src/utils/random.h index 57e1f243d..1e3e617f9 100644 --- a/src/utils/random.h +++ b/src/utils/random.h @@ -53,7 +53,7 @@ inline double NextDouble(void) { } /*! \brief return a random number in n */ inline uint32_t NextUInt32(uint32_t n) { - return (uint32_t)floor(NextDouble() * n); + return (uint32_t)std::floor(NextDouble() * n); } /*! \brief return x~N(mu,sigma^2) */ inline double SampleNormal(double mu, double sigma) { diff --git a/src/utils/utils.h b/src/utils/utils.h index c319c5ab7..afe17f64c 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -149,8 +149,8 @@ inline void Error(const char *fmt, ...) { #endif /*! \brief replace fopen, report error when the file open fails */ -inline FILE *FopenCheck(const char *fname, const char *flag) { - FILE *fp = fopen64(fname, flag); +inline std::FILE *FopenCheck(const char *fname, const char *flag) { + std::FILE *fp = fopen64(fname, flag); Check(fp != NULL, "can not open file \"%s\"\n", fname); return fp; }