From 9fd8612700c235635a949d5f403add33991bf5da Mon Sep 17 00:00:00 2001 From: tqchen Date: Tue, 3 Mar 2015 12:37:29 -0800 Subject: [PATCH] fix cranchecks --- src/io/io.cpp | 24 ++++++++++++++---------- wrapper/xgboost_wrapper.cpp | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/io/io.cpp b/src/io/io.cpp index 0072618c6..eb7f9fbde 100644 --- a/src/io/io.cpp +++ b/src/io/io.cpp @@ -6,9 +6,10 @@ #include "../utils/io.h" #include "../utils/utils.h" #include "simple_dmatrix-inl.hpp" +#ifndef XGBOOST_STRICT_CXX98_ #include "page_dmatrix-inl.hpp" #include "page_fmatrix-inl.hpp" - +#endif // implements data loads using dmatrix simple for now namespace xgboost { @@ -19,14 +20,6 @@ DataMatrix* LoadDataMatrix(const char *fname, bool silent, bool savebuffer) { dmat->LoadText(fname, silent); return dmat; } - std::string tmp_fname; - const char *fname_ext = NULL; - if (strchr(fname, ';') != NULL) { - tmp_fname = fname; - char *ptr = strchr(&tmp_fname[0], ';'); - ptr[0] = '\0'; fname = &tmp_fname[0]; - fname_ext = ptr + 1; - } int magic; utils::FileStream fs(utils::FopenCheck(fname, "rb")); utils::Check(fs.Read(&magic, sizeof(magic)) != 0, "invalid input file format"); @@ -38,6 +31,15 @@ DataMatrix* LoadDataMatrix(const char *fname, bool silent, bool savebuffer) { fs.Close(); return dmat; } +#ifndef XGBOOST_STRICT_CXX98_ + std::string tmp_fname; + const char *fname_ext = NULL; + if (strchr(fname, ';') != NULL) { + tmp_fname = fname; + char *ptr = strchr(&tmp_fname[0], ';'); + ptr[0] = '\0'; fname = &tmp_fname[0]; + fname_ext = ptr + 1; + } if (magic == DMatrixPage::kMagic) { if (fname_ext == NULL) { DMatrixPage *dmat = new DMatrixPage(); @@ -58,14 +60,15 @@ DataMatrix* LoadDataMatrix(const char *fname, bool silent, bool savebuffer) { dmat->Load(fs, silent, fname); return dmat; } + #endif fs.Close(); - DMatrixSimple *dmat = new DMatrixSimple(); dmat->CacheLoad(fname, silent, savebuffer); return dmat; } void SaveDataMatrix(const DataMatrix &dmat, const char *fname, bool silent) { +#ifndef XGBOOST_STRICT_CXX98_ if (!strcmp(fname + strlen(fname) - 5, ".page")) { DMatrixPage::Save(fname, dmat, silent); return; @@ -74,6 +77,7 @@ void SaveDataMatrix(const DataMatrix &dmat, const char *fname, bool silent) { DMatrixColPage::Save(fname, dmat, silent); return; } +#endif if (dmat.magic == DMatrixSimple::kMagic) { const DMatrixSimple *p_dmat = static_cast(&dmat); p_dmat->SaveBinary(fname, silent); diff --git a/wrapper/xgboost_wrapper.cpp b/wrapper/xgboost_wrapper.cpp index 6c8f250c1..659ee05ed 100644 --- a/wrapper/xgboost_wrapper.cpp +++ b/wrapper/xgboost_wrapper.cpp @@ -8,9 +8,11 @@ #include // include all std functions using namespace std; + #ifdef _MSC_VER #define isnan(x) (_isnan(x) != 0) #endif + #include "./xgboost_wrapper.h" #include "../src/data.h" #include "../src/learner/learner-inl.hpp" @@ -99,6 +101,14 @@ class Booster: public learner::BoostLearner { using namespace xgboost::wrapper; +inline bool checknan(float v) { +#if defined(__SUN__) || defined(__sum__) || defined(__SunOS) + return !(v==v); +#else + return isnan(v); +#endif +} + extern "C"{ void* XGDMatrixCreateFromFile(const char *fname, int silent) { return LoadDataMatrix(fname, silent != 0, false); @@ -152,7 +162,7 @@ extern "C"{ bst_ulong nrow, bst_ulong ncol, float missing) { - bool nan_missing = isnan(missing); + bool nan_missing = checknan(missing); DMatrixSimple *p_mat = new DMatrixSimple(); DMatrixSimple &mat = *p_mat; mat.info.info.num_row = nrow; @@ -160,7 +170,7 @@ extern "C"{ for (bst_ulong i = 0; i < nrow; ++i, data += ncol) { bst_ulong nelem = 0; for (bst_ulong j = 0; j < ncol; ++j) { - if (isnan(data[j])) { + if (checknan(data[j])) { utils::Check(nan_missing, "There are NAN in the matrix, however, you did not set missing=NAN"); } else {