[R] make all customizations to meet strict standard of cran

This commit is contained in:
tqchen 2016-01-15 16:41:06 -08:00
parent 634db18a0f
commit 1495a43cea
23 changed files with 397 additions and 75 deletions

2
.gitignore vendored
View File

@ -52,8 +52,6 @@ Debug
#.Rbuildignore #.Rbuildignore
R-package.Rproj R-package.Rproj
*.cache* *.cache*
R-package/inst
R-package/src
#java #java
java/xgboost4j/target java/xgboost4j/target
java/xgboost4j/tmp java/xgboost4j/tmp

View File

@ -15,7 +15,12 @@ ifndef RABIT
endif endif
ROOTDIR = $(CURDIR) ROOTDIR = $(CURDIR)
UNAME= $(shell uname)
ifeq ($(OS), Windows_NT)
UNAME="Windows"
else
UNAME=$(shell uname)
endif
include $(config) include $(config)
ifeq ($(USE_OPENMP), 0) ifeq ($(USE_OPENMP), 0)
@ -34,13 +39,8 @@ ifndef CXX
export CXX = $(if $(shell which g++-5),g++-5,g++) export CXX = $(if $(shell which g++-5),g++-5,g++)
endif endif
ifeq ($(OS), Windows_NT)
export CXX = g++ -m64
export CC = gcc -m64
endif
export LDFLAGS= -pthread -lm $(ADD_LDFLAGS) $(DMLC_LDFLAGS) $(PLUGIN_LDFLAGS) export LDFLAGS= -pthread -lm $(ADD_LDFLAGS) $(DMLC_LDFLAGS) $(PLUGIN_LDFLAGS)
export CFLAGS= -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -fPIC -Iinclude $(ADD_CFLAGS) $(PLUGIN_CFLAGS) export CFLAGS= -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude $(ADD_CFLAGS) $(PLUGIN_CFLAGS)
CFLAGS += -I$(DMLC_CORE)/include -I$(RABIT)/include CFLAGS += -I$(DMLC_CORE)/include -I$(RABIT)/include
#java include path #java include path
export JAVAINCFLAGS = -I${JAVA_HOME}/include -I./java export JAVAINCFLAGS = -I${JAVA_HOME}/include -I./java
@ -49,6 +49,13 @@ ifndef LINT_LANG
LINT_LANG= "all" LINT_LANG= "all"
endif endif
ifneq ($(UNAME), Windows)
CFLAGS += -fPIC
XGBOOST_DYLIB = lib/libxgboost.so
else
XGBOOST_DYLIB = lib/libxgboost.dll
endif
ifeq ($(UNAME), Linux) ifeq ($(UNAME), Linux)
LDFLAGS += -lrt LDFLAGS += -lrt
JAVAINCFLAGS += -I${JAVA_HOME}/include/linux JAVAINCFLAGS += -I${JAVA_HOME}/include/linux
@ -68,7 +75,8 @@ endif
# specify tensor path # specify tensor path
.PHONY: clean all lint clean_all doxygen rcpplint Rpack Rbuild Rcheck java .PHONY: clean all lint clean_all doxygen rcpplint Rpack Rbuild Rcheck java
all: lib/libxgboost.a lib/libxgboost.so xgboost
all: lib/libxgboost.a $(XGBOOST_DYLIB) xgboost
$(DMLC_CORE)/libdmlc.a: $(DMLC_CORE)/libdmlc.a:
+ cd $(DMLC_CORE); make libdmlc.a config=$(ROOTDIR)/$(config); cd $(ROOTDIR) + cd $(DMLC_CORE); make libdmlc.a config=$(ROOTDIR)/$(config); cd $(ROOTDIR)
@ -108,7 +116,7 @@ lib/libxgboost.a: $(ALL_DEP)
@mkdir -p $(@D) @mkdir -p $(@D)
ar crv $@ $(filter %.o, $?) ar crv $@ $(filter %.o, $?)
lib/libxgboost.so: $(ALL_DEP) lib/libxgboost.dll lib/libxgboost.so: $(ALL_DEP)
@mkdir -p $(@D) @mkdir -p $(@D)
$(CXX) $(CFLAGS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS) $(CXX) $(CFLAGS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
@ -125,11 +133,11 @@ lint: rcpplint
python2 dmlc-core/scripts/lint.py xgboost ${LINT_LANG} include src plugin python2 dmlc-core/scripts/lint.py xgboost ${LINT_LANG} include src plugin
clean: clean:
$(RM) -rf build build_plugin lib bin *~ */*~ */*/*~ */*/*/*~ amalgamation/*.o xgboost $(RM) -rf build build_plugin lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o xgboost
clean_all: clean clean_all: clean
cd $(DMLC_CORE); make clean; cd - cd $(DMLC_CORE); make clean; cd $(ROODIR)
cd $(RABIT); make clean; cd - cd $(RABIT); make clean; cd $(ROODIR)
doxygen: doxygen:
doxygen doc/Doxyfile doxygen doc/Doxyfile

View File

@ -16,7 +16,7 @@ install.packages('xgboost')
For up-to-date version, please install from github. Windows user will need to install [RTools](http://cran.r-project.org/bin/windows/Rtools/) first. For up-to-date version, please install from github. Windows user will need to install [RTools](http://cran.r-project.org/bin/windows/Rtools/) first.
```r ```r
devtools::install_github('dmlc/xgboost',subdir='R-package') devtools::install_git('git://github.com/dmlc/xgboost',subdir='R-package')
``` ```
Examples Examples

View File

@ -2,9 +2,16 @@
PKGROOT=../../ PKGROOT=../../
ENABLE_STD_THREAD=1 ENABLE_STD_THREAD=1
# _*_ mode: Makefile; _*_ # _*_ mode: Makefile; _*_
CXX_STD = CXX11 CXX_STD = CXX11
XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0 -DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD)
PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include $(XGB_RFLAGS) XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0\
-DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -DDMLC_DISABLE_STDIN=1\
-DDMLC_LOG_CUSTOMIZE=1 -DXGBOOST_CUSTOMIZE_LOGGER=1\
-DRABIT_CUSTOMIZE_MSG_ -DRABIT_STRICT_CXX98_
PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include -I$(PKGROOT) $(XGB_RFLAGS)
PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS)
OBJECTS= ./xgboost_R.o $(PKGROOT)/amalgamation/xgboost-all0.o $(PKGROOT)/amalgamation/dmlc-minimum0.o $(PKGROOT)/rabit/src/engine_empty.o OBJECTS= ./xgboost_R.o ./xgboost_custom.o ./xgboost_assert.o\
$(PKGROOT)/amalgamation/xgboost-all0.o $(PKGROOT)/amalgamation/dmlc-minimum0.o $(PKGROOT)/rabit/src/engine_empty.o

View File

@ -16,10 +16,16 @@ xgblib:
cp -r ../../amalgamation . cp -r ../../amalgamation .
CXX_STD = CXX11 CXX_STD = CXX11
XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0 -DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD)
PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include $(XGB_RFLAGS) XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0\
-DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -DDMLC_DISABLE_STDIN=1\
-DDMLC_LOG_CUSTOMIZE=1 -DXGBOOST_CUSTOMIZE_LOGGER=1\
-DRABIT_CUSTOMIZE_MSG_ -DRABIT_STRICT_CXX98_
PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(PKGROOT)/dmlc-core/include -I$(PKGROOT)/rabit/include -I$(PKGROOT) $(XGB_RFLAGS)
PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS)
OBJECTS= ./xgboost_R.o $(PKGROOT)/amalgamation/xgboost-all0.o $(PKGROOT)/amalgamation/dmlc-minimum0.o $(PKGROOT)/rabit/src/engine_empty.o OBJECTS= ./xgboost_R.o ./xgboost_custom.o ./xgboost_assert.o\
$(PKGROOT)/amalgamation/xgboost-all0.o $(PKGROOT)/amalgamation/dmlc-minimum0.o $(PKGROOT)/rabit/src/engine_empty.o
$(OBJECTS) : xgblib $(OBJECTS) : xgblib

View File

@ -34,16 +34,6 @@
error(XGBGetLastError()); \ error(XGBGetLastError()); \
} }
namespace xgboost {
namespace common {
bool CheckNAN(double v) {
return ISNAN(v);
}
double LogGamma(double v) {
return lgammafn(v);
}
} // namespace common
} // namespace xgboost
using namespace dmlc; using namespace dmlc;

View File

@ -0,0 +1,26 @@
// Copyright (c) 2014 by Contributors
#include <stdio.h>
#include <stdarg.h>
#include <Rinternals.h>
// implements error handling
void XGBoostAssert_R(int exp, const char *fmt, ...) {
char buf[1024];
if (exp == 0) {
va_list args;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
error("AssertError:%s\n", buf);
}
}
void XGBoostCheck_R(int exp, const char *fmt, ...) {
char buf[1024];
if (exp == 0) {
va_list args;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);
error("%s\n", buf);
}
}

View File

@ -0,0 +1,65 @@
// Copyright (c) 2015 by Contributors
// This file contains the customization implementations of R module
// to change behavior of libxgboost
#include <xgboost/logging.h>
#include "src/common/random.h"
#include "./xgboost_R.h"
// redirect the messages to R's console.
namespace dmlc {
void CustomLogMessage::Log(const std::string& msg) {
Rprintf("%s\n", msg.c_str());
}
} // namespace dmlc
// implements rabit error handling.
extern "C" {
void XGBoostAssert_R(int exp, const char *fmt, ...);
void XGBoostCheck_R(int exp, const char *fmt, ...);
}
namespace rabit {
namespace utils {
extern "C" {
void (*Printf)(const char *fmt, ...) = Rprintf;
void (*Assert)(int exp, const char *fmt, ...) = XGBoostAssert_R;
void (*Check)(int exp, const char *fmt, ...) = XGBoostCheck_R;
void (*Error)(const char *fmt, ...) = error;
}
}
}
namespace xgboost {
ConsoleLogger::~ConsoleLogger() {
dmlc::CustomLogMessage::Log(log_stream_.str());
}
TrackerLogger::~TrackerLogger() {
dmlc::CustomLogMessage::Log(log_stream_.str());
}
} // namespace xgboost
namespace xgboost {
namespace common {
// redirect the nath functions.
bool CheckNAN(double v) {
return ISNAN(v);
}
double LogGamma(double v) {
return lgammafn(v);
}
// customize random engine.
void CustomGlobalRandomEngine::seed(CustomGlobalRandomEngine::result_type val) {
// ignore the seed
}
// use R's PRNG to replacd
CustomGlobalRandomEngine::result_type
CustomGlobalRandomEngine::operator()() {
return static_cast<result_type>(
std::floor(unif_rand() * CustomGlobalRandomEngine::max()));
}
} // namespace common
} // namespace xgboost

@ -1 +1 @@
Subproject commit 42428bc7e79fb3ff80322ca8bc2fdd8026cbc04d Subproject commit ad2ddde8b6624abf3007a71b2923c3925530cc81

View File

@ -1,28 +1,145 @@
Build XGBoost Installation Guide
============= ==================
* Run ```bash build.sh``` (you can also type make)
* If you have C++11 compiler, it is recommended to type ```make cxx11=1```
- C++11 is not used by default
* If your compiler does not come with OpenMP support, it will fire an warning telling you that the code will compile into single thread mode, and you will get single thread xgboost
* You may get a error: -lgomp is not found
- You can type ```make no_omp=1```, this will get you single thread xgboost
- Alternatively, you can upgrade your compiler to compile multi-thread version
* Windows(VS 2010): see [../windows](../windows) folder
- In principle, you put all the cpp files in the Makefile to the project, and build
* OS X with multi-threading support: see [next section](#openmp-for-os-x)
Build XGBoost in OS X with OpenMP This page gives instructions of how to build and install the xgboost package from
--------------------------------- scratch on various systems. It consists of two steps:
Here is the complete solution to use OpenMp-enabled compilers to install XGBoost.
1. Obtain gcc-5.x.x with openmp support by `brew install gcc --without-multilib`. (`brew` is the de facto standard of `apt-get` on OS X. So installing [HPC](http://hpc.sourceforge.net/) separately is not recommended, but it should work.) 1. Fist build the shared library from the C++ codes (`libxgboost.so` for linux/osx and `libxgboost.dll` for windows).
- Exception: for R-package installation please directly refer to the R package section.
2. Then install the language packages (e.g. Python Package).
2. `cd xgboost` then `bash build.sh` to compile XGBoost. Please refer to [Installation FAQ](#frequently-asked-questions) first if you had any problem
during installation. If the instructions do not work for you, please feel free
to ask questions at [xgboost/issues](https://github.com/dmlc/xgboost/issues), or
even better to send pull request if you can fix the problem.
3. Install xgboost package for Python and R ## Contents
- [Build the Shared Library](#build-the-shared-library)
- [Prerequisites](#prerequisites)
- [Building on Ubuntu/Debian](#building-on-ubuntu-debian)
- [Building on OSX](#building-on-osx)
- [Building on Windows](#building-on-windows)
- [Customized Building](#customized-building)
- [Python Package Installation](#python-package-installation)
- [R Package Installation](#r-package-installation)
- [Docker Images](#docker-images)
- [Frequently asked questions](#frequently-asked-questions)
- For Python: go to `python-package` sub-folder to install python version with `python setup.py install` (or `sudo python setup.py install`). ## Build the Shared Library
- For R: Set the `Makevars` file in highest piority for R.
Our goal is to build the shared library:
- On Linux/OSX the target library is ```libxgboost.so```
- On Windows the target libary is ```libxgboost.dll```
The minimal building requirement is
- A recent c++ compiler supporting C++ 11 (g++-4.6 or higher)
We can edit `make/config.mk` to change the compile options, and then build by
`make`. If everything goes well, we can go the specific language installation section.
### Building on Ubuntu/Debian
On Ubuntu, one build xgboost by
Then build xgboost
```bash
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; make -j4
```
### Building on OSX
On Ubuntu OSX, one build xgboost by
```bash
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; cp make/minimum.mk ./config.mk; make -j4
```
This build xgboost without multi-threading, because by default clang in OSX does not come with open-mp.
See the following paragraph for OpenMP enabled xgboost.
Here is the complete solution to use OpenMP-enabled compilers to install XGBoost.
Obtain gcc-5.x.x with openmp support by `brew install gcc --without-multilib`. (`brew` is the de facto standard of `apt-get` on OS X. So installing [HPC](http://hpc.sourceforge.net/) separately is not recommended, but it should work.)
```bash
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost; cp make/config.mk ./config.mk; make -j4
```
### Building on Windows
XGBoost support both build by MSVC or MinGW. Here is how you can build xgboost library using MinGW.
Build with mingw
```bash
cp make/mingw64.mk config.mk; make -j4
```
The MSVC build for new version is not yet updated.
### Customized Building
The configuration of xgboost can be modified by ```config.mk```
- modify configuration on various distributed filesystem such as HDFS/Amazon S3/...
- First copy [make/config.mk](../make/config.mk) to the project root, on which
any local modification will be ignored by git, then modify the according flags.
## Python Package Installation
The python package is located at [python-package](../python-package).
There are several ways to install the package:
1. Install system-widely, which requires root permission
```bash
cd python; sudo python setup.py install
```
You will however need Python `distutils` module for this to
work. It is often part of the core python package or it can be installed using your
package manager, e.g. in Debian use
```bash
sudo apt-get install python-setuptools
```
*NOTE: If you recompiled xgboost, then you need to reinstall it again to
make the new library take effect*
2. Only set the environment variable `PYTHONPATH` to tell python where to find
the library. For example, assume we cloned `xgboost` on the home directory
`~`. then we can added the following line in `~/.bashrc`
It is ***recommended for developers*** who may change the codes. The changes will be immediately reflected once you pulled the code and rebuild the project (no need to call ```setup``` again)
```bash
export PYTHONPATH=~/xgboost/python-package
```
3. Install only for the current user.
```bash
cd python; python setup.py develop --user
```
## R Package Installation
You can install R package using devtools
```r
devtools::install_git('git://github.com/dmlc/xgboost',subdir='R-package')
```
For OSX users, single threaded version will be installed, to install multi-threaded version.
First follow [Building on OSX](#building-on-osx) to get the OpenMP enabled compiler, then:
- Set the `Makevars` file in highest piority for R.
The point is, there are three `Makevars` : `~/.R/Makevars`, `xgboost/R-package/src/Makevars`, and `/usr/local/Cellar/r/3.2.0/R.framework/Resources/etc/Makeconf` (the last one obtained by running `file.path(R.home("etc"), "Makeconf")` in R), and `SHLIB_OPENMP_CXXFLAGS` is not set by default!! After trying, it seems that the first one has highest piority (surprise!). The point is, there are three `Makevars` : `~/.R/Makevars`, `xgboost/R-package/src/Makevars`, and `/usr/local/Cellar/r/3.2.0/R.framework/Resources/etc/Makeconf` (the last one obtained by running `file.path(R.home("etc"), "Makeconf")` in R), and `SHLIB_OPENMP_CXXFLAGS` is not set by default!! After trying, it seems that the first one has highest piority (surprise!).
@ -38,13 +155,19 @@ Here is the complete solution to use OpenMp-enabled compilers to install XGBoost
devtools::install_local('xgboost/', subdir = 'R-package') # you may use devtools devtools::install_local('xgboost/', subdir = 'R-package') # you may use devtools
``` ```
## Frequent Asked Questions
Build with HDFS and S3 Support 1. **Compile failed after `git pull`**
------------------------------
* To build xgboost use with HDFS/S3 support and distributed learnig. It is recommended to build with dmlc, with the following steps Please first update the submodules, clean all and recompile:
- ```git clone https://github.com/dmlc/dmlc-core```
- Follow instruction in dmlc-core/make/config.mk to compile libdmlc.a ```bash
- In root folder of xgboost, type ```make dmlc=dmlc-core``` git submodule update && make clean_all && make -j4
* This will allow xgboost to directly load data and save model from/to hdfs and s3 ```
- Simply replace the filename with prefix s3:// or hdfs://
* This xgboost that can be used for distributed learning 2. **Compile failed after `config.mk` is modified**
Need to clean all first:
```bash
make clean_all && make -j4
```

View File

@ -25,6 +25,20 @@
#define XGBOOST_LOG_WITH_TIME 1 #define XGBOOST_LOG_WITH_TIME 1
#endif #endif
/*!
* \brief Whether customize the logger outputs.
*/
#ifndef XGBOOST_CUSTOMIZE_LOGGER
#define XGBOOST_CUSTOMIZE_LOGGER XGBOOST_STRICT_R_MODE
#endif
/*!
* \brief Whether to customize global PRNG.
*/
#ifndef XGBOOST_CUSTOMIZE_GLOBAL_PRNG
#define XGBOOST_CUSTOMIZE_GLOBAL_PRNG XGBOOST_STRICT_R_MODE
#endif
/*! \brief namespace of xgboo st*/ /*! \brief namespace of xgboo st*/
namespace xgboost { namespace xgboost {
/*! /*!

30
make/mingw64.mk Normal file
View File

@ -0,0 +1,30 @@
#-----------------------------------------------------------
# xgboost: Configuration for MinGW(Windows 64bit)
# This allows to compile xgboost on windows by using mingw.
# You will need to get install an mingw toolchain.
# g++-4.6 or later is required.
#
# see config.mk for template.
#-----------------------------------------------------------
export CXX=g++ -m64
export CC=gcc -m64
# Whether enable openmp support, needed for multi-threading.
USE_OPENMP = 1
# whether use HDFS support during compile
USE_HDFS = 0
# whether use AWS S3 support during compile
USE_S3 = 0
# whether use Azure blob support during compile
USE_AZURE = 0
# Rabit library version,
# - librabit.a Normal distributed version.
# - librabit_empty.a Non distributed mock version,
LIB_RABIT = librabit_empty.a
DMLC_CFLAGS = -DDMLC_ENABLE_STD_THREAD=0
ADD_CFLAGS = -DDMLC_ENABLE_STD_THREAD=0

View File

@ -1,14 +1,11 @@
include *.sh *.md *.rst include *.md *.rst
recursive-include xgboost * recursive-include xgboost *
recursive-include xgboost/wrapper * recursive-include xgboost/include *
recursive-include xgboost/windows *
recursive-include xgboost/subtree *
recursive-include xgboost/src * recursive-include xgboost/src *
recursive-include xgboost/multi-node *
#exclude pre-compiled .o file for less confusions #exclude pre-compiled .o file for less confusions
#include the pre-compiled .so is needed as a placeholder #include the pre-compiled .so is needed as a placeholder
#since it will be copy after compiling on the fly #since it will be copy after compiling on the fly
global-exclude xgboost/wrapper/*.so.gz global-exclude xgboost/build/*
global-exclude xgboost/*.o global-exclude xgboost/*.o
global-exclude *.pyo global-exclude *.pyo
global-exclude *.pyc global-exclude *.pyc

View File

@ -17,7 +17,7 @@ libpath = {'__file__': libpath_py}
exec(compile(open(libpath_py, "rb").read(), libpath_py, 'exec'), libpath, libpath) exec(compile(open(libpath_py, "rb").read(), libpath_py, 'exec'), libpath, libpath)
LIB_PATH = libpath['find_lib_path']() LIB_PATH = libpath['find_lib_path']()
print("Install libxgboost from: %s" % LIB_PATH)
#Please use setup_pip.py for generating and deploying pip installation #Please use setup_pip.py for generating and deploying pip installation
#detailed instruction in setup_pip.py #detailed instruction in setup_pip.py
setup(name='xgboost', setup(name='xgboost',

View File

@ -7,8 +7,8 @@
namespace xgboost { namespace xgboost {
namespace common { namespace common {
RandomEngine& GlobalRandom() { GlobalRandomEngine& GlobalRandom() {
static RandomEngine inst; static GlobalRandomEngine inst;
return inst; return inst;
} }
} }

View File

@ -113,7 +113,7 @@ inline bool CheckNAN(T v) {
#ifdef _MSC_VER #ifdef _MSC_VER
return (_isnan(v) != 0); return (_isnan(v) != 0);
#else #else
return isnan(v); return std::isnan(v);
#endif #endif
} }
template<typename T> template<typename T>

View File

@ -8,6 +8,7 @@
#define XGBOOST_COMMON_RANDOM_H_ #define XGBOOST_COMMON_RANDOM_H_
#include <random> #include <random>
#include <limits>
namespace xgboost { namespace xgboost {
namespace common { namespace common {
@ -15,11 +16,54 @@ namespace common {
* \brief Define mt19937 as default type Random Engine. * \brief Define mt19937 as default type Random Engine.
*/ */
typedef std::mt19937 RandomEngine; typedef std::mt19937 RandomEngine;
#if XGBOOST_CUSTOMIZE_GLOBAL_PRNG
/*!
* \brief An customized random engine, used to be plugged in PRNG from other systems.
* The implementation of this library is not provided by xgboost core library.
* Instead the other library can implement this class, which will be used as GlobalRandomEngine
* If XGBOOST_RANDOM_CUSTOMIZE = 1, by default this is switched off.
*/
class CustomGlobalRandomEngine {
public:
/*! \brief The result type */
typedef size_t result_type;
/*! \brief The minimum of random numbers generated */
inline static constexpr result_type min() {
return 0;
}
/*! \brief The maximum random numbers generated */
inline static constexpr result_type max() {
return std::numeric_limits<size_t>::max();
}
/*!
* \brief seed function, to be implemented
* \param val The value of the seed.
*/
void seed(result_type val);
/*!
* \return next random number.
*/
result_type operator()();
};
/*!
* \brief global random engine
*/
typedef CustomGlobalRandomEngine GlobalRandomEngine;
#else
/*!
* \brief global random engine
*/
typedef RandomEngine GlobalRandomEngine;
#endif
/*! /*!
* \brief global singleton of a random engine. * \brief global singleton of a random engine.
* Only use this engine when necessary, not thread-safe. * Only use this engine when necessary, not thread-safe.
*/ */
RandomEngine& GlobalRandom(); // NOLINT(*) GlobalRandomEngine& GlobalRandom(); // NOLINT(*)
} // namespace common } // namespace common
} // namespace xgboost } // namespace xgboost

View File

@ -8,6 +8,8 @@
#include <dmlc/timer.h> #include <dmlc/timer.h>
#include <xgboost/logging.h> #include <xgboost/logging.h>
#include <memory> #include <memory>
#if DMLC_ENABLE_STD_THREAD
#include "./sparse_page_dmatrix.h" #include "./sparse_page_dmatrix.h"
#include "../common/random.h" #include "../common/random.h"
#include "../common/group_data.h" #include "../common/group_data.h"
@ -278,3 +280,4 @@ void SparsePageDMatrix::InitColAccess(const std::vector<bool>& enabled,
} // namespace data } // namespace data
} // namespace xgboost } // namespace xgboost
#endif

