| 1 | // Copyright (c) 2015 by Contributors |
| 2 | // This file contains the customization implementations of R module |
| 3 | // to change behavior of libxgboost |
| 4 | |
| 5 | #include <xgboost/logging.h> |
| 6 | #include "../../src/common/random.h" |
| 7 | #include "./xgboost_R.h" |
| 8 | |
| 9 | // redirect the messages to R's console. |
| 10 | namespace dmlc { |
| 11 | void CustomLogMessage::Log(const std::string& msg) { |
| 12 | Rprintf("%s\n", msg.c_str()); |
| 13 | } |
| 14 | } // namespace dmlc |
| 15 | |
| 16 | namespace xgboost { |
| 17 | ConsoleLogger::~ConsoleLogger() { |
| 18 | if (cur_verbosity_ == LogVerbosity::kIgnore || |
| 19 | cur_verbosity_ <= GlobalVerbosity()) { |
| 20 | if (cur_verbosity_ == LogVerbosity::kWarning) { |
| 21 | REprintf("%s\n", log_stream_.str().c_str()); |
| 22 | } else { |
| 23 | dmlc::CustomLogMessage::Log(log_stream_.str()); |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | TrackerLogger::~TrackerLogger() { |
| 28 | dmlc::CustomLogMessage::Log(log_stream_.str()); |
| 29 | } |
| 30 | } // namespace xgboost |
| 31 | |
| 32 | namespace xgboost { |
| 33 | namespace common { |
| 34 | |
| 35 | // redirect the nath functions. |
| 36 | bool CheckNAN(double v) { |
| 37 | return ISNAN(v); |
| 38 | } |
| 39 | #if !defined(XGBOOST_USE_CUDA) |
| 40 | double LogGamma(double v) { |
| 41 | return lgammafn(v); |
| 42 | } |
| 43 | #endif // !defined(XGBOOST_USE_CUDA) |
| 44 | |
| 45 | } // namespace common |
| 46 | } // namespace xgboost |