From 2e444f833864e7f944e77954d511ce1dff8b62fa Mon Sep 17 00:00:00 2001 From: Tianqi Chen Date: Sun, 23 Nov 2014 20:52:13 -0800 Subject: [PATCH] remove warning from MSVC need another round of check --- src/gbm/gbtree-inl.hpp | 2 +- src/io/io.cpp | 1 + src/io/page_dmatrix-inl.hpp | 2 +- src/io/page_fmatrix-inl.hpp | 4 ++-- src/learner/learner-inl.hpp | 2 +- src/sync/sync.h | 2 +- src/sync/sync_mpi.cpp | 6 +++--- src/sync/sync_tcp.cpp | 4 ++-- src/tree/updater_basemaker-inl.hpp | 3 ++- src/tree/updater_histmaker-inl.hpp | 18 +++++++++--------- src/utils/io.h | 2 +- src/utils/quantile.h | 14 ++++++++------ 12 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/gbm/gbtree-inl.hpp b/src/gbm/gbtree-inl.hpp index b20acd48e..8d511f06e 100644 --- a/src/gbm/gbtree-inl.hpp +++ b/src/gbm/gbtree-inl.hpp @@ -324,7 +324,7 @@ class GBTree : public IGradBooster { unsigned ntree_limit) { // number of valid trees if (ntree_limit == 0 || ntree_limit > trees.size()) { - ntree_limit = trees.size(); + ntree_limit = static_cast(trees.size()); } std::vector &preds = *out_preds; preds.resize(info.num_row * ntree_limit); diff --git a/src/io/io.cpp b/src/io/io.cpp index 0f9611e67..0072618c6 100644 --- a/src/io/io.cpp +++ b/src/io/io.cpp @@ -1,5 +1,6 @@ #define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_DEPRECATE +#define NOMINMAX #include #include "./io.h" #include "../utils/io.h" diff --git a/src/io/page_dmatrix-inl.hpp b/src/io/page_dmatrix-inl.hpp index 41ad19be5..4f70ff2e9 100644 --- a/src/io/page_dmatrix-inl.hpp +++ b/src/io/page_dmatrix-inl.hpp @@ -165,7 +165,7 @@ class ThreadRowPageIterator: public utils::IIterator { // loader factory for page struct Factory { public: - long file_begin_; + size_t file_begin_; utils::FileStream fi; Factory(void) {} inline void SetFile(const utils::FileStream &fi) { diff --git a/src/io/page_fmatrix-inl.hpp b/src/io/page_fmatrix-inl.hpp index 91d24cf2d..0527da827 100644 --- a/src/io/page_fmatrix-inl.hpp +++ b/src/io/page_fmatrix-inl.hpp @@ -138,8 +138,8 @@ class CSCMatrixManager { fi_->Seek(col_ptr_[cidx] * sizeof(ColBatch::Entry) + begin_data_); utils::Check(fi_->Read(p_data, sizeof(ColBatch::Entry) * len) != 0, "invalid column buffer format"); - p_page->col_data.push_back(ColBatch::Inst(p_data, len)); - p_page->col_index.push_back(cidx); + p_page->col_data.push_back(ColBatch::Inst(p_data, static_cast(len))); + p_page->col_index.push_back(static_cast(cidx)); return true; } // the following are in memory auxiliary data structure diff --git a/src/learner/learner-inl.hpp b/src/learner/learner-inl.hpp index d16986e83..05ab09f98 100644 --- a/src/learner/learner-inl.hpp +++ b/src/learner/learner-inl.hpp @@ -187,7 +187,7 @@ class BoostLearner { * \param p_train pointer to the matrix used by training */ inline void CheckInit(DMatrix *p_train) { - int ncol = p_train->info.info.num_col; + int ncol = static_cast(p_train->info.info.num_col); std::vector enabled(ncol, true); if (part_load_col != 0) { diff --git a/src/sync/sync.h b/src/sync/sync.h index 8d053faa0..2e14f2807 100644 --- a/src/sync/sync.h +++ b/src/sync/sync.h @@ -49,7 +49,7 @@ void Finalize(void); * \param op reduction function */ template -void AllReduce(DType *sendrecvbuf, int count, ReduceOp op); +void AllReduce(DType *sendrecvbuf, size_t count, ReduceOp op); /*! * \brief broadcast an std::string to all others from root diff --git a/src/sync/sync_mpi.cpp b/src/sync/sync_mpi.cpp index 42b7c7ba6..f867fa5d0 100644 --- a/src/sync/sync_mpi.cpp +++ b/src/sync/sync_mpi.cpp @@ -33,7 +33,7 @@ void Finalize(void) { MPI::Finalize(); } -void AllReduce_(void *sendrecvbuf, int count, const MPI::Datatype &dtype, ReduceOp op) { +void AllReduce_(void *sendrecvbuf, size_t count, const MPI::Datatype &dtype, ReduceOp op) { switch(op) { case kBitwiseOR: MPI::COMM_WORLD.Allreduce(MPI_IN_PLACE, sendrecvbuf, count, dtype, MPI::BOR); return; case kSum: MPI::COMM_WORLD.Allreduce(MPI_IN_PLACE, sendrecvbuf, count, dtype, MPI::SUM); return; @@ -42,12 +42,12 @@ void AllReduce_(void *sendrecvbuf, int count, const MPI::Datatype &dtype, Reduce } template<> -void AllReduce(uint32_t *sendrecvbuf, int count, ReduceOp op) { +void AllReduce(uint32_t *sendrecvbuf, size_t count, ReduceOp op) { AllReduce_(sendrecvbuf, count, MPI::UNSIGNED, op); } template<> -void AllReduce(float *sendrecvbuf, int count, ReduceOp op) { +void AllReduce(float *sendrecvbuf, size_t count, ReduceOp op) { AllReduce_(sendrecvbuf, count, MPI::FLOAT, op); } diff --git a/src/sync/sync_tcp.cpp b/src/sync/sync_tcp.cpp index 330b5318d..6ed24f51d 100644 --- a/src/sync/sync_tcp.cpp +++ b/src/sync/sync_tcp.cpp @@ -483,7 +483,7 @@ inline void ReduceBitOR(const void *src_, void *dst_, int len, const MPI::Dataty } template<> -void AllReduce(uint32_t *sendrecvbuf, int count, ReduceOp op) { +void AllReduce(uint32_t *sendrecvbuf, size_t count, ReduceOp op) { typedef uint32_t DType; switch(op) { case kBitwiseOR: manager.AllReduce(sendrecvbuf, sizeof(DType), count, ReduceBitOR); return; @@ -494,7 +494,7 @@ void AllReduce(uint32_t *sendrecvbuf, int count, ReduceOp op) { } template<> -void AllReduce(float *sendrecvbuf, int count, ReduceOp op) { +void AllReduce(float *sendrecvbuf, size_t count, ReduceOp op) { typedef float DType; switch(op) { case kSum: manager.AllReduce(sendrecvbuf, sizeof(DType), count, ReduceSum); return; diff --git a/src/tree/updater_basemaker-inl.hpp b/src/tree/updater_basemaker-inl.hpp index e5cfd17fa..68bd9ede4 100644 --- a/src/tree/updater_basemaker-inl.hpp +++ b/src/tree/updater_basemaker-inl.hpp @@ -69,7 +69,8 @@ class BaseMaker: public IUpdater { std::vector &findex = *p_findex; findex.clear(); for (size_t i = 0; i < fminmax.size(); i += 2) { - if (this->Type(i / 2) != 0) findex.push_back(i / 2); + const bst_uint fid = static_cast(i / 2); + if (this->Type(fid) != 0) findex.push_back(fid); } unsigned n = static_cast(p * findex.size()); random::Shuffle(findex); diff --git a/src/tree/updater_histmaker-inl.hpp b/src/tree/updater_histmaker-inl.hpp index 06febf47a..61d3008d5 100644 --- a/src/tree/updater_histmaker-inl.hpp +++ b/src/tree/updater_histmaker-inl.hpp @@ -68,7 +68,7 @@ class HistMaker: public BaseMaker { /*! \brief data in different hist unit */ std::vector data; /*! \brief */ - inline HistUnit operator[](bst_uint fid) { + inline HistUnit operator[](size_t fid) { return HistUnit(cut + rptr[fid], &data[0] + rptr[fid], rptr[fid+1] - rptr[fid]); @@ -159,7 +159,7 @@ class HistMaker: public BaseMaker { std::vector *p_fset) { p_fset->resize(tree.param.num_feature); for (size_t i = 0; i < p_fset->size(); ++i) { - (*p_fset)[i] = i; + (*p_fset)[i] = static_cast(i); } } // reset position after split, this is not a must, depending on implementation @@ -187,7 +187,7 @@ class HistMaker: public BaseMaker { c.SetSubstract(node_sum, s); if (c.sum_hess >= param.min_child_weight) { double loss_chg = s.CalcGain(param) + c.CalcGain(param) - root_gain; - if (best->Update(loss_chg, fid, hist.cut[i], false)) { + if (best->Update((float)loss_chg, fid, hist.cut[i], false)) { *left_sum = s; } } @@ -200,7 +200,7 @@ class HistMaker: public BaseMaker { c.SetSubstract(node_sum, s); if (c.sum_hess >= param.min_child_weight) { double loss_chg = s.CalcGain(param) + c.CalcGain(param) - root_gain; - if (best->Update(loss_chg, fid, hist.cut[i-1], true)) { + if (best->Update((float)loss_chg, fid, hist.cut[i-1], true)) { *left_sum = c; } } @@ -258,7 +258,7 @@ class HistMaker: public BaseMaker { } inline void SetStats(RegTree *p_tree, int nid, const TStats &node_sum) { - p_tree->stat(nid).base_weight = node_sum.CalcWeight(param); + p_tree->stat(nid).base_weight = static_cast(node_sum.CalcWeight(param)); p_tree->stat(nid).sum_hess = static_cast(node_sum.sum_hess); node_sum.SetLeafVec(param, p_tree->leafvec(nid)); } @@ -419,17 +419,17 @@ class CQHistMaker: public HistMaker { bst_float last = cpt + fabs(cpt) + rt_eps; this->wspace.cut.push_back(last); } - this->wspace.rptr.push_back(this->wspace.cut.size()); + this->wspace.rptr.push_back(static_cast(this->wspace.cut.size())); } else { utils::Assert(offset == -2, "BUG in mark"); bst_float cpt = feat_helper.MaxValue(fset[i]); this->wspace.cut.push_back(cpt + fabs(cpt) + rt_eps); - this->wspace.rptr.push_back(this->wspace.cut.size()); + this->wspace.rptr.push_back(static_cast(this->wspace.cut.size())); } } // reserve last value for global statistics this->wspace.cut.push_back(0.0f); - this->wspace.rptr.push_back(this->wspace.cut.size()); + this->wspace.rptr.push_back(static_cast(this->wspace.cut.size())); } utils::Assert(this->wspace.rptr.size() == (fset.size() + 1) * this->qexpand.size() + 1, @@ -493,7 +493,7 @@ class CQHistMaker: public HistMaker { } else { for (size_t i = 0; i < this->qexpand.size(); ++i) { const unsigned nid = this->qexpand[i]; - sbuilder[nid].sum_total = nstats[nid].sum_hess; + sbuilder[nid].sum_total = static_cast(nstats[nid].sum_hess); } } // if only one value, no need to do second pass diff --git a/src/utils/io.h b/src/utils/io.h index 97aaa94b2..dff691ee0 100644 --- a/src/utils/io.h +++ b/src/utils/io.h @@ -188,7 +188,7 @@ class FileStream : public ISeekStream { std::fwrite(ptr, size, 1, fp); } virtual void Seek(size_t pos) { - std::fseek(fp, pos, SEEK_SET); + std::fseek(fp, static_cast(pos), SEEK_SET); } virtual size_t Tell(void) { return std::ftell(fp); diff --git a/src/utils/quantile.h b/src/utils/quantile.h index 8d49afc98..32495fb3b 100644 --- a/src/utils/quantile.h +++ b/src/utils/quantile.h @@ -186,7 +186,7 @@ struct WQSummary { * \param maxsize size we can afford in the pruned sketch */ - inline void SetPrune(const WQSummary &src, RType maxsize) { + inline void SetPrune(const WQSummary &src, size_t maxsize) { if (src.size <= maxsize) { this->CopyFrom(src); return; } @@ -290,7 +290,7 @@ struct WXQSummary : public WQSummary { return e.rmin_next() > e.rmax_prev() + chunk; } // set prune - inline void SetPrune(const WQSummary &src, RType maxsize) { + inline void SetPrune(const WQSummary &src, size_t maxsize) { if (src.size <= maxsize) { this->CopyFrom(src); return; } @@ -435,7 +435,7 @@ struct GKSummary { * \param src source summary * \param maxsize size we can afford in the pruned sketch */ - inline void SetPrune(const GKSummary &src, RType maxsize) { + inline void SetPrune(const GKSummary &src, size_t maxsize) { if (src.size <= maxsize) { this->CopyFrom(src); return; } @@ -597,12 +597,14 @@ class QuantileSketchTemplate { inline void Init(size_t maxn, double eps) { nlevel = 1; while (true) { - limit_size = ceil(nlevel / eps) + 1; - if ((1 << nlevel) * limit_size >= maxn) break; + limit_size = static_cast(ceil(nlevel / eps)) + 1; + size_t n = (1UL << nlevel); + if (n * limit_size >= maxn) break; ++nlevel; } // check invariant - utils::Assert((1 << nlevel) * limit_size >= maxn, "invalid init parameter"); + size_t n = (1UL << nlevel); + utils::Assert(n * limit_size >= maxn, "invalid init parameter"); utils::Assert(nlevel <= limit_size * eps, "invalid init parameter"); // lazy reserve the space, if there is only one value, no need to allocate space inqueue.queue.resize(1);