From 18277086d9feeb477d66d68f664785289b1f7a8b Mon Sep 17 00:00:00 2001 From: Tianqi Chen Date: Sun, 19 Apr 2015 00:20:52 -0700 Subject: [PATCH] fix windows warnings --- src/io/libsvm_parser.h | 7 ++++--- src/io/page_fmatrix-inl.hpp | 8 ++++---- src/io/simple_fmatrix-inl.hpp | 7 ++++--- src/learner/evaluation-inl.hpp | 2 +- wrapper/xgboost_wrapper.cpp | 6 +++--- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/io/libsvm_parser.h b/src/io/libsvm_parser.h index 8041892d7..6579d80e3 100644 --- a/src/io/libsvm_parser.h +++ b/src/io/libsvm_parser.h @@ -6,10 +6,11 @@ */ #ifndef XGBOOST_IO_LIBSVM_PARSER_H_ #define XGBOOST_IO_LIBSVM_PARSER_H_ - +#define NOMINMAX #include #include #include +#include #include "../utils/omp.h" #include "../utils/utils.h" #include "../sync/sync.h" @@ -120,12 +121,12 @@ class LibSVMPageFactory { while (isdigit(*p) && p != end) ++p; if (*p == ':') { out->data.push_back(SparseBatch::Entry(atol(head), - atof(p + 1))); + static_cast(atof(p + 1)))); } else { if (out->label.size() != 0) { out->offset.push_back(out->data.size()); } - out->label.push_back(atof(head)); + out->label.push_back(static_cast(atof(head))); } while (!isspace(*p) && p != end) ++p; } diff --git a/src/io/page_fmatrix-inl.hpp b/src/io/page_fmatrix-inl.hpp index 8bcea2bd4..0883998f4 100644 --- a/src/io/page_fmatrix-inl.hpp +++ b/src/io/page_fmatrix-inl.hpp @@ -26,7 +26,7 @@ class ThreadColPageIterator: public utils::IIterator { for (size_t i = 0; i < col_data_.size(); ++i) { col_data_[i] = SparseBatch::Inst (BeginPtr(page_->data) + page_->offset[i], - page_->offset[i + 1] - page_->offset[i]); + static_cast(page_->offset[i + 1] - page_->offset[i])); } out_.col_data = BeginPtr(col_data_); out_.size = col_data_.size(); @@ -110,7 +110,7 @@ class FMatrixPage : public IFMatrix { size_t ncol = this->NumCol(); col_index_.resize(0); for (size_t i = 0; i < ncol; ++i) { - col_index_.push_back(i); + col_index_.push_back(static_cast(i)); } col_iter_.SetIndexSet(col_index_, false); col_iter_.BeforeFirst(); @@ -229,7 +229,7 @@ class FMatrixPage : public IFMatrix { #pragma omp parallel for schedule(static) for (bst_omp_uint i = 0; i < ndata; ++i) { int tid = omp_get_thread_num(); - for (bst_uint j = prow.offset[i]; j < prow.offset[i+1]; ++j) { + for (size_t j = prow.offset[i]; j < prow.offset[i+1]; ++j) { const SparseBatch::Entry &e = prow.data[j]; if (enabled[e.index]) { builder.AddBudget(e.index, tid); @@ -240,7 +240,7 @@ class FMatrixPage : public IFMatrix { #pragma omp parallel for schedule(static) for (bst_omp_uint i = 0; i < ndata; ++i) { int tid = omp_get_thread_num(); - for (bst_uint j = prow.offset[i]; j < prow.offset[i+1]; ++j) { + for (size_t j = prow.offset[i]; j < prow.offset[i+1]; ++j) { const SparseBatch::Entry &e = prow.data[j]; builder.Push(e.index, SparseBatch::Entry(ridx[i], e.fvalue), diff --git a/src/io/simple_fmatrix-inl.hpp b/src/io/simple_fmatrix-inl.hpp index 3ba6f2801..acf85297f 100644 --- a/src/io/simple_fmatrix-inl.hpp +++ b/src/io/simple_fmatrix-inl.hpp @@ -165,7 +165,8 @@ class FMatrixS : public IFMatrix { while (iter_->Next()) { const RowBatch &batch = iter_->Value(); bmap.resize(bmap.size() + batch.size, true); - for (size_t i = 0; i < batch.size; ++i) { + long batch_size = static_cast(batch.size); + for (long i = 0; i < batch_size; ++i) { bst_uint ridx = static_cast(batch.base_rowid + i); if (pkeep == 1.0f || random::SampleBinary(pkeep)) { buffered_rowset_.push_back(ridx); @@ -174,7 +175,7 @@ class FMatrixS : public IFMatrix { } } #pragma omp parallel for schedule(static) - for (size_t i = 0; i < batch.size; ++i) { + for (long i = 0; i < batch_size; ++i) { int tid = omp_get_thread_num(); bst_uint ridx = static_cast(batch.base_rowid + i); if (bmap[ridx]) { @@ -193,7 +194,7 @@ class FMatrixS : public IFMatrix { while (iter_->Next()) { const RowBatch &batch = iter_->Value(); #pragma omp parallel for schedule(static) - for (size_t i = 0; i < batch.size; ++i) { + for (long i = 0; i < static_cast(batch.size); ++i) { int tid = omp_get_thread_num(); bst_uint ridx = static_cast(batch.base_rowid + i); if (bmap[ridx]) { diff --git a/src/learner/evaluation-inl.hpp b/src/learner/evaluation-inl.hpp index 02d86f606..8798ff99b 100644 --- a/src/learner/evaluation-inl.hpp +++ b/src/learner/evaluation-inl.hpp @@ -130,7 +130,7 @@ struct EvalMClassBase : public IEvaluator { const float wt = info.GetWeight(i); int label = static_cast(info.labels[i]); if (label >= 0 && label < static_cast(nclass)) { - sum += Derived::EvalRow(info.labels[i], + sum += Derived::EvalRow(label, BeginPtr(preds) + i * nclass, nclass) * wt; wsum += wt; diff --git a/wrapper/xgboost_wrapper.cpp b/wrapper/xgboost_wrapper.cpp index dec266ff6..2b28469c7 100644 --- a/wrapper/xgboost_wrapper.cpp +++ b/wrapper/xgboost_wrapper.cpp @@ -149,9 +149,9 @@ extern "C"{ DMatrixSimple &mat = *p_mat; utils::ParallelGroupBuilder builder(&mat.row_ptr_, &mat.row_data_); builder.InitBudget(0, nthread); - bst_ulong ncol = nindptr - 1; + long ncol = static_cast(nindptr - 1); #pragma omp parallel for schedule(static) - for (bst_ulong i = 0; i < ncol; ++i) { + for (long i = 0; i < ncol; ++i) { int tid = omp_get_thread_num(); for (unsigned j = col_ptr[i]; j < col_ptr[i+1]; ++j) { builder.AddBudget(indices[j], tid); @@ -159,7 +159,7 @@ extern "C"{ } builder.InitStorage(); #pragma omp parallel for schedule(static) - for (bst_ulong i = 0; i < ncol; ++i) { + for (long i = 0; i < ncol; ++i) { int tid = omp_get_thread_num(); for (unsigned j = col_ptr[i]; j < col_ptr[i+1]; ++j) { builder.Push(indices[j],