diff --git a/R-package/tests/testthat/test_helpers.R b/R-package/tests/testthat/test_helpers.R index 09d1e73df..5c14d5318 100644 --- a/R-package/tests/testthat/test_helpers.R +++ b/R-package/tests/testthat/test_helpers.R @@ -7,8 +7,8 @@ require(vcd, quietly = TRUE) float_tolerance = 5e-6 -# disable some tests for Win32 -win32_flag = .Platform$OS.type == "windows" && .Machine$sizeof.pointer != 8 +# disable some tests for 32-bit environment +flag_32bit = .Machine$sizeof.pointer != 8 set.seed(1982) data(Arthritis) @@ -44,7 +44,7 @@ mbst.GLM <- xgboost(data = as.matrix(iris[, -5]), label = mlabel, verbose = 0, test_that("xgb.dump works", { - if (!win32_flag) + if (!flag_32bit) expect_length(xgb.dump(bst.Tree), 200) dump_file = file.path(tempdir(), 'xgb.model.dump') expect_true(xgb.dump(bst.Tree, dump_file, with_stats = T)) @@ -54,7 +54,7 @@ test_that("xgb.dump works", { # JSON format dmp <- xgb.dump(bst.Tree, dump_format = "json") expect_length(dmp, 1) - if (!win32_flag) + if (!flag_32bit) 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") dt.tree <- xgb.model.dt.tree(feature_names = feature.names, model = bst.Tree) expect_equal(names.dt.trees, names(dt.tree)) - if (!win32_flag) + if (!flag_32bit) expect_equal(dim(dt.tree), c(188, 10)) 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", { 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(colnames(importance.Tree), c("Feature", "Gain", "Cover", "Frequency")) expect_output(str(importance.Tree), 'Feature.*\\"Age\\"') diff --git a/src/common/io.cc b/src/common/io.cc index 7a19acd9b..a8df1640f 100644 --- a/src/common/io.cc +++ b/src/common/io.cc @@ -117,14 +117,16 @@ std::string LoadSequentialFile(std::string fname) { size_t f_size_bytes = fs.st_size; buffer.resize(f_size_bytes + 1); int32_t fd = open(fname.c_str(), O_RDONLY); +#if defined(__linux__) posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); +#endif // defined(__linux__) ssize_t bytes_read = read(fd, &buffer[0], f_size_bytes); if (bytes_read < 0) { close(fd); ReadErr(); } close(fd); -#else +#else // defined(__unix__) FILE *f = fopen(fname.c_str(), "r"); if (f == NULL) { std::string msg;