View File

@ -6,6 +6,8 @@
#include <dmlc/timer.h> #include <dmlc/timer.h>
#include <xgboost/logging.h> #include <xgboost/logging.h>
#include <memory> #include <memory>
#if DMLC_ENABLE_STD_THREAD
#include "./sparse_page_source.h" #include "./sparse_page_source.h"
namespace xgboost { namespace xgboost {
@ -175,3 +177,4 @@ void SparsePageSource::Create(DMatrix* src,
} // namespace data } // namespace data
} // namespace xgboost } // namespace xgboost
#endif

View File

@ -334,7 +334,8 @@ class LearnerImpl : public Learner {
// in distributed mode, use safe choice otherwise // in distributed mode, use safe choice otherwise
size_t max_row_perbatch = tparam.max_row_perbatch; size_t max_row_perbatch = tparam.max_row_perbatch;
if (tparam.test_flag == "block" || tparam.dsplit == 2) { if (tparam.test_flag == "block" || tparam.dsplit == 2) {
max_row_perbatch = std::min(32UL << 10UL, max_row_perbatch); max_row_perbatch = std::min(
static_cast<size_t>(32UL << 10UL), max_row_perbatch);
} }
// initialize column access // initialize column access
p_train->InitColAccess(enabled, p_train->InitColAccess(enabled,

View File

@ -9,6 +9,8 @@
#include "./common/sync.h" #include "./common/sync.h"
namespace xgboost { namespace xgboost {
#if XGBOOST_CUSTOMIZE_LOGGER == 0
ConsoleLogger::~ConsoleLogger() { ConsoleLogger::~ConsoleLogger() {
std::cout << log_stream_.str() << std::endl; std::cout << log_stream_.str() << std::endl;
} }
@ -17,4 +19,5 @@ TrackerLogger::~TrackerLogger() {
log_stream_ << '\n'; log_stream_ << '\n';
rabit::TrackerPrint(log_stream_.str()); rabit::TrackerPrint(log_stream_.str());
} }
#endif
} // namespace xgboost } // namespace xgboost

View File

@ -374,8 +374,10 @@ class BaseMaker: public TreeUpdater {
} }
} else { } else {
if (rmax >= next_goal) { if (rmax >= next_goal) {
rabit::TrackerPrintf("INFO: rmax=%g, sum_total=%g, next_goal=%g, size=%lu\n", LOG(TRACKER) << "INFO: rmax=" << rmax
rmax, sum_total, next_goal, sketch->temp.size); << ", sum_total=" << sum_total
<< ", naxt_goal=" << next_goal
<< ", size=" << sketch->temp.size;
} }
} }
rmin = rmax; rmin = rmax;

View File

@ -2,4 +2,6 @@
if [ ${TASK} == "r_test" ]; then if [ ${TASK} == "r_test" ]; then
cat xgboost/xgboost.Rcheck/*.log cat xgboost/xgboost.Rcheck/*.log
echo "--------------------------"
cat xgboost/xgboost.Rcheck/*.out
fi fi