fix nan
This commit is contained in:
parent
841d076f20
commit
39cb9d2c5e
@ -28,6 +28,11 @@ extern "C" {
|
|||||||
void (*Check)(int exp, const char *fmt, ...) = XGBoostCheck_R;
|
void (*Check)(int exp, const char *fmt, ...) = XGBoostCheck_R;
|
||||||
void (*Error)(const char *fmt, ...) = error;
|
void (*Error)(const char *fmt, ...) = error;
|
||||||
}
|
}
|
||||||
|
namespace wrapper {
|
||||||
|
bool CheckNAN(float v) {
|
||||||
|
return ISNAN(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|
||||||
namespace random {
|
namespace random {
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <cmath>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
// include all std functions
|
// include all std functions
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -96,19 +97,19 @@ class Booster: public learner::BoostLearner {
|
|||||||
private:
|
private:
|
||||||
bool init_model;
|
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 wrapper
|
||||||
} // namespace xgboost
|
} // namespace xgboost
|
||||||
|
|
||||||
using namespace xgboost::wrapper;
|
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"{
|
extern "C"{
|
||||||
void* XGDMatrixCreateFromFile(const char *fname, int silent) {
|
void* XGDMatrixCreateFromFile(const char *fname, int silent) {
|
||||||
return LoadDataMatrix(fname, silent != 0, false);
|
return LoadDataMatrix(fname, silent != 0, false);
|
||||||
@ -162,7 +163,7 @@ extern "C"{
|
|||||||
bst_ulong nrow,
|
bst_ulong nrow,
|
||||||
bst_ulong ncol,
|
bst_ulong ncol,
|
||||||
float missing) {
|
float missing) {
|
||||||
bool nan_missing = checknan(missing);
|
bool nan_missing = CheckNAN(missing);
|
||||||
DMatrixSimple *p_mat = new DMatrixSimple();
|
DMatrixSimple *p_mat = new DMatrixSimple();
|
||||||
DMatrixSimple &mat = *p_mat;
|
DMatrixSimple &mat = *p_mat;
|
||||||
mat.info.info.num_row = nrow;
|
mat.info.info.num_row = nrow;
|
||||||
@ -170,7 +171,7 @@ extern "C"{
|
|||||||
for (bst_ulong i = 0; i < nrow; ++i, data += ncol) {
|
for (bst_ulong i = 0; i < nrow; ++i, data += ncol) {
|
||||||
bst_ulong nelem = 0;
|
bst_ulong nelem = 0;
|
||||||
for (bst_ulong j = 0; j < ncol; ++j) {
|
for (bst_ulong j = 0; j < ncol; ++j) {
|
||||||
if (checknan(data[j])) {
|
if (CheckNAN(data[j])) {
|
||||||
utils::Check(nan_missing,
|
utils::Check(nan_missing,
|
||||||
"There are NAN in the matrix, however, you did not set missing=NAN");
|
"There are NAN in the matrix, however, you did not set missing=NAN");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user