This commit is contained in:
tqchen 2015-03-03 22:33:03 -08:00
parent 841d076f20
commit 39cb9d2c5e
2 changed files with 16 additions and 10 deletions

View File

@ -28,6 +28,11 @@ extern "C" {
void (*Check)(int exp, const char *fmt, ...) = XGBoostCheck_R;
void (*Error)(const char *fmt, ...) = error;
}
namespace wrapper {
bool CheckNAN(float v) {
return ISNAN(v);
}
}
} // namespace utils
namespace random {

View File

@ -5,6 +5,7 @@
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
// include all std functions
using namespace std;
@ -96,19 +97,19 @@ class Booster: public learner::BoostLearner {
private:
bool init_model;
};
#if !defined(XGBOOST_STRICT_CXX98_)
inline bool CheckNAN(float v) {
return isnan(v);
}
#else
// redirect to defs in R
bool CheckNAN(float v);
#endif
} // namespace wrapper
} // namespace xgboost
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);
@ -162,7 +163,7 @@ extern "C"{
bst_ulong nrow,
bst_ulong ncol,
float missing) {
bool nan_missing = checknan(missing);
bool nan_missing = CheckNAN(missing);
DMatrixSimple *p_mat = new DMatrixSimple();
DMatrixSimple &mat = *p_mat;
mat.info.info.num_row = nrow;
@ -170,7 +171,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 (checknan(data[j])) {
if (CheckNAN(data[j])) {
utils::Check(nan_missing,
"There are NAN in the matrix, however, you did not set missing=NAN");
} else {