Port R compatibility patches from 1.0.0 release branch (#5577)
* Don't use memset to set struct when compiling for R * Support 32-bit Solaris target for R package
This commit is contained in:
parent
f27b6f9ba6
commit
e4f5b6c84f
@ -7,8 +7,8 @@ require(vcd, quietly = TRUE)
|
|||||||
|
|
||||||
float_tolerance = 5e-6
|
float_tolerance = 5e-6
|
||||||
|
|
||||||
# disable some tests for Win32
|
# disable some tests for 32-bit environment
|
||||||
win32_flag = .Platform$OS.type == "windows" && .Machine$sizeof.pointer != 8
|
flag_32bit = .Machine$sizeof.pointer != 8
|
||||||
|
|
||||||
set.seed(1982)
|
set.seed(1982)
|
||||||
data(Arthritis)
|
data(Arthritis)
|
||||||
@ -44,7 +44,7 @@ mbst.GLM <- xgboost(data = as.matrix(iris[, -5]), label = mlabel, verbose = 0,
|
|||||||
|
|
||||||
|
|
||||||
test_that("xgb.dump works", {
|
test_that("xgb.dump works", {
|
||||||
if (!win32_flag)
|
if (!flag_32bit)
|
||||||
expect_length(xgb.dump(bst.Tree), 200)
|
expect_length(xgb.dump(bst.Tree), 200)
|
||||||
dump_file = file.path(tempdir(), 'xgb.model.dump')
|
dump_file = file.path(tempdir(), 'xgb.model.dump')
|
||||||
expect_true(xgb.dump(bst.Tree, dump_file, with_stats = T))
|
expect_true(xgb.dump(bst.Tree, dump_file, with_stats = T))
|
||||||
@ -54,7 +54,7 @@ test_that("xgb.dump works", {
|
|||||||
# JSON format
|
# JSON format
|
||||||
dmp <- xgb.dump(bst.Tree, dump_format = "json")
|
dmp <- xgb.dump(bst.Tree, dump_format = "json")
|
||||||
expect_length(dmp, 1)
|
expect_length(dmp, 1)
|
||||||
if (!win32_flag)
|
if (!flag_32bit)
|
||||||
expect_length(grep('nodeid', strsplit(dmp, '\n')[[1]]), 188)
|
expect_length(grep('nodeid', strsplit(dmp, '\n')[[1]]), 188)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ test_that("xgb.model.dt.tree works with and without feature names", {
|
|||||||
names.dt.trees <- c("Tree", "Node", "ID", "Feature", "Split", "Yes", "No", "Missing", "Quality", "Cover")
|
names.dt.trees <- c("Tree", "Node", "ID", "Feature", "Split", "Yes", "No", "Missing", "Quality", "Cover")
|
||||||
dt.tree <- xgb.model.dt.tree(feature_names = feature.names, model = bst.Tree)
|
dt.tree <- xgb.model.dt.tree(feature_names = feature.names, model = bst.Tree)
|
||||||
expect_equal(names.dt.trees, names(dt.tree))
|
expect_equal(names.dt.trees, names(dt.tree))
|
||||||
if (!win32_flag)
|
if (!flag_32bit)
|
||||||
expect_equal(dim(dt.tree), c(188, 10))
|
expect_equal(dim(dt.tree), c(188, 10))
|
||||||
expect_output(str(dt.tree), 'Feature.*\\"Age\\"')
|
expect_output(str(dt.tree), 'Feature.*\\"Age\\"')
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ test_that("xgb.model.dt.tree throws error for gblinear", {
|
|||||||
|
|
||||||
test_that("xgb.importance works with and without feature names", {
|
test_that("xgb.importance works with and without feature names", {
|
||||||
importance.Tree <- xgb.importance(feature_names = feature.names, model = bst.Tree)
|
importance.Tree <- xgb.importance(feature_names = feature.names, model = bst.Tree)
|
||||||
if (!win32_flag)
|
if (!flag_32bit)
|
||||||
expect_equal(dim(importance.Tree), c(7, 4))
|
expect_equal(dim(importance.Tree), c(7, 4))
|
||||||
expect_equal(colnames(importance.Tree), c("Feature", "Gain", "Cover", "Frequency"))
|
expect_equal(colnames(importance.Tree), c("Feature", "Gain", "Cover", "Frequency"))
|
||||||
expect_output(str(importance.Tree), 'Feature.*\\"Age\\"')
|
expect_output(str(importance.Tree), 'Feature.*\\"Age\\"')
|
||||||
|
|||||||
@ -831,7 +831,11 @@ void GHistIndexBlockMatrix::Init(const GHistIndexMatrix& gmat,
|
|||||||
* \brief fill a histogram by zeros in range [begin, end)
|
* \brief fill a histogram by zeros in range [begin, end)
|
||||||
*/
|
*/
|
||||||
void InitilizeHistByZeroes(GHistRow hist, size_t begin, size_t end) {
|
void InitilizeHistByZeroes(GHistRow hist, size_t begin, size_t end) {
|
||||||
|
#if defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1
|
||||||
|
std::fill(hist.begin() + begin, hist.begin() + end, tree::GradStats());
|
||||||
|
#else // defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1
|
||||||
memset(hist.data() + begin, '\0', (end-begin)*sizeof(tree::GradStats));
|
memset(hist.data() + begin, '\0', (end-begin)*sizeof(tree::GradStats));
|
||||||
|
#endif // defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@ -117,14 +117,16 @@ std::string LoadSequentialFile(std::string fname) {
|
|||||||
size_t f_size_bytes = fs.st_size;
|
size_t f_size_bytes = fs.st_size;
|
||||||
buffer.resize(f_size_bytes + 1);
|
buffer.resize(f_size_bytes + 1);
|
||||||
int32_t fd = open(fname.c_str(), O_RDONLY);
|
int32_t fd = open(fname.c_str(), O_RDONLY);
|
||||||
|
#if defined(__linux__)
|
||||||
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
|
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
|
||||||
|
#endif // defined(__linux__)
|
||||||
ssize_t bytes_read = read(fd, &buffer[0], f_size_bytes);
|
ssize_t bytes_read = read(fd, &buffer[0], f_size_bytes);
|
||||||
if (bytes_read < 0) {
|
if (bytes_read < 0) {
|
||||||
close(fd);
|
close(fd);
|
||||||
ReadErr();
|
ReadErr();
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
#else
|
#else // defined(__unix__)
|
||||||
FILE *f = fopen(fname.c_str(), "r");
|
FILE *f = fopen(fname.c_str(), "r");
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|||||||
@ -20,11 +20,11 @@
|
|||||||
#define OBSERVER_PRINT LOG(INFO)
|
#define OBSERVER_PRINT LOG(INFO)
|
||||||
#define OBSERVER_ENDL ""
|
#define OBSERVER_ENDL ""
|
||||||
#define OBSERVER_NEWLINE ""
|
#define OBSERVER_NEWLINE ""
|
||||||
#else
|
#else // defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1
|
||||||
#define OBSERVER_PRINT std::cout << std::setprecision(17)
|
#define OBSERVER_PRINT std::cout << std::setprecision(17)
|
||||||
#define OBSERVER_ENDL std::endl
|
#define OBSERVER_ENDL std::endl
|
||||||
#define OBSERVER_NEWLINE "\n"
|
#define OBSERVER_NEWLINE "\n"
|
||||||
#endif // defined(XGBOOST_STRICT_R_MODE)
|
#endif // defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1
|
||||||
|
|
||||||
namespace xgboost {
|
namespace xgboost {
|
||||||
/*\brief An observer for logging internal data structures.
|
/*\brief An observer for logging internal data structures.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user