forked from dmlc/xgboost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[R] make all customizations to meet strict standard of cran
- Loading branch information
Showing
23 changed files
with
397 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Submodule dmlc-core
updated
8 files
+7 −5 | .travis.yml | |
+3 −2 | cmake/lint.cmake | |
+8 −0 | include/dmlc/base.h | |
+27 −1 | include/dmlc/logging.h | |
+7 −2 | make/dmlc.mk | |
+1 −2 | scripts/lint3.py | |
+4 −18 | scripts/travis/travis_script.sh | |
+1 −1 | src/io/local_filesys.cc |
Oops, something went wrong.