move sprintf into std
This commit is contained in:
parent
29a7027dba
commit
bb5c151f57
@ -14,6 +14,7 @@ using namespace xgboost;
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
void XGBoostAssert_R(int exp, const char *fmt, ...);
|
void XGBoostAssert_R(int exp, const char *fmt, ...);
|
||||||
void XGBoostCheck_R(int exp, const char *fmt, ...);
|
void XGBoostCheck_R(int exp, const char *fmt, ...);
|
||||||
|
int XGBoostSPrintf_R(char *buf, size_t size, const char *fmt, ...);
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements error handling
|
// implements error handling
|
||||||
@ -21,6 +22,7 @@ namespace xgboost {
|
|||||||
namespace utils {
|
namespace utils {
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void (*Printf)(const char *fmt, ...) = Rprintf;
|
void (*Printf)(const char *fmt, ...) = Rprintf;
|
||||||
|
int (*SPrintf)(char *buf, size_t size, const char *fmt, ...) = XGBoostSPrintf_R;
|
||||||
void (*Assert)(int exp, const char *fmt, ...) = XGBoostAssert_R;
|
void (*Assert)(int exp, const char *fmt, ...) = XGBoostAssert_R;
|
||||||
void (*Check)(int exp, const char *fmt, ...) = XGBoostCheck_R;
|
void (*Check)(int exp, const char *fmt, ...) = XGBoostCheck_R;
|
||||||
void (*Error)(const char *fmt, ...) = error;
|
void (*Error)(const char *fmt, ...) = error;
|
||||||
|
|||||||
@ -23,3 +23,11 @@ void XGBoostCheck_R(int exp, const char *fmt, ...) {
|
|||||||
error("%s\n", buf);
|
error("%s\n", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int XGBoostSPrintf_R(char *buf, size_t size, const char *fmt, ...) {
|
||||||
|
int ret;
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
ret = vsnprintf(buf, size, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|||||||
@ -73,7 +73,7 @@ class EvalSet{
|
|||||||
for (size_t i = 0; i < evals_.size(); ++i) {
|
for (size_t i = 0; i < evals_.size(); ++i) {
|
||||||
float res = evals_[i]->Eval(preds, info);
|
float res = evals_[i]->Eval(preds, info);
|
||||||
char tmp[1024];
|
char tmp[1024];
|
||||||
snprintf(tmp, sizeof(tmp), "\t%s-%s:%f", evname, evals_[i]->Name(), res);
|
utils::SPrintf(tmp, sizeof(tmp), "\t%s-%s:%f", evname, evals_[i]->Name(), res);
|
||||||
result += tmp;
|
result += tmp;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -63,10 +63,10 @@ class BoostLearner {
|
|||||||
}
|
}
|
||||||
char str_temp[25];
|
char str_temp[25];
|
||||||
if (num_feature > mparam.num_feature) {
|
if (num_feature > mparam.num_feature) {
|
||||||
snprintf(str_temp, sizeof(str_temp), "%u", num_feature);
|
utils::SPrintf(str_temp, sizeof(str_temp), "%u", num_feature);
|
||||||
this->SetParam("bst:num_feature", str_temp);
|
this->SetParam("bst:num_feature", str_temp);
|
||||||
}
|
}
|
||||||
snprintf(str_temp, sizeof(str_temp), "%lu",
|
utils::SPrintf(str_temp, sizeof(str_temp), "%lu",
|
||||||
static_cast<unsigned long>(buffer_size));
|
static_cast<unsigned long>(buffer_size));
|
||||||
this->SetParam("num_pbuffer", str_temp);
|
this->SetParam("num_pbuffer", str_temp);
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
@ -183,7 +183,7 @@ class BoostLearner {
|
|||||||
const std::vector<std::string> &evname) {
|
const std::vector<std::string> &evname) {
|
||||||
std::string res;
|
std::string res;
|
||||||
char tmp[256];
|
char tmp[256];
|
||||||
snprintf(tmp, sizeof(tmp), "[%d]", iter);
|
utils::SPrintf(tmp, sizeof(tmp), "[%d]", iter);
|
||||||
res = tmp;
|
res = tmp;
|
||||||
for (size_t i = 0; i < evals.size(); ++i) {
|
for (size_t i = 0; i < evals.size(); ++i) {
|
||||||
this->PredictRaw(*evals[i], &preds_);
|
this->PredictRaw(*evals[i], &preds_);
|
||||||
|
|||||||
@ -87,6 +87,7 @@ void HandlePrint(const char *msg);
|
|||||||
#ifdef XGBOOST_STRICT_CXX98_
|
#ifdef XGBOOST_STRICT_CXX98_
|
||||||
// these function pointers are to be assigned
|
// these function pointers are to be assigned
|
||||||
extern "C" void (*Printf)(const char *fmt, ...);
|
extern "C" void (*Printf)(const char *fmt, ...);
|
||||||
|
extern "C" int (*SPrintf)(char *buf, size_t size, const char *fmt, ...);
|
||||||
extern "C" void (*Assert)(int exp, const char *fmt, ...);
|
extern "C" void (*Assert)(int exp, const char *fmt, ...);
|
||||||
extern "C" void (*Check)(int exp, const char *fmt, ...);
|
extern "C" void (*Check)(int exp, const char *fmt, ...);
|
||||||
extern "C" void (*Error)(const char *fmt, ...);
|
extern "C" void (*Error)(const char *fmt, ...);
|
||||||
@ -100,6 +101,14 @@ inline void Printf(const char *fmt, ...) {
|
|||||||
va_end(args);
|
va_end(args);
|
||||||
HandlePrint(msg.c_str());
|
HandlePrint(msg.c_str());
|
||||||
}
|
}
|
||||||
|
/*! \brief portable version of snprintf */
|
||||||
|
inline int SPrintf(char *buf, size_t size, const char *fmt, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
int ret = vsnprintf(buf, size, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/*! \brief assert an condition is true, use this to handle debug information */
|
/*! \brief assert an condition is true, use this to handle debug information */
|
||||||
inline void Assert(bool exp, const char *fmt, ...) {
|
inline void Assert(bool exp, const char *fmt, ...) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user