change omp loop var to bst_omp_uint, add XGB_DLL to wrapper

This commit is contained in:
tqchen
2014-08-26 19:37:04 -07:00
parent 97467fe807
commit 7739f57c8b
13 changed files with 100 additions and 88 deletions

View File

@@ -213,7 +213,7 @@ extern "C" {
&olen);
FILE *fo = utils::FopenCheck(CHAR(asChar(fname)), "w");
for (size_t i = 0; i < olen; ++i) {
fprintf(fo, "booster[%lu]:\n", i);
fprintf(fo, "booster[%u]:\n", static_cast<unsigned>(i));
fprintf(fo, "%s", res[i]);
}
fclose(fo);

View File

@@ -32,9 +32,9 @@ class Booster: public learner::BoostLearner<FMatrixS> {
inline void BoostOneIter(const DataMatrix &train,
float *grad, float *hess, uint64_t len) {
this->gpair_.resize(len);
const unsigned ndata = static_cast<unsigned>(len);
const bst_omp_uint ndata = static_cast<bst_omp_uint>(len);
#pragma omp parallel for schedule(static)
for (unsigned j = 0; j < ndata; ++j) {
for (bst_omp_uint j = 0; j < ndata; ++j) {
gpair_[j] = bst_gpair(grad[j], hess[j]);
}
gbm_->DoBoost(train.fmat, train.info.info, &gpair_);

View File

@@ -9,13 +9,14 @@
#include <cstdio>
// define uint64_t to be unsigned long
typedef unsigned long uint64_t;
#define XGB_DLL
extern "C" {
/*!
* \brief load a data matrix
* \return a loaded data matrix
*/
void* XGDMatrixCreateFromFile(const char *fname, int silent);
XGB_DLL void* XGDMatrixCreateFromFile(const char *fname, int silent);
/*!
* \brief create a matrix content from csr format
* \param indptr pointer to row headers
@@ -25,11 +26,11 @@ extern "C" {
* \param nelem number of nonzero elements in the matrix
* \return created dmatrix
*/
void* XGDMatrixCreateFromCSR(const uint64_t *indptr,
const unsigned *indices,
const float *data,
uint64_t nindptr,
uint64_t nelem);
XGB_DLL void* XGDMatrixCreateFromCSR(const uint64_t *indptr,
const unsigned *indices,
const float *data,
uint64_t nindptr,
uint64_t nelem);
/*!
* \brief create matrix content from dense matrix
* \param data pointer to the data space
@@ -38,10 +39,10 @@ extern "C" {
* \param missing which value to represent missing value
* \return created dmatrix
*/
void* XGDMatrixCreateFromMat(const float *data,
uint64_t nrow,
uint64_t ncol,
float missing);
XGB_DLL void* XGDMatrixCreateFromMat(const float *data,
uint64_t nrow,
uint64_t ncol,
float missing);
/*!
* \brief create a new dmatrix from sliced content of existing matrix
* \param handle instance of data matrix to be sliced
@@ -49,20 +50,20 @@ extern "C" {
* \param len length of index set
* \return a sliced new matrix
*/
void* XGDMatrixSliceDMatrix(void *handle,
const int *idxset,
uint64_t len);
XGB_DLL void* XGDMatrixSliceDMatrix(void *handle,
const int *idxset,
uint64_t len);
/*!
* \brief free space in data matrix
*/
void XGDMatrixFree(void *handle);
XGB_DLL void XGDMatrixFree(void *handle);
/*!
* \brief load a data matrix into binary file
* \param handle a instance of data matrix
* \param fname file name
* \param silent print statistics when saving
*/
void XGDMatrixSaveBinary(void *handle, const char *fname, int silent);
XGB_DLL void XGDMatrixSaveBinary(void *handle, const char *fname, int silent);
/*!
* \brief set float vector to a content in info
* \param handle a instance of data matrix
@@ -70,7 +71,7 @@ extern "C" {
* \param array pointer to float vector
* \param len length of array
*/
void XGDMatrixSetFloatInfo(void *handle, const char *field, const float *array, uint64_t len);
XGB_DLL void XGDMatrixSetFloatInfo(void *handle, const char *field, const float *array, uint64_t len);
/*!
* \brief set uint32 vector to a content in info
* \param handle a instance of data matrix
@@ -78,14 +79,14 @@ extern "C" {
* \param array pointer to float vector
* \param len length of array
*/
void XGDMatrixSetUIntInfo(void *handle, const char *field, const unsigned *array, uint64_t len);
XGB_DLL void XGDMatrixSetUIntInfo(void *handle, const char *field, const unsigned *array, uint64_t len);
/*!
* \brief set label of the training matrix
* \param handle a instance of data matrix
* \param group pointer to group size
* \param len length of array
*/
void XGDMatrixSetGroup(void *handle, const unsigned *group, uint64_t len);
XGB_DLL void XGDMatrixSetGroup(void *handle, const unsigned *group, uint64_t len);
/*!
* \brief get float info vector from matrix
* \param handle a instance of data matrix
@@ -93,7 +94,7 @@ extern "C" {
* \param out_len used to set result length
* \return pointer to the result
*/
const float* XGDMatrixGetFloatInfo(const void *handle, const char *field, uint64_t* out_len);
XGB_DLL const float* XGDMatrixGetFloatInfo(const void *handle, const char *field, uint64_t* out_len);
/*!
* \brief get uint32 info vector from matrix
* \param handle a instance of data matrix
@@ -101,37 +102,37 @@ extern "C" {
* \param out_len used to set result length
* \return pointer to the result
*/
const unsigned* XGDMatrixGetUIntInfo(const void *handle, const char *field, uint64_t* out_len);
XGB_DLL const unsigned* XGDMatrixGetUIntInfo(const void *handle, const char *field, uint64_t* out_len);
/*!
* \brief return number of rows
*/
uint64_t XGDMatrixNumRow(const void *handle);
XGB_DLL uint64_t XGDMatrixNumRow(const void *handle);
// --- start XGBoost class
/*!
* \brief create xgboost learner
* \param dmats matrices that are set to be cached
* \param len length of dmats
*/
void *XGBoosterCreate(void* dmats[], uint64_t len);
XGB_DLL void *XGBoosterCreate(void* dmats[], uint64_t len);
/*!
* \brief free obj in handle
* \param handle handle to be freed
*/
void XGBoosterFree(void* handle);
XGB_DLL void XGBoosterFree(void* handle);
/*!
* \brief set parameters
* \param handle handle
* \param name parameter name
* \param val value of parameter
*/
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
* \param handle handle
* \param iter current iteration rounds
* \param dtrain training data
*/
void XGBoosterUpdateOneIter(void *handle, int iter, void *dtrain);
XGB_DLL void XGBoosterUpdateOneIter(void *handle, int iter, void *dtrain);
/*!
* \brief update the model, by directly specify gradient and second order gradient,
* this can be used to replace UpdateOneIter, to support customized loss function
@@ -141,8 +142,8 @@ extern "C" {
* \param hess second order gradient statistics
* \param len length of grad/hess array
*/
void XGBoosterBoostOneIter(void *handle, void *dtrain,
float *grad, float *hess, uint64_t len);
XGB_DLL void XGBoosterBoostOneIter(void *handle, void *dtrain,
float *grad, float *hess, uint64_t len);
/*!
* \brief get evaluation statistics for xgboost
* \param handle handle
@@ -152,8 +153,8 @@ extern "C" {
* \param len length of dmats
* \return the string containing evaluation stati
*/
const char *XGBoosterEvalOneIter(void *handle, int iter, void *dmats[],
const char *evnames[], uint64_t len);
XGB_DLL const char *XGBoosterEvalOneIter(void *handle, int iter, void *dmats[],
const char *evnames[], uint64_t len);
/*!
* \brief make prediction based on dmat
* \param handle handle
@@ -161,19 +162,19 @@ extern "C" {
* \param output_margin whether only output raw margin value
* \param len used to store length of returning result
*/
const float *XGBoosterPredict(void *handle, void *dmat, int output_margin, uint64_t *len);
XGB_DLL const float *XGBoosterPredict(void *handle, void *dmat, int output_margin, uint64_t *len);
/*!
* \brief load model from existing file
* \param handle handle
* \param fname file name
*/
void XGBoosterLoadModel(void *handle, const char *fname);
XGB_DLL void XGBoosterLoadModel(void *handle, const char *fname);
/*!
* \brief save model into existing file
* \param handle handle
* \param fname file name
*/
void XGBoosterSaveModel(const void *handle, const char *fname);
XGB_DLL void XGBoosterSaveModel(const void *handle, const char *fname);
/*!
* \brief dump model, return array of strings representing model dump
* \param handle handle
@@ -181,7 +182,7 @@ extern "C" {
* \param out_len length of output array
* \return char *data[], representing dump of each model
*/
const char **XGBoosterDumpModel(void *handle, const char *fmap,
uint64_t *out_len);
XGB_DLL const char **XGBoosterDumpModel(void *handle, const char *fmap,
uint64_t *out_len);
};
#endif // XGBOOST_WRAPPER_H_