[R] make all customizations to meet strict standard of cran
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
|
||||
namespace xgboost {
|
||||
namespace common {
|
||||
RandomEngine& GlobalRandom() {
|
||||
static RandomEngine inst;
|
||||
GlobalRandomEngine& GlobalRandom() {
|
||||
static GlobalRandomEngine inst;
|
||||
return inst;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ inline bool CheckNAN(T v) {
|
||||
#ifdef _MSC_VER
|
||||
return (_isnan(v) != 0);
|
||||
#else
|
||||
return isnan(v);
|
||||
return std::isnan(v);
|
||||
#endif
|
||||
}
|
||||
template<typename T>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define XGBOOST_COMMON_RANDOM_H_
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
|
||||
namespace xgboost {
|
||||
namespace common {
|
||||
@@ -15,11 +16,54 @@ namespace common {
|
||||
* \brief Define mt19937 as default type Random Engine.
|
||||
*/
|
||||
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.
|
||||
* Only use this engine when necessary, not thread-safe.
|
||||
*/
|
||||
RandomEngine& GlobalRandom(); // NOLINT(*)
|
||||
GlobalRandomEngine& GlobalRandom(); // NOLINT(*)
|
||||
|
||||
} // namespace common
|
||||
} // namespace xgboost
|
||||
|
||||
Reference in New Issue
Block a user