fix all cpp lint
This commit is contained in:
parent
1123253f79
commit
57ec922214
@ -1,9 +1,10 @@
|
|||||||
|
// Copyright (c) 2014 by Contributors
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "wrapper/xgboost_wrapper.h"
|
#include "wrapper/xgboost_wrapper.h"
|
||||||
#include "src/utils/utils.h"
|
#include "src/utils/utils.h"
|
||||||
#include "src/utils/omp.h"
|
#include "src/utils/omp.h"
|
||||||
@ -34,7 +35,7 @@ bool CheckNAN(double v) {
|
|||||||
bool LogGamma(double v) {
|
bool LogGamma(double v) {
|
||||||
return lgammafn(v);
|
return lgammafn(v);
|
||||||
}
|
}
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|
||||||
namespace random {
|
namespace random {
|
||||||
void Seed(unsigned seed) {
|
void Seed(unsigned seed) {
|
||||||
@ -62,7 +63,7 @@ extern "C" {
|
|||||||
SEXP XGCheckNullPtr_R(SEXP handle) {
|
SEXP XGCheckNullPtr_R(SEXP handle) {
|
||||||
return ScalarLogical(R_ExternalPtrAddr(handle) == NULL);
|
return ScalarLogical(R_ExternalPtrAddr(handle) == NULL);
|
||||||
}
|
}
|
||||||
void _DMatrixFinalizer(SEXP ext) {
|
void _DMatrixFinalizer(SEXP ext) {
|
||||||
if (R_ExternalPtrAddr(ext) == NULL) return;
|
if (R_ExternalPtrAddr(ext) == NULL) return;
|
||||||
XGDMatrixFree(R_ExternalPtrAddr(ext));
|
XGDMatrixFree(R_ExternalPtrAddr(ext));
|
||||||
R_ClearExternalPtr(ext);
|
R_ClearExternalPtr(ext);
|
||||||
@ -76,7 +77,7 @@ extern "C" {
|
|||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
SEXP XGDMatrixCreateFromMat_R(SEXP mat,
|
SEXP XGDMatrixCreateFromMat_R(SEXP mat,
|
||||||
SEXP missing) {
|
SEXP missing) {
|
||||||
_WrapperBegin();
|
_WrapperBegin();
|
||||||
SEXP dim = getAttrib(mat, R_DimSymbol);
|
SEXP dim = getAttrib(mat, R_DimSymbol);
|
||||||
@ -95,7 +96,7 @@ extern "C" {
|
|||||||
SEXP ret = PROTECT(R_MakeExternalPtr(handle, R_NilValue, R_NilValue));
|
SEXP ret = PROTECT(R_MakeExternalPtr(handle, R_NilValue, R_NilValue));
|
||||||
R_RegisterCFinalizerEx(ret, _DMatrixFinalizer, TRUE);
|
R_RegisterCFinalizerEx(ret, _DMatrixFinalizer, TRUE);
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
SEXP XGDMatrixCreateFromCSC_R(SEXP indptr,
|
SEXP XGDMatrixCreateFromCSC_R(SEXP indptr,
|
||||||
SEXP indices,
|
SEXP indices,
|
||||||
@ -138,7 +139,7 @@ extern "C" {
|
|||||||
SEXP ret = PROTECT(R_MakeExternalPtr(res, R_NilValue, R_NilValue));
|
SEXP ret = PROTECT(R_MakeExternalPtr(res, R_NilValue, R_NilValue));
|
||||||
R_RegisterCFinalizerEx(ret, _DMatrixFinalizer, TRUE);
|
R_RegisterCFinalizerEx(ret, _DMatrixFinalizer, TRUE);
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
void XGDMatrixSaveBinary_R(SEXP handle, SEXP fname, SEXP silent) {
|
void XGDMatrixSaveBinary_R(SEXP handle, SEXP fname, SEXP silent) {
|
||||||
_WrapperBegin();
|
_WrapperBegin();
|
||||||
@ -152,7 +153,7 @@ extern "C" {
|
|||||||
const char *name = CHAR(asChar(field));
|
const char *name = CHAR(asChar(field));
|
||||||
if (!strcmp("group", name)) {
|
if (!strcmp("group", name)) {
|
||||||
std::vector<unsigned> vec(len);
|
std::vector<unsigned> vec(len);
|
||||||
#pragma omp parallel for schedule(static)
|
#pragma omp parallel for schedule(static)
|
||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
vec[i] = static_cast<unsigned>(INTEGER(array)[i]);
|
vec[i] = static_cast<unsigned>(INTEGER(array)[i]);
|
||||||
}
|
}
|
||||||
@ -163,7 +164,7 @@ extern "C" {
|
|||||||
for (int i = 0; i < len; ++i) {
|
for (int i = 0; i < len; ++i) {
|
||||||
vec[i] = REAL(array)[i];
|
vec[i] = REAL(array)[i];
|
||||||
}
|
}
|
||||||
XGDMatrixSetFloatInfo(R_ExternalPtrAddr(handle),
|
XGDMatrixSetFloatInfo(R_ExternalPtrAddr(handle),
|
||||||
CHAR(asChar(field)),
|
CHAR(asChar(field)),
|
||||||
BeginPtr(vec), len);
|
BeginPtr(vec), len);
|
||||||
}
|
}
|
||||||
@ -187,7 +188,7 @@ extern "C" {
|
|||||||
return ScalarInteger(static_cast<int>(nrow));
|
return ScalarInteger(static_cast<int>(nrow));
|
||||||
}
|
}
|
||||||
// functions related to booster
|
// functions related to booster
|
||||||
void _BoosterFinalizer(SEXP ext) {
|
void _BoosterFinalizer(SEXP ext) {
|
||||||
if (R_ExternalPtrAddr(ext) == NULL) return;
|
if (R_ExternalPtrAddr(ext) == NULL) return;
|
||||||
XGBoosterFree(R_ExternalPtrAddr(ext));
|
XGBoosterFree(R_ExternalPtrAddr(ext));
|
||||||
R_ClearExternalPtr(ext);
|
R_ClearExternalPtr(ext);
|
||||||
@ -196,7 +197,7 @@ extern "C" {
|
|||||||
_WrapperBegin();
|
_WrapperBegin();
|
||||||
int len = length(dmats);
|
int len = length(dmats);
|
||||||
std::vector<void*> dvec;
|
std::vector<void*> dvec;
|
||||||
for (int i = 0; i < len; ++i){
|
for (int i = 0; i < len; ++i) {
|
||||||
dvec.push_back(R_ExternalPtrAddr(VECTOR_ELT(dmats, i)));
|
dvec.push_back(R_ExternalPtrAddr(VECTOR_ELT(dmats, i)));
|
||||||
}
|
}
|
||||||
void *handle = XGBoosterCreate(BeginPtr(dvec), dvec.size());
|
void *handle = XGBoosterCreate(BeginPtr(dvec), dvec.size());
|
||||||
@ -252,7 +253,7 @@ extern "C" {
|
|||||||
const char *ret =
|
const char *ret =
|
||||||
XGBoosterEvalOneIter(R_ExternalPtrAddr(handle),
|
XGBoosterEvalOneIter(R_ExternalPtrAddr(handle),
|
||||||
asInteger(iter),
|
asInteger(iter),
|
||||||
BeginPtr(vec_dmats), BeginPtr(vec_sptr), len);
|
BeginPtr(vec_dmats), BeginPtr(vec_sptr), len);
|
||||||
_WrapperEnd();
|
_WrapperEnd();
|
||||||
return mkString(ret);
|
return mkString(ret);
|
||||||
}
|
}
|
||||||
@ -282,7 +283,7 @@ extern "C" {
|
|||||||
XGBoosterSaveModel(R_ExternalPtrAddr(handle), CHAR(asChar(fname)));
|
XGBoosterSaveModel(R_ExternalPtrAddr(handle), CHAR(asChar(fname)));
|
||||||
_WrapperEnd();
|
_WrapperEnd();
|
||||||
}
|
}
|
||||||
void XGBoosterLoadModelFromRaw_R(SEXP handle, SEXP raw) {
|
void XGBoosterLoadModelFromRaw_R(SEXP handle, SEXP raw) {
|
||||||
_WrapperBegin();
|
_WrapperBegin();
|
||||||
XGBoosterLoadModelFromBuffer(R_ExternalPtrAddr(handle),
|
XGBoosterLoadModelFromBuffer(R_ExternalPtrAddr(handle),
|
||||||
RAW(raw),
|
RAW(raw),
|
||||||
@ -298,7 +299,7 @@ extern "C" {
|
|||||||
if (olen != 0) {
|
if (olen != 0) {
|
||||||
memcpy(RAW(ret), raw, olen);
|
memcpy(RAW(ret), raw, olen);
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
SEXP XGBoosterDumpModel_R(SEXP handle, SEXP fmap, SEXP with_stats) {
|
SEXP XGBoosterDumpModel_R(SEXP handle, SEXP fmap, SEXP with_stats) {
|
||||||
@ -310,10 +311,10 @@ extern "C" {
|
|||||||
asInteger(with_stats),
|
asInteger(with_stats),
|
||||||
&olen);
|
&olen);
|
||||||
_WrapperEnd();
|
_WrapperEnd();
|
||||||
SEXP out = PROTECT(allocVector(STRSXP, olen));
|
SEXP out = PROTECT(allocVector(STRSXP, olen));
|
||||||
for (size_t i = 0; i < olen; ++i) {
|
for (size_t i = 0; i < olen; ++i) {
|
||||||
stringstream stream;
|
stringstream stream;
|
||||||
stream << "booster["<<i<<"]\n" << res[i];
|
stream << "booster[" << i <<"]\n" << res[i];
|
||||||
SET_STRING_ELT(out, i, mkChar(stream.str().c_str()));
|
SET_STRING_ELT(out, i, mkChar(stream.str().c_str()));
|
||||||
}
|
}
|
||||||
UNPROTECT(1);
|
UNPROTECT(1);
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
#ifndef XGBOOST_WRAPPER_R_H_
|
|
||||||
#define XGBOOST_WRAPPER_R_H_
|
|
||||||
/*!
|
/*!
|
||||||
|
* Copyright 2014 (c) by Contributors
|
||||||
* \file xgboost_wrapper_R.h
|
* \file xgboost_wrapper_R.h
|
||||||
* \author Tianqi Chen
|
* \author Tianqi Chen
|
||||||
* \brief R wrapper of xgboost
|
* \brief R wrapper of xgboost
|
||||||
*/
|
*/
|
||||||
|
#ifndef XGBOOST_WRAPPER_R_H_ // NOLINT(*)
|
||||||
|
#define XGBOOST_WRAPPER_R_H_ // NOLINT(*)
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <Rinternals.h>
|
#include <Rinternals.h>
|
||||||
#include <R_ext/Random.h>
|
#include <R_ext/Random.h>
|
||||||
@ -19,7 +21,7 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
SEXP XGCheckNullPtr_R(SEXP handle);
|
SEXP XGCheckNullPtr_R(SEXP handle);
|
||||||
/*!
|
/*!
|
||||||
* \brief load a data matrix
|
* \brief load a data matrix
|
||||||
* \param fname name of the content
|
* \param fname name of the content
|
||||||
* \param silent whether print messages
|
* \param silent whether print messages
|
||||||
* \return a loaded data matrix
|
* \return a loaded data matrix
|
||||||
@ -32,9 +34,9 @@ extern "C" {
|
|||||||
* \param missing which value to represent missing value
|
* \param missing which value to represent missing value
|
||||||
* \return created dmatrix
|
* \return created dmatrix
|
||||||
*/
|
*/
|
||||||
SEXP XGDMatrixCreateFromMat_R(SEXP mat,
|
SEXP XGDMatrixCreateFromMat_R(SEXP mat,
|
||||||
SEXP missing);
|
SEXP missing);
|
||||||
/*!
|
/*!
|
||||||
* \brief create a matrix content from CSC format
|
* \brief create a matrix content from CSC format
|
||||||
* \param indptr pointer to column headers
|
* \param indptr pointer to column headers
|
||||||
* \param indices row indices
|
* \param indices row indices
|
||||||
@ -70,26 +72,26 @@ extern "C" {
|
|||||||
* \param handle a instance of data matrix
|
* \param handle a instance of data matrix
|
||||||
* \param field field name
|
* \param field field name
|
||||||
* \return info vector
|
* \return info vector
|
||||||
*/
|
*/
|
||||||
SEXP XGDMatrixGetInfo_R(SEXP handle, SEXP field);
|
SEXP XGDMatrixGetInfo_R(SEXP handle, SEXP field);
|
||||||
/*!
|
/*!
|
||||||
* \brief return number of rows
|
* \brief return number of rows
|
||||||
* \param handle a instance of data matrix
|
* \param handle a instance of data matrix
|
||||||
*/
|
*/
|
||||||
SEXP XGDMatrixNumRow_R(SEXP handle);
|
SEXP XGDMatrixNumRow_R(SEXP handle);
|
||||||
/*!
|
/*!
|
||||||
* \brief create xgboost learner
|
* \brief create xgboost learner
|
||||||
* \param dmats a list of dmatrix handles that will be cached
|
* \param dmats a list of dmatrix handles that will be cached
|
||||||
*/
|
*/
|
||||||
SEXP XGBoosterCreate_R(SEXP dmats);
|
SEXP XGBoosterCreate_R(SEXP dmats);
|
||||||
/*!
|
/*!
|
||||||
* \brief set parameters
|
* \brief set parameters
|
||||||
* \param handle handle
|
* \param handle handle
|
||||||
* \param name parameter name
|
* \param name parameter name
|
||||||
* \param val value of parameter
|
* \param val value of parameter
|
||||||
*/
|
*/
|
||||||
void XGBoosterSetParam_R(SEXP handle, SEXP name, SEXP val);
|
void XGBoosterSetParam_R(SEXP handle, SEXP name, SEXP val);
|
||||||
/*!
|
/*!
|
||||||
* \brief update the model in one round using dtrain
|
* \brief update the model in one round using dtrain
|
||||||
* \param handle handle
|
* \param handle handle
|
||||||
* \param iter current iteration rounds
|
* \param iter current iteration rounds
|
||||||
@ -132,12 +134,12 @@ extern "C" {
|
|||||||
* \brief save model into existing file
|
* \brief save model into existing file
|
||||||
* \param handle handle
|
* \param handle handle
|
||||||
* \param fname file name
|
* \param fname file name
|
||||||
*/
|
*/
|
||||||
void XGBoosterSaveModel_R(SEXP handle, SEXP fname);
|
void XGBoosterSaveModel_R(SEXP handle, SEXP fname);
|
||||||
/*!
|
/*!
|
||||||
* \brief load model from raw array
|
* \brief load model from raw array
|
||||||
* \param handle handle
|
* \param handle handle
|
||||||
*/
|
*/
|
||||||
void XGBoosterLoadModelFromRaw_R(SEXP handle, SEXP raw);
|
void XGBoosterLoadModelFromRaw_R(SEXP handle, SEXP raw);
|
||||||
/*!
|
/*!
|
||||||
* \brief save model into R's raw array
|
* \brief save model into R's raw array
|
||||||
@ -153,4 +155,4 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
SEXP XGBoosterDumpModel_R(SEXP handle, SEXP fmap, SEXP with_stats);
|
SEXP XGBoosterDumpModel_R(SEXP handle, SEXP fmap, SEXP with_stats);
|
||||||
}
|
}
|
||||||
#endif // XGBOOST_WRAPPER_R_H_
|
#endif // XGBOOST_WRAPPER_R_H_ // NOLINT(*)
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// Copyright (c) 2014 by Contributors
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <Rinternals.h>
|
#include <Rinternals.h>
|
||||||
@ -6,17 +7,17 @@
|
|||||||
void XGBoostAssert_R(int exp, const char *fmt, ...) {
|
void XGBoostAssert_R(int exp, const char *fmt, ...) {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
if (exp == 0) {
|
if (exp == 0) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vsprintf(buf, fmt, args);
|
vsprintf(buf, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
error("AssertError:%s\n", buf);
|
error("AssertError:%s\n", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void XGBoostCheck_R(int exp, const char *fmt, ...) {
|
void XGBoostCheck_R(int exp, const char *fmt, ...) {
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
if (exp == 0) {
|
if (exp == 0) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
vsprintf(buf, fmt, args);
|
vsprintf(buf, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
@ -25,7 +26,7 @@ void XGBoostCheck_R(int exp, const char *fmt, ...) {
|
|||||||
}
|
}
|
||||||
int XGBoostSPrintf_R(char *buf, size_t size, const char *fmt, ...) {
|
int XGBoostSPrintf_R(char *buf, size_t size, const char *fmt, ...) {
|
||||||
int ret;
|
int ret;
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
ret = vsnprintf(buf, size, fmt, args);
|
ret = vsnprintf(buf, size, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
// Copyright (c) 2014 by Contributors
|
||||||
// implementations in ctypes
|
// implementations in ctypes
|
||||||
#define _CRT_SECURE_NO_WARNINGS
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
#define _CRT_SECURE_NO_DEPRECATE
|
#define _CRT_SECURE_NO_DEPRECATE
|
||||||
@ -31,9 +32,11 @@ class Booster: public learner::BoostLearner {
|
|||||||
this->init_model = false;
|
this->init_model = false;
|
||||||
this->SetCacheData(mats);
|
this->SetCacheData(mats);
|
||||||
}
|
}
|
||||||
inline const float *Pred(const DataMatrix &dmat, int option_mask, unsigned ntree_limit, bst_ulong *len) {
|
inline const float *Pred(const DataMatrix &dmat, int option_mask,
|
||||||
|
unsigned ntree_limit, bst_ulong *len) {
|
||||||
this->CheckInitModel();
|
this->CheckInitModel();
|
||||||
this->Predict(dmat, (option_mask&1) != 0, &this->preds_, ntree_limit, (option_mask&2) != 0);
|
this->Predict(dmat, (option_mask&1) != 0, &this->preds_,
|
||||||
|
ntree_limit, (option_mask&2) != 0);
|
||||||
*len = static_cast<bst_ulong>(this->preds_.size());
|
*len = static_cast<bst_ulong>(this->preds_.size());
|
||||||
return BeginPtr(this->preds_);
|
return BeginPtr(this->preds_);
|
||||||
}
|
}
|
||||||
@ -57,9 +60,9 @@ class Booster: public learner::BoostLearner {
|
|||||||
this->init_model = true;
|
this->init_model = true;
|
||||||
}
|
}
|
||||||
inline void LoadModelFromBuffer(const void *buf, size_t size) {
|
inline void LoadModelFromBuffer(const void *buf, size_t size) {
|
||||||
utils::MemoryFixSizeBuffer fs((void*)buf, size);
|
utils::MemoryFixSizeBuffer fs((void*)buf, size); // NOLINT(*)
|
||||||
learner::BoostLearner::LoadModel(fs, true);
|
learner::BoostLearner::LoadModel(fs, true);
|
||||||
this->init_model = true;
|
this->init_model = true;
|
||||||
}
|
}
|
||||||
inline const char *GetModelRaw(bst_ulong *out_len) {
|
inline const char *GetModelRaw(bst_ulong *out_len) {
|
||||||
this->CheckInitModel();
|
this->CheckInitModel();
|
||||||
@ -99,246 +102,247 @@ class Booster: public learner::BoostLearner {
|
|||||||
|
|
||||||
using namespace xgboost::wrapper;
|
using namespace xgboost::wrapper;
|
||||||
|
|
||||||
extern "C"{
|
void* XGDMatrixCreateFromFile(const char *fname, int silent) {
|
||||||
void* XGDMatrixCreateFromFile(const char *fname, int silent) {
|
return LoadDataMatrix(fname, silent != 0, false, false);
|
||||||
return LoadDataMatrix(fname, silent != 0, false, false);
|
}
|
||||||
|
void* XGDMatrixCreateFromCSR(const bst_ulong *indptr,
|
||||||
|
const unsigned *indices,
|
||||||
|
const float *data,
|
||||||
|
bst_ulong nindptr,
|
||||||
|
bst_ulong nelem) {
|
||||||
|
DMatrixSimple *p_mat = new DMatrixSimple();
|
||||||
|
DMatrixSimple &mat = *p_mat;
|
||||||
|
mat.row_ptr_.resize(nindptr);
|
||||||
|
for (bst_ulong i = 0; i < nindptr; ++i) {
|
||||||
|
mat.row_ptr_[i] = static_cast<size_t>(indptr[i]);
|
||||||
}
|
}
|
||||||
void* XGDMatrixCreateFromCSR(const bst_ulong *indptr,
|
mat.row_data_.resize(nelem);
|
||||||
const unsigned *indices,
|
for (bst_ulong i = 0; i < nelem; ++i) {
|
||||||
const float *data,
|
mat.row_data_[i] = RowBatch::Entry(indices[i], data[i]);
|
||||||
bst_ulong nindptr,
|
mat.info.info.num_col = std::max(mat.info.info.num_col,
|
||||||
bst_ulong nelem) {
|
static_cast<size_t>(indices[i]+1));
|
||||||
DMatrixSimple *p_mat = new DMatrixSimple();
|
|
||||||
DMatrixSimple &mat = *p_mat;
|
|
||||||
mat.row_ptr_.resize(nindptr);
|
|
||||||
for (bst_ulong i = 0; i < nindptr; ++i) {
|
|
||||||
mat.row_ptr_[i] = static_cast<size_t>(indptr[i]);
|
|
||||||
}
|
|
||||||
mat.row_data_.resize(nelem);
|
|
||||||
for (bst_ulong i = 0; i < nelem; ++i) {
|
|
||||||
mat.row_data_[i] = RowBatch::Entry(indices[i], data[i]);
|
|
||||||
mat.info.info.num_col = std::max(mat.info.info.num_col,
|
|
||||||
static_cast<size_t>(indices[i]+1));
|
|
||||||
}
|
|
||||||
mat.info.info.num_row = nindptr - 1;
|
|
||||||
return p_mat;
|
|
||||||
}
|
}
|
||||||
XGB_DLL void* XGDMatrixCreateFromCSC(const bst_ulong *col_ptr,
|
mat.info.info.num_row = nindptr - 1;
|
||||||
const unsigned *indices,
|
return p_mat;
|
||||||
const float *data,
|
}
|
||||||
bst_ulong nindptr,
|
void* XGDMatrixCreateFromCSC(const bst_ulong *col_ptr,
|
||||||
bst_ulong nelem) {
|
const unsigned *indices,
|
||||||
int nthread;
|
const float *data,
|
||||||
#pragma omp parallel
|
bst_ulong nindptr,
|
||||||
{
|
bst_ulong nelem) {
|
||||||
nthread = omp_get_num_threads();
|
int nthread;
|
||||||
}
|
#pragma omp parallel
|
||||||
|
{
|
||||||
DMatrixSimple *p_mat = new DMatrixSimple();
|
nthread = omp_get_num_threads();
|
||||||
DMatrixSimple &mat = *p_mat;
|
|
||||||
utils::ParallelGroupBuilder<RowBatch::Entry> builder(&mat.row_ptr_, &mat.row_data_);
|
|
||||||
builder.InitBudget(0, nthread);
|
|
||||||
long ncol = static_cast<long>(nindptr - 1);
|
|
||||||
#pragma omp parallel for schedule(static)
|
|
||||||
for (long i = 0; i < ncol; ++i) {
|
|
||||||
int tid = omp_get_thread_num();
|
|
||||||
for (unsigned j = col_ptr[i]; j < col_ptr[i+1]; ++j) {
|
|
||||||
builder.AddBudget(indices[j], tid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
builder.InitStorage();
|
|
||||||
#pragma omp parallel for schedule(static)
|
|
||||||
for (long i = 0; i < ncol; ++i) {
|
|
||||||
int tid = omp_get_thread_num();
|
|
||||||
for (unsigned j = col_ptr[i]; j < col_ptr[i+1]; ++j) {
|
|
||||||
builder.Push(indices[j],
|
|
||||||
RowBatch::Entry(static_cast<bst_uint>(i), data[j]),
|
|
||||||
tid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mat.info.info.num_row = mat.row_ptr_.size() - 1;
|
|
||||||
mat.info.info.num_col = static_cast<size_t>(ncol);
|
|
||||||
return p_mat;
|
|
||||||
}
|
}
|
||||||
void* XGDMatrixCreateFromMat(const float *data,
|
|
||||||
bst_ulong nrow,
|
DMatrixSimple *p_mat = new DMatrixSimple();
|
||||||
bst_ulong ncol,
|
DMatrixSimple &mat = *p_mat;
|
||||||
float missing) {
|
utils::ParallelGroupBuilder<RowBatch::Entry> builder(&mat.row_ptr_, &mat.row_data_);
|
||||||
bool nan_missing = utils::CheckNAN(missing);
|
builder.InitBudget(0, nthread);
|
||||||
DMatrixSimple *p_mat = new DMatrixSimple();
|
long ncol = static_cast<long>(nindptr - 1); // NOLINT(*)
|
||||||
DMatrixSimple &mat = *p_mat;
|
#pragma omp parallel for schedule(static)
|
||||||
mat.info.info.num_row = nrow;
|
for (long i = 0; i < ncol; ++i) { // NOLINT(*)
|
||||||
mat.info.info.num_col = ncol;
|
int tid = omp_get_thread_num();
|
||||||
for (bst_ulong i = 0; i < nrow; ++i, data += ncol) {
|
for (unsigned j = col_ptr[i]; j < col_ptr[i+1]; ++j) {
|
||||||
bst_ulong nelem = 0;
|
builder.AddBudget(indices[j], tid);
|
||||||
for (bst_ulong j = 0; j < ncol; ++j) {
|
}
|
||||||
if (utils::CheckNAN(data[j])) {
|
}
|
||||||
utils::Check(nan_missing,
|
builder.InitStorage();
|
||||||
"There are NAN in the matrix, however, you did not set missing=NAN");
|
#pragma omp parallel for schedule(static)
|
||||||
} else {
|
for (long i = 0; i < ncol; ++i) { // NOLINT(*)
|
||||||
if (nan_missing || data[j] != missing) {
|
int tid = omp_get_thread_num();
|
||||||
mat.row_data_.push_back(RowBatch::Entry(j, data[j]));
|
for (unsigned j = col_ptr[i]; j < col_ptr[i+1]; ++j) {
|
||||||
++nelem;
|
builder.Push(indices[j],
|
||||||
}
|
RowBatch::Entry(static_cast<bst_uint>(i), data[j]),
|
||||||
|
tid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mat.info.info.num_row = mat.row_ptr_.size() - 1;
|
||||||
|
mat.info.info.num_col = static_cast<size_t>(ncol);
|
||||||
|
return p_mat;
|
||||||
|
}
|
||||||
|
void* XGDMatrixCreateFromMat(const float *data,
|
||||||
|
bst_ulong nrow,
|
||||||
|
bst_ulong ncol,
|
||||||
|
float missing) {
|
||||||
|
bool nan_missing = utils::CheckNAN(missing);
|
||||||
|
DMatrixSimple *p_mat = new DMatrixSimple();
|
||||||
|
DMatrixSimple &mat = *p_mat;
|
||||||
|
mat.info.info.num_row = nrow;
|
||||||
|
mat.info.info.num_col = ncol;
|
||||||
|
for (bst_ulong i = 0; i < nrow; ++i, data += ncol) {
|
||||||
|
bst_ulong nelem = 0;
|
||||||
|
for (bst_ulong j = 0; j < ncol; ++j) {
|
||||||
|
if (utils::CheckNAN(data[j])) {
|
||||||
|
utils::Check(nan_missing,
|
||||||
|
"There are NAN in the matrix, however, you did not set missing=NAN");
|
||||||
|
} else {
|
||||||
|
if (nan_missing || data[j] != missing) {
|
||||||
|
mat.row_data_.push_back(RowBatch::Entry(j, data[j]));
|
||||||
|
++nelem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mat.row_ptr_.push_back(mat.row_ptr_.back() + nelem);
|
|
||||||
}
|
}
|
||||||
return p_mat;
|
mat.row_ptr_.push_back(mat.row_ptr_.back() + nelem);
|
||||||
}
|
}
|
||||||
void* XGDMatrixSliceDMatrix(void *handle,
|
return p_mat;
|
||||||
const int *idxset,
|
}
|
||||||
bst_ulong len) {
|
void* XGDMatrixSliceDMatrix(void *handle,
|
||||||
DMatrixSimple tmp;
|
const int *idxset,
|
||||||
DataMatrix &dsrc = *static_cast<DataMatrix*>(handle);
|
bst_ulong len) {
|
||||||
if (dsrc.magic != DMatrixSimple::kMagic) {
|
DMatrixSimple tmp;
|
||||||
tmp.CopyFrom(dsrc);
|
DataMatrix &dsrc = *static_cast<DataMatrix*>(handle);
|
||||||
}
|
if (dsrc.magic != DMatrixSimple::kMagic) {
|
||||||
DataMatrix &src = (dsrc.magic == DMatrixSimple::kMagic ?
|
tmp.CopyFrom(dsrc);
|
||||||
*static_cast<DMatrixSimple*>(handle): tmp);
|
}
|
||||||
DMatrixSimple *p_ret = new DMatrixSimple();
|
DataMatrix &src = (dsrc.magic == DMatrixSimple::kMagic ?
|
||||||
DMatrixSimple &ret = *p_ret;
|
*static_cast<DMatrixSimple*>(handle): tmp);
|
||||||
|
DMatrixSimple *p_ret = new DMatrixSimple();
|
||||||
|
DMatrixSimple &ret = *p_ret;
|
||||||
|
|
||||||
utils::Check(src.info.group_ptr.size() == 0,
|
utils::Check(src.info.group_ptr.size() == 0,
|
||||||
"slice does not support group structure");
|
"slice does not support group structure");
|
||||||
ret.Clear();
|
ret.Clear();
|
||||||
ret.info.info.num_row = len;
|
ret.info.info.num_row = len;
|
||||||
ret.info.info.num_col = src.info.num_col();
|
ret.info.info.num_col = src.info.num_col();
|
||||||
|
|
||||||
utils::IIterator<RowBatch> *iter = src.fmat()->RowIterator();
|
utils::IIterator<RowBatch> *iter = src.fmat()->RowIterator();
|
||||||
iter->BeforeFirst();
|
iter->BeforeFirst();
|
||||||
utils::Assert(iter->Next(), "slice");
|
utils::Assert(iter->Next(), "slice");
|
||||||
const RowBatch &batch = iter->Value();
|
const RowBatch &batch = iter->Value();
|
||||||
for (bst_ulong i = 0; i < len; ++i) {
|
for (bst_ulong i = 0; i < len; ++i) {
|
||||||
const int ridx = idxset[i];
|
const int ridx = idxset[i];
|
||||||
RowBatch::Inst inst = batch[ridx];
|
RowBatch::Inst inst = batch[ridx];
|
||||||
utils::Check(static_cast<bst_ulong>(ridx) < batch.size, "slice index exceed number of rows");
|
utils::Check(static_cast<bst_ulong>(ridx) < batch.size, "slice index exceed number of rows");
|
||||||
ret.row_data_.resize(ret.row_data_.size() + inst.length);
|
ret.row_data_.resize(ret.row_data_.size() + inst.length);
|
||||||
memcpy(&ret.row_data_[ret.row_ptr_.back()], inst.data,
|
memcpy(&ret.row_data_[ret.row_ptr_.back()], inst.data,
|
||||||
sizeof(RowBatch::Entry) * inst.length);
|
sizeof(RowBatch::Entry) * inst.length);
|
||||||
ret.row_ptr_.push_back(ret.row_ptr_.back() + inst.length);
|
ret.row_ptr_.push_back(ret.row_ptr_.back() + inst.length);
|
||||||
if (src.info.labels.size() != 0) {
|
if (src.info.labels.size() != 0) {
|
||||||
ret.info.labels.push_back(src.info.labels[ridx]);
|
ret.info.labels.push_back(src.info.labels[ridx]);
|
||||||
}
|
|
||||||
if (src.info.weights.size() != 0) {
|
|
||||||
ret.info.weights.push_back(src.info.weights[ridx]);
|
|
||||||
}
|
|
||||||
if (src.info.info.root_index.size() != 0) {
|
|
||||||
ret.info.info.root_index.push_back(src.info.info.root_index[ridx]);
|
|
||||||
}
|
|
||||||
if (src.info.info.fold_index.size() != 0) {
|
|
||||||
ret.info.info.fold_index.push_back(src.info.info.fold_index[ridx]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return p_ret;
|
if (src.info.weights.size() != 0) {
|
||||||
}
|
ret.info.weights.push_back(src.info.weights[ridx]);
|
||||||
void XGDMatrixFree(void *handle) {
|
}
|
||||||
delete static_cast<DataMatrix*>(handle);
|
if (src.info.info.root_index.size() != 0) {
|
||||||
}
|
ret.info.info.root_index.push_back(src.info.info.root_index[ridx]);
|
||||||
void XGDMatrixSaveBinary(void *handle, const char *fname, int silent) {
|
}
|
||||||
SaveDataMatrix(*static_cast<DataMatrix*>(handle), fname, silent != 0);
|
if (src.info.info.fold_index.size() != 0) {
|
||||||
}
|
ret.info.info.fold_index.push_back(src.info.info.fold_index[ridx]);
|
||||||
void XGDMatrixSetFloatInfo(void *handle, const char *field, const float *info, bst_ulong len) {
|
|
||||||
std::vector<float> &vec =
|
|
||||||
static_cast<DataMatrix*>(handle)->info.GetFloatInfo(field);
|
|
||||||
vec.resize(len);
|
|
||||||
memcpy(BeginPtr(vec), info, sizeof(float) * len);
|
|
||||||
}
|
|
||||||
void XGDMatrixSetUIntInfo(void *handle, const char *field, const unsigned *info, bst_ulong len) {
|
|
||||||
std::vector<unsigned> &vec =
|
|
||||||
static_cast<DataMatrix*>(handle)->info.GetUIntInfo(field);
|
|
||||||
vec.resize(len);
|
|
||||||
memcpy(BeginPtr(vec), info, sizeof(unsigned) * len);
|
|
||||||
}
|
|
||||||
void XGDMatrixSetGroup(void *handle, const unsigned *group, bst_ulong len) {
|
|
||||||
DataMatrix *pmat = static_cast<DataMatrix*>(handle);
|
|
||||||
pmat->info.group_ptr.resize(len + 1);
|
|
||||||
pmat->info.group_ptr[0] = 0;
|
|
||||||
for (uint64_t i = 0; i < len; ++i) {
|
|
||||||
pmat->info.group_ptr[i+1] = pmat->info.group_ptr[i] + group[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const float* XGDMatrixGetFloatInfo(const void *handle, const char *field, bst_ulong* len) {
|
return p_ret;
|
||||||
const std::vector<float> &vec =
|
}
|
||||||
static_cast<const DataMatrix*>(handle)->info.GetFloatInfo(field);
|
void XGDMatrixFree(void *handle) {
|
||||||
*len = static_cast<bst_ulong>(vec.size());
|
delete static_cast<DataMatrix*>(handle);
|
||||||
return BeginPtr(vec);
|
}
|
||||||
}
|
void XGDMatrixSaveBinary(void *handle, const char *fname, int silent) {
|
||||||
const unsigned* XGDMatrixGetUIntInfo(const void *handle, const char *field, bst_ulong* len) {
|
SaveDataMatrix(*static_cast<DataMatrix*>(handle), fname, silent != 0);
|
||||||
const std::vector<unsigned> &vec =
|
}
|
||||||
static_cast<const DataMatrix*>(handle)->info.GetUIntInfo(field);
|
void XGDMatrixSetFloatInfo(void *handle, const char *field, const float *info, bst_ulong len) {
|
||||||
*len = static_cast<bst_ulong>(vec.size());
|
std::vector<float> &vec =
|
||||||
return BeginPtr(vec);
|
static_cast<DataMatrix*>(handle)->info.GetFloatInfo(field);
|
||||||
}
|
vec.resize(len);
|
||||||
bst_ulong XGDMatrixNumRow(const void *handle) {
|
memcpy(BeginPtr(vec), info, sizeof(float) * len);
|
||||||
return static_cast<bst_ulong>(static_cast<const DataMatrix*>(handle)->info.num_row());
|
}
|
||||||
}
|
void XGDMatrixSetUIntInfo(void *handle, const char *field, const unsigned *info, bst_ulong len) {
|
||||||
|
std::vector<unsigned> &vec =
|
||||||
// xgboost implementation
|
static_cast<DataMatrix*>(handle)->info.GetUIntInfo(field);
|
||||||
void *XGBoosterCreate(void *dmats[], bst_ulong len) {
|
vec.resize(len);
|
||||||
std::vector<DataMatrix*> mats;
|
memcpy(BeginPtr(vec), info, sizeof(unsigned) * len);
|
||||||
for (bst_ulong i = 0; i < len; ++i) {
|
}
|
||||||
DataMatrix *dtr = static_cast<DataMatrix*>(dmats[i]);
|
void XGDMatrixSetGroup(void *handle, const unsigned *group, bst_ulong len) {
|
||||||
mats.push_back(dtr);
|
DataMatrix *pmat = static_cast<DataMatrix*>(handle);
|
||||||
}
|
pmat->info.group_ptr.resize(len + 1);
|
||||||
return new Booster(mats);
|
pmat->info.group_ptr[0] = 0;
|
||||||
}
|
for (uint64_t i = 0; i < len; ++i) {
|
||||||
void XGBoosterFree(void *handle) {
|
pmat->info.group_ptr[i+1] = pmat->info.group_ptr[i] + group[i];
|
||||||
delete static_cast<Booster*>(handle);
|
|
||||||
}
|
|
||||||
void XGBoosterSetParam(void *handle, const char *name, const char *value) {
|
|
||||||
static_cast<Booster*>(handle)->SetParam(name, value);
|
|
||||||
}
|
|
||||||
void XGBoosterUpdateOneIter(void *handle, int iter, void *dtrain) {
|
|
||||||
Booster *bst = static_cast<Booster*>(handle);
|
|
||||||
DataMatrix *dtr = static_cast<DataMatrix*>(dtrain);
|
|
||||||
bst->CheckInitModel();
|
|
||||||
bst->CheckInit(dtr);
|
|
||||||
bst->UpdateOneIter(iter, *dtr);
|
|
||||||
}
|
|
||||||
void XGBoosterBoostOneIter(void *handle, void *dtrain,
|
|
||||||
float *grad, float *hess, bst_ulong len) {
|
|
||||||
Booster *bst = static_cast<Booster*>(handle);
|
|
||||||
DataMatrix *dtr = static_cast<DataMatrix*>(dtrain);
|
|
||||||
bst->CheckInitModel();
|
|
||||||
bst->CheckInit(dtr);
|
|
||||||
bst->BoostOneIter(*dtr, grad, hess, len);
|
|
||||||
}
|
|
||||||
const char* XGBoosterEvalOneIter(void *handle, int iter, void *dmats[],
|
|
||||||
const char *evnames[], bst_ulong len) {
|
|
||||||
Booster *bst = static_cast<Booster*>(handle);
|
|
||||||
std::vector<std::string> names;
|
|
||||||
std::vector<const DataMatrix*> mats;
|
|
||||||
for (bst_ulong i = 0; i < len; ++i) {
|
|
||||||
mats.push_back(static_cast<DataMatrix*>(dmats[i]));
|
|
||||||
names.push_back(std::string(evnames[i]));
|
|
||||||
}
|
|
||||||
bst->CheckInitModel();
|
|
||||||
bst->eval_str = bst->EvalOneIter(iter, mats, names);
|
|
||||||
return bst->eval_str.c_str();
|
|
||||||
}
|
|
||||||
const float *XGBoosterPredict(void *handle, void *dmat, int option_mask, unsigned ntree_limit, bst_ulong *len) {
|
|
||||||
return static_cast<Booster*>(handle)->Pred(*static_cast<DataMatrix*>(dmat), option_mask, ntree_limit, len);
|
|
||||||
}
|
|
||||||
void XGBoosterLoadModel(void *handle, const char *fname) {
|
|
||||||
static_cast<Booster*>(handle)->LoadModel(fname);
|
|
||||||
}
|
|
||||||
void XGBoosterSaveModel(void *handle, const char *fname) {
|
|
||||||
Booster *bst = static_cast<Booster*>(handle);
|
|
||||||
bst->CheckInitModel();
|
|
||||||
bst->SaveModel(fname, false);
|
|
||||||
}
|
|
||||||
void XGBoosterLoadModelFromBuffer(void *handle, const void *buf, bst_ulong len) {
|
|
||||||
static_cast<Booster*>(handle)->LoadModelFromBuffer(buf, len);
|
|
||||||
}
|
|
||||||
const char *XGBoosterGetModelRaw(void *handle, bst_ulong *out_len) {
|
|
||||||
return static_cast<Booster*>(handle)->GetModelRaw(out_len);
|
|
||||||
}
|
|
||||||
const char** XGBoosterDumpModel(void *handle, const char *fmap, int with_stats, bst_ulong *len){
|
|
||||||
utils::FeatMap featmap;
|
|
||||||
if (strlen(fmap) != 0) {
|
|
||||||
featmap.LoadText(fmap);
|
|
||||||
}
|
|
||||||
return static_cast<Booster*>(handle)->GetModelDump(featmap, with_stats != 0, len);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const float* XGDMatrixGetFloatInfo(const void *handle, const char *field, bst_ulong* len) {
|
||||||
|
const std::vector<float> &vec =
|
||||||
|
static_cast<const DataMatrix*>(handle)->info.GetFloatInfo(field);
|
||||||
|
*len = static_cast<bst_ulong>(vec.size());
|
||||||
|
return BeginPtr(vec);
|
||||||
|
}
|
||||||
|
const unsigned* XGDMatrixGetUIntInfo(const void *handle, const char *field, bst_ulong* len) {
|
||||||
|
const std::vector<unsigned> &vec =
|
||||||
|
static_cast<const DataMatrix*>(handle)->info.GetUIntInfo(field);
|
||||||
|
*len = static_cast<bst_ulong>(vec.size());
|
||||||
|
return BeginPtr(vec);
|
||||||
|
}
|
||||||
|
bst_ulong XGDMatrixNumRow(const void *handle) {
|
||||||
|
return static_cast<bst_ulong>(static_cast<const DataMatrix*>(handle)->info.num_row());
|
||||||
|
}
|
||||||
|
|
||||||
|
// xgboost implementation
|
||||||
|
void *XGBoosterCreate(void *dmats[], bst_ulong len) {
|
||||||
|
std::vector<DataMatrix*> mats;
|
||||||
|
for (bst_ulong i = 0; i < len; ++i) {
|
||||||
|
DataMatrix *dtr = static_cast<DataMatrix*>(dmats[i]);
|
||||||
|
mats.push_back(dtr);
|
||||||
|
}
|
||||||
|
return new Booster(mats);
|
||||||
|
}
|
||||||
|
void XGBoosterFree(void *handle) {
|
||||||
|
delete static_cast<Booster*>(handle);
|
||||||
|
}
|
||||||
|
void XGBoosterSetParam(void *handle, const char *name, const char *value) {
|
||||||
|
static_cast<Booster*>(handle)->SetParam(name, value);
|
||||||
|
}
|
||||||
|
void XGBoosterUpdateOneIter(void *handle, int iter, void *dtrain) {
|
||||||
|
Booster *bst = static_cast<Booster*>(handle);
|
||||||
|
DataMatrix *dtr = static_cast<DataMatrix*>(dtrain);
|
||||||
|
bst->CheckInitModel();
|
||||||
|
bst->CheckInit(dtr);
|
||||||
|
bst->UpdateOneIter(iter, *dtr);
|
||||||
|
}
|
||||||
|
void XGBoosterBoostOneIter(void *handle, void *dtrain,
|
||||||
|
float *grad, float *hess, bst_ulong len) {
|
||||||
|
Booster *bst = static_cast<Booster*>(handle);
|
||||||
|
DataMatrix *dtr = static_cast<DataMatrix*>(dtrain);
|
||||||
|
bst->CheckInitModel();
|
||||||
|
bst->CheckInit(dtr);
|
||||||
|
bst->BoostOneIter(*dtr, grad, hess, len);
|
||||||
|
}
|
||||||
|
const char* XGBoosterEvalOneIter(void *handle, int iter, void *dmats[],
|
||||||
|
const char *evnames[], bst_ulong len) {
|
||||||
|
Booster *bst = static_cast<Booster*>(handle);
|
||||||
|
std::vector<std::string> names;
|
||||||
|
std::vector<const DataMatrix*> mats;
|
||||||
|
for (bst_ulong i = 0; i < len; ++i) {
|
||||||
|
mats.push_back(static_cast<DataMatrix*>(dmats[i]));
|
||||||
|
names.push_back(std::string(evnames[i]));
|
||||||
|
}
|
||||||
|
bst->CheckInitModel();
|
||||||
|
bst->eval_str = bst->EvalOneIter(iter, mats, names);
|
||||||
|
return bst->eval_str.c_str();
|
||||||
|
}
|
||||||
|
const float *XGBoosterPredict(void *handle, void *dmat, int option_mask,
|
||||||
|
unsigned ntree_limit, bst_ulong *len) {
|
||||||
|
return static_cast<Booster*>(handle)->Pred(*static_cast<DataMatrix*>(dmat),
|
||||||
|
option_mask, ntree_limit, len);
|
||||||
|
}
|
||||||
|
void XGBoosterLoadModel(void *handle, const char *fname) {
|
||||||
|
static_cast<Booster*>(handle)->LoadModel(fname);
|
||||||
|
}
|
||||||
|
void XGBoosterSaveModel(void *handle, const char *fname) {
|
||||||
|
Booster *bst = static_cast<Booster*>(handle);
|
||||||
|
bst->CheckInitModel();
|
||||||
|
bst->SaveModel(fname, false);
|
||||||
|
}
|
||||||
|
void XGBoosterLoadModelFromBuffer(void *handle, const void *buf, bst_ulong len) {
|
||||||
|
static_cast<Booster*>(handle)->LoadModelFromBuffer(buf, len);
|
||||||
|
}
|
||||||
|
const char *XGBoosterGetModelRaw(void *handle, bst_ulong *out_len) {
|
||||||
|
return static_cast<Booster*>(handle)->GetModelRaw(out_len);
|
||||||
|
}
|
||||||
|
const char** XGBoosterDumpModel(void *handle, const char *fmap,
|
||||||
|
int with_stats, bst_ulong *len) {
|
||||||
|
utils::FeatMap featmap;
|
||||||
|
if (strlen(fmap) != 0) {
|
||||||
|
featmap.LoadText(fmap);
|
||||||
|
}
|
||||||
|
return static_cast<Booster*>(handle)->GetModelDump(featmap, with_stats != 0, len);
|
||||||
|
}
|
||||||
|
|||||||
@ -1,24 +1,26 @@
|
|||||||
#ifndef XGBOOST_WRAPPER_H_
|
|
||||||
#define XGBOOST_WRAPPER_H_
|
|
||||||
/*!
|
/*!
|
||||||
|
* Copyright (c) 2014 by Contributors
|
||||||
* \file xgboost_wrapper.h
|
* \file xgboost_wrapper.h
|
||||||
* \author Tianqi Chen
|
* \author Tianqi Chen
|
||||||
* \brief a C style wrapper of xgboost
|
* \brief a C style wrapper of xgboost
|
||||||
* can be used to create wrapper of other languages
|
* can be used to create wrapper of other languages
|
||||||
*/
|
*/
|
||||||
|
#ifndef XGBOOST_WRAPPER_H_
|
||||||
|
#define XGBOOST_WRAPPER_H_
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(_WIN32)
|
#if defined(_MSC_VER) || defined(_WIN32)
|
||||||
#define XGB_DLL __declspec(dllexport)
|
#define XGB_DLL __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define XGB_DLL
|
#define XGB_DLL
|
||||||
#endif
|
#endif
|
||||||
// manually define unsign long
|
// manually define unsign long
|
||||||
typedef unsigned long bst_ulong;
|
typedef unsigned long bst_ulong; // NOLINT(*)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
/*!
|
/*!
|
||||||
* \brief load a data matrix
|
* \brief load a data matrix
|
||||||
* \param fname the name of the file
|
* \param fname the name of the file
|
||||||
* \param silent whether print messages during loading
|
* \param silent whether print messages during loading
|
||||||
* \return a loaded data matrix
|
* \return a loaded data matrix
|
||||||
@ -29,7 +31,7 @@ extern "C" {
|
|||||||
* \param indptr pointer to row headers
|
* \param indptr pointer to row headers
|
||||||
* \param indices findex
|
* \param indices findex
|
||||||
* \param data fvalue
|
* \param data fvalue
|
||||||
* \param nindptr number of rows in the matix + 1
|
* \param nindptr number of rows in the matix + 1
|
||||||
* \param nelem number of nonzero elements in the matrix
|
* \param nelem number of nonzero elements in the matrix
|
||||||
* \return created dmatrix
|
* \return created dmatrix
|
||||||
*/
|
*/
|
||||||
@ -51,7 +53,7 @@ extern "C" {
|
|||||||
const unsigned *indices,
|
const unsigned *indices,
|
||||||
const float *data,
|
const float *data,
|
||||||
bst_ulong nindptr,
|
bst_ulong nindptr,
|
||||||
bst_ulong nelem);
|
bst_ulong nelem);
|
||||||
/*!
|
/*!
|
||||||
* \brief create matrix content from dense matrix
|
* \brief create matrix content from dense matrix
|
||||||
* \param data pointer to the data space
|
* \param data pointer to the data space
|
||||||
@ -92,7 +94,8 @@ extern "C" {
|
|||||||
* \param array pointer to float vector
|
* \param array pointer to float vector
|
||||||
* \param len length of array
|
* \param len length of array
|
||||||
*/
|
*/
|
||||||
XGB_DLL void XGDMatrixSetFloatInfo(void *handle, const char *field, const float *array, bst_ulong len);
|
XGB_DLL void XGDMatrixSetFloatInfo(void *handle, const char *field,
|
||||||
|
const float *array, bst_ulong len);
|
||||||
/*!
|
/*!
|
||||||
* \brief set uint32 vector to a content in info
|
* \brief set uint32 vector to a content in info
|
||||||
* \param handle a instance of data matrix
|
* \param handle a instance of data matrix
|
||||||
@ -100,7 +103,8 @@ extern "C" {
|
|||||||
* \param array pointer to float vector
|
* \param array pointer to float vector
|
||||||
* \param len length of array
|
* \param len length of array
|
||||||
*/
|
*/
|
||||||
XGB_DLL void XGDMatrixSetUIntInfo(void *handle, const char *field, const unsigned *array, bst_ulong len);
|
XGB_DLL void XGDMatrixSetUIntInfo(void *handle, const char *field,
|
||||||
|
const unsigned *array, bst_ulong len);
|
||||||
/*!
|
/*!
|
||||||
* \brief set label of the training matrix
|
* \brief set label of the training matrix
|
||||||
* \param handle a instance of data matrix
|
* \param handle a instance of data matrix
|
||||||
@ -115,7 +119,8 @@ extern "C" {
|
|||||||
* \param out_len used to set result length
|
* \param out_len used to set result length
|
||||||
* \return pointer to the result
|
* \return pointer to the result
|
||||||
*/
|
*/
|
||||||
XGB_DLL const float* XGDMatrixGetFloatInfo(const void *handle, const char *field, bst_ulong* out_len);
|
XGB_DLL const float* XGDMatrixGetFloatInfo(const void *handle,
|
||||||
|
const char *field, bst_ulong* out_len);
|
||||||
/*!
|
/*!
|
||||||
* \brief get uint32 info vector from matrix
|
* \brief get uint32 info vector from matrix
|
||||||
* \param handle a instance of data matrix
|
* \param handle a instance of data matrix
|
||||||
@ -123,31 +128,32 @@ extern "C" {
|
|||||||
* \param out_len used to set result length
|
* \param out_len used to set result length
|
||||||
* \return pointer to the result
|
* \return pointer to the result
|
||||||
*/
|
*/
|
||||||
XGB_DLL const unsigned* XGDMatrixGetUIntInfo(const void *handle, const char *field, bst_ulong* out_len);
|
XGB_DLL const unsigned* XGDMatrixGetUIntInfo(const void *handle,
|
||||||
|
const char *field, bst_ulong* out_len);
|
||||||
/*!
|
/*!
|
||||||
* \brief return number of rows
|
* \brief return number of rows
|
||||||
*/
|
*/
|
||||||
XGB_DLL bst_ulong XGDMatrixNumRow(const void *handle);
|
XGB_DLL bst_ulong XGDMatrixNumRow(const void *handle);
|
||||||
// --- start XGBoost class
|
// --- start XGBoost class
|
||||||
/*!
|
/*!
|
||||||
* \brief create xgboost learner
|
* \brief create xgboost learner
|
||||||
* \param dmats matrices that are set to be cached
|
* \param dmats matrices that are set to be cached
|
||||||
* \param len length of dmats
|
* \param len length of dmats
|
||||||
*/
|
*/
|
||||||
XGB_DLL void *XGBoosterCreate(void* dmats[], bst_ulong len);
|
XGB_DLL void *XGBoosterCreate(void* dmats[], bst_ulong len);
|
||||||
/*!
|
/*!
|
||||||
* \brief free obj in handle
|
* \brief free obj in handle
|
||||||
* \param handle handle to be freed
|
* \param handle handle to be freed
|
||||||
*/
|
*/
|
||||||
XGB_DLL void XGBoosterFree(void* handle);
|
XGB_DLL void XGBoosterFree(void* handle);
|
||||||
/*!
|
/*!
|
||||||
* \brief set parameters
|
* \brief set parameters
|
||||||
* \param handle handle
|
* \param handle handle
|
||||||
* \param name parameter name
|
* \param name parameter name
|
||||||
* \param val value of parameter
|
* \param val value of parameter
|
||||||
*/
|
*/
|
||||||
XGB_DLL void XGBoosterSetParam(void *handle, const char *name, const char *value);
|
XGB_DLL void XGBoosterSetParam(void *handle, const char *name, const char *value);
|
||||||
/*!
|
/*!
|
||||||
* \brief update the model in one round using dtrain
|
* \brief update the model in one round using dtrain
|
||||||
* \param handle handle
|
* \param handle handle
|
||||||
* \param iter current iteration rounds
|
* \param iter current iteration rounds
|
||||||
@ -188,8 +194,8 @@ extern "C" {
|
|||||||
* when the parameter is set to 0, we will use all the trees
|
* when the parameter is set to 0, we will use all the trees
|
||||||
* \param len used to store length of returning result
|
* \param len used to store length of returning result
|
||||||
*/
|
*/
|
||||||
XGB_DLL const float *XGBoosterPredict(void *handle, void *dmat,
|
XGB_DLL const float *XGBoosterPredict(void *handle, void *dmat,
|
||||||
int option_mask,
|
int option_mask,
|
||||||
unsigned ntree_limit,
|
unsigned ntree_limit,
|
||||||
bst_ulong *len);
|
bst_ulong *len);
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user