remove warning from MSVC need another round of check

This commit is contained in:
Tianqi Chen 2014-11-23 20:52:13 -08:00
parent b55fe80350
commit 2e444f8338
12 changed files with 32 additions and 28 deletions

View File

@ -324,7 +324,7 @@ class GBTree : public IGradBooster {
unsigned ntree_limit) { unsigned ntree_limit) {
// number of valid trees // number of valid trees
if (ntree_limit == 0 || ntree_limit > trees.size()) { if (ntree_limit == 0 || ntree_limit > trees.size()) {
ntree_limit = trees.size(); ntree_limit = static_cast<unsigned>(trees.size());
} }
std::vector<float> &preds = *out_preds; std::vector<float> &preds = *out_preds;
preds.resize(info.num_row * ntree_limit); preds.resize(info.num_row * ntree_limit);

View File

@ -1,5 +1,6 @@
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE
#define NOMINMAX
#include <string> #include <string>
#include "./io.h" #include "./io.h"
#include "../utils/io.h" #include "../utils/io.h"

View File

@ -165,7 +165,7 @@ class ThreadRowPageIterator: public utils::IIterator<RowBatch> {
// loader factory for page // loader factory for page
struct Factory { struct Factory {
public: public:
long file_begin_; size_t file_begin_;
utils::FileStream fi; utils::FileStream fi;
Factory(void) {} Factory(void) {}
inline void SetFile(const utils::FileStream &fi) { inline void SetFile(const utils::FileStream &fi) {

View File

@ -138,8 +138,8 @@ class CSCMatrixManager {
fi_->Seek(col_ptr_[cidx] * sizeof(ColBatch::Entry) + begin_data_); fi_->Seek(col_ptr_[cidx] * sizeof(ColBatch::Entry) + begin_data_);
utils::Check(fi_->Read(p_data, sizeof(ColBatch::Entry) * len) != 0, utils::Check(fi_->Read(p_data, sizeof(ColBatch::Entry) * len) != 0,
"invalid column buffer format"); "invalid column buffer format");
p_page->col_data.push_back(ColBatch::Inst(p_data, len)); p_page->col_data.push_back(ColBatch::Inst(p_data, static_cast<bst_uint>(len)));
p_page->col_index.push_back(cidx); p_page->col_index.push_back(static_cast<bst_uint>(cidx));
return true; return true;
} }
// the following are in memory auxiliary data structure // the following are in memory auxiliary data structure

View File

@ -187,7 +187,7 @@ class BoostLearner {
* \param p_train pointer to the matrix used by training * \param p_train pointer to the matrix used by training
*/ */
inline void CheckInit(DMatrix *p_train) { inline void CheckInit(DMatrix *p_train) {
int ncol = p_train->info.info.num_col; int ncol = static_cast<int>(p_train->info.info.num_col);
std::vector<bool> enabled(ncol, true); std::vector<bool> enabled(ncol, true);
if (part_load_col != 0) { if (part_load_col != 0) {

View File

@ -49,7 +49,7 @@ void Finalize(void);
* \param op reduction function * \param op reduction function
*/ */
template<typename DType> template<typename DType>
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 * \brief broadcast an std::string to all others from root

View File

@ -33,7 +33,7 @@ void Finalize(void) {
MPI::Finalize(); 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) { switch(op) {
case kBitwiseOR: MPI::COMM_WORLD.Allreduce(MPI_IN_PLACE, sendrecvbuf, count, dtype, MPI::BOR); return; 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; 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<> template<>
void AllReduce<uint32_t>(uint32_t *sendrecvbuf, int count, ReduceOp op) { void AllReduce<uint32_t>(uint32_t *sendrecvbuf, size_t count, ReduceOp op) {
AllReduce_(sendrecvbuf, count, MPI::UNSIGNED, op); AllReduce_(sendrecvbuf, count, MPI::UNSIGNED, op);
} }
template<> template<>
void AllReduce<float>(float *sendrecvbuf, int count, ReduceOp op) { void AllReduce<float>(float *sendrecvbuf, size_t count, ReduceOp op) {
AllReduce_(sendrecvbuf, count, MPI::FLOAT, op); AllReduce_(sendrecvbuf, count, MPI::FLOAT, op);
} }

View File

@ -483,7 +483,7 @@ inline void ReduceBitOR(const void *src_, void *dst_, int len, const MPI::Dataty
} }
template<> template<>
void AllReduce<uint32_t>(uint32_t *sendrecvbuf, int count, ReduceOp op) { void AllReduce<uint32_t>(uint32_t *sendrecvbuf, size_t count, ReduceOp op) {
typedef uint32_t DType; typedef uint32_t DType;
switch(op) { switch(op) {
case kBitwiseOR: manager.AllReduce(sendrecvbuf, sizeof(DType), count, ReduceBitOR<DType>); return; case kBitwiseOR: manager.AllReduce(sendrecvbuf, sizeof(DType), count, ReduceBitOR<DType>); return;
@ -494,7 +494,7 @@ void AllReduce<uint32_t>(uint32_t *sendrecvbuf, int count, ReduceOp op) {
} }
template<> template<>
void AllReduce<float>(float *sendrecvbuf, int count, ReduceOp op) { void AllReduce<float>(float *sendrecvbuf, size_t count, ReduceOp op) {
typedef float DType; typedef float DType;
switch(op) { switch(op) {
case kSum: manager.AllReduce(sendrecvbuf, sizeof(DType), count, ReduceSum<DType>); return; case kSum: manager.AllReduce(sendrecvbuf, sizeof(DType), count, ReduceSum<DType>); return;

View File

@ -69,7 +69,8 @@ class BaseMaker: public IUpdater {
std::vector<bst_uint> &findex = *p_findex; std::vector<bst_uint> &findex = *p_findex;
findex.clear(); findex.clear();
for (size_t i = 0; i < fminmax.size(); i += 2) { 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<bst_uint>(i / 2);
if (this->Type(fid) != 0) findex.push_back(fid);
} }
unsigned n = static_cast<unsigned>(p * findex.size()); unsigned n = static_cast<unsigned>(p * findex.size());
random::Shuffle(findex); random::Shuffle(findex);

View File

@ -68,7 +68,7 @@ class HistMaker: public BaseMaker {
/*! \brief data in different hist unit */ /*! \brief data in different hist unit */
std::vector<TStats> data; std::vector<TStats> data;
/*! \brief */ /*! \brief */
inline HistUnit operator[](bst_uint fid) { inline HistUnit operator[](size_t fid) {
return HistUnit(cut + rptr[fid], return HistUnit(cut + rptr[fid],
&data[0] + rptr[fid], &data[0] + rptr[fid],
rptr[fid+1] - rptr[fid]); rptr[fid+1] - rptr[fid]);
@ -159,7 +159,7 @@ class HistMaker: public BaseMaker {
std::vector<bst_uint> *p_fset) { std::vector<bst_uint> *p_fset) {
p_fset->resize(tree.param.num_feature); p_fset->resize(tree.param.num_feature);
for (size_t i = 0; i < p_fset->size(); ++i) { for (size_t i = 0; i < p_fset->size(); ++i) {
(*p_fset)[i] = i; (*p_fset)[i] = static_cast<unsigned>(i);
} }
} }
// reset position after split, this is not a must, depending on implementation // 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); c.SetSubstract(node_sum, s);
if (c.sum_hess >= param.min_child_weight) { if (c.sum_hess >= param.min_child_weight) {
double loss_chg = s.CalcGain(param) + c.CalcGain(param) - root_gain; 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; *left_sum = s;
} }
} }
@ -200,7 +200,7 @@ class HistMaker: public BaseMaker {
c.SetSubstract(node_sum, s); c.SetSubstract(node_sum, s);
if (c.sum_hess >= param.min_child_weight) { if (c.sum_hess >= param.min_child_weight) {
double loss_chg = s.CalcGain(param) + c.CalcGain(param) - root_gain; 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; *left_sum = c;
} }
} }
@ -258,7 +258,7 @@ class HistMaker: public BaseMaker {
} }
inline void SetStats(RegTree *p_tree, int nid, const TStats &node_sum) { 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<float>(node_sum.CalcWeight(param));
p_tree->stat(nid).sum_hess = static_cast<float>(node_sum.sum_hess); p_tree->stat(nid).sum_hess = static_cast<float>(node_sum.sum_hess);
node_sum.SetLeafVec(param, p_tree->leafvec(nid)); node_sum.SetLeafVec(param, p_tree->leafvec(nid));
} }
@ -419,17 +419,17 @@ class CQHistMaker: public HistMaker<TStats> {
bst_float last = cpt + fabs(cpt) + rt_eps; bst_float last = cpt + fabs(cpt) + rt_eps;
this->wspace.cut.push_back(last); this->wspace.cut.push_back(last);
} }
this->wspace.rptr.push_back(this->wspace.cut.size()); this->wspace.rptr.push_back(static_cast<unsigned>(this->wspace.cut.size()));
} else { } else {
utils::Assert(offset == -2, "BUG in mark"); utils::Assert(offset == -2, "BUG in mark");
bst_float cpt = feat_helper.MaxValue(fset[i]); bst_float cpt = feat_helper.MaxValue(fset[i]);
this->wspace.cut.push_back(cpt + fabs(cpt) + rt_eps); 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<unsigned>(this->wspace.cut.size()));
} }
} }
// reserve last value for global statistics // reserve last value for global statistics
this->wspace.cut.push_back(0.0f); this->wspace.cut.push_back(0.0f);
this->wspace.rptr.push_back(this->wspace.cut.size()); this->wspace.rptr.push_back(static_cast<unsigned>(this->wspace.cut.size()));
} }
utils::Assert(this->wspace.rptr.size() == utils::Assert(this->wspace.rptr.size() ==
(fset.size() + 1) * this->qexpand.size() + 1, (fset.size() + 1) * this->qexpand.size() + 1,
@ -493,7 +493,7 @@ class CQHistMaker: public HistMaker<TStats> {
} else { } else {
for (size_t i = 0; i < this->qexpand.size(); ++i) { for (size_t i = 0; i < this->qexpand.size(); ++i) {
const unsigned nid = this->qexpand[i]; const unsigned nid = this->qexpand[i];
sbuilder[nid].sum_total = nstats[nid].sum_hess; sbuilder[nid].sum_total = static_cast<bst_float>(nstats[nid].sum_hess);
} }
} }
// if only one value, no need to do second pass // if only one value, no need to do second pass

View File

@ -188,7 +188,7 @@ class FileStream : public ISeekStream {
std::fwrite(ptr, size, 1, fp); std::fwrite(ptr, size, 1, fp);
} }
virtual void Seek(size_t pos) { virtual void Seek(size_t pos) {
std::fseek(fp, pos, SEEK_SET); std::fseek(fp, static_cast<long>(pos), SEEK_SET);
} }
virtual size_t Tell(void) { virtual size_t Tell(void) {
return std::ftell(fp); return std::ftell(fp);

View File

@ -186,7 +186,7 @@ struct WQSummary {
* \param maxsize size we can afford in the pruned sketch * \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) { if (src.size <= maxsize) {
this->CopyFrom(src); return; this->CopyFrom(src); return;
} }
@ -290,7 +290,7 @@ struct WXQSummary : public WQSummary<DType, RType> {
return e.rmin_next() > e.rmax_prev() + chunk; return e.rmin_next() > e.rmax_prev() + chunk;
} }
// set prune // set prune
inline void SetPrune(const WQSummary<DType, RType> &src, RType maxsize) { inline void SetPrune(const WQSummary<DType, RType> &src, size_t maxsize) {
if (src.size <= maxsize) { if (src.size <= maxsize) {
this->CopyFrom(src); return; this->CopyFrom(src); return;
} }
@ -435,7 +435,7 @@ struct GKSummary {
* \param src source summary * \param src source summary
* \param maxsize size we can afford in the pruned sketch * \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) { if (src.size <= maxsize) {
this->CopyFrom(src); return; this->CopyFrom(src); return;
} }
@ -597,12 +597,14 @@ class QuantileSketchTemplate {
inline void Init(size_t maxn, double eps) { inline void Init(size_t maxn, double eps) {
nlevel = 1; nlevel = 1;
while (true) { while (true) {
limit_size = ceil(nlevel / eps) + 1; limit_size = static_cast<size_t>(ceil(nlevel / eps)) + 1;
if ((1 << nlevel) * limit_size >= maxn) break; size_t n = (1UL << nlevel);
if (n * limit_size >= maxn) break;
++nlevel; ++nlevel;
} }
// check invariant // 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"); utils::Assert(nlevel <= limit_size * eps, "invalid init parameter");
// lazy reserve the space, if there is only one value, no need to allocate space // lazy reserve the space, if there is only one value, no need to allocate space
inqueue.queue.resize(1); inqueue.queue.resize(1);