fix all cpp lint

This commit is contained in:
tqchen 2015-07-03 19:42:44 -07:00
parent 1123253f79
commit 57ec922214
5 changed files with 302 additions and 288 deletions

View File

@ -1,3 +1,4 @@
// Copyright (c) 2014 by Contributors
#include <vector>
#include <string>
#include <utility>

View File

@ -1,10 +1,12 @@
#ifndef XGBOOST_WRAPPER_R_H_
#define XGBOOST_WRAPPER_R_H_
/*!
* Copyright 2014 (c) by Contributors
* \file xgboost_wrapper_R.h
* \author Tianqi Chen
* \brief R wrapper of xgboost
*/
#ifndef XGBOOST_WRAPPER_R_H_ // NOLINT(*)
#define XGBOOST_WRAPPER_R_H_ // NOLINT(*)
extern "C" {
#include <Rinternals.h>
#include <R_ext/Random.h>
@ -153,4 +155,4 @@ extern "C" {
*/
SEXP XGBoosterDumpModel_R(SEXP handle, SEXP fmap, SEXP with_stats);
}
#endif // XGBOOST_WRAPPER_R_H_
#endif // XGBOOST_WRAPPER_R_H_ // NOLINT(*)

View File

@ -1,3 +1,4 @@
// Copyright (c) 2014 by Contributors
#include <stdio.h>
#include <stdarg.h>
#include <Rinternals.h>

View File

@ -1,3 +1,4 @@
// Copyright (c) 2014 by Contributors
// implementations in ctypes
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
@ -31,9 +32,11 @@ class Booster: public learner::BoostLearner {
this->init_model = false;
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->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());
return BeginPtr(this->preds_);
}
@ -57,7 +60,7 @@ class Booster: public learner::BoostLearner {
this->init_model = true;
}
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);
this->init_model = true;
}
@ -99,7 +102,6 @@ class Booster: public learner::BoostLearner {
using namespace xgboost::wrapper;
extern "C"{
void* XGDMatrixCreateFromFile(const char *fname, int silent) {
return LoadDataMatrix(fname, silent != 0, false, false);
}
@ -123,7 +125,7 @@ extern "C"{
mat.info.info.num_row = nindptr - 1;
return p_mat;
}
XGB_DLL void* XGDMatrixCreateFromCSC(const bst_ulong *col_ptr,
void* XGDMatrixCreateFromCSC(const bst_ulong *col_ptr,
const unsigned *indices,
const float *data,
bst_ulong nindptr,
@ -138,9 +140,9 @@ extern "C"{
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);
long ncol = static_cast<long>(nindptr - 1); // NOLINT(*)
#pragma omp parallel for schedule(static)
for (long i = 0; i < ncol; ++i) {
for (long i = 0; i < ncol; ++i) { // NOLINT(*)
int tid = omp_get_thread_num();
for (unsigned j = col_ptr[i]; j < col_ptr[i+1]; ++j) {
builder.AddBudget(indices[j], tid);
@ -148,7 +150,7 @@ extern "C"{
}
builder.InitStorage();
#pragma omp parallel for schedule(static)
for (long i = 0; i < ncol; ++i) {
for (long i = 0; i < ncol; ++i) { // NOLINT(*)
int tid = omp_get_thread_num();
for (unsigned j = col_ptr[i]; j < col_ptr[i+1]; ++j) {
builder.Push(indices[j],
@ -317,8 +319,10 @@ extern "C"{
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);
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);
@ -334,11 +338,11 @@ extern "C"{
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){
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);
}
}

View File

@ -1,18 +1,20 @@
#ifndef XGBOOST_WRAPPER_H_
#define XGBOOST_WRAPPER_H_
/*!
* Copyright (c) 2014 by Contributors
* \file xgboost_wrapper.h
* \author Tianqi Chen
* \brief a C style wrapper of xgboost
* can be used to create wrapper of other languages
*/
#ifndef XGBOOST_WRAPPER_H_
#define XGBOOST_WRAPPER_H_
#if defined(_MSC_VER) || defined(_WIN32)
#define XGB_DLL __declspec(dllexport)
#else
#define XGB_DLL
#endif
// manually define unsign long
typedef unsigned long bst_ulong;
typedef unsigned long bst_ulong; // NOLINT(*)
#ifdef __cplusplus
extern "C" {
@ -92,7 +94,8 @@ extern "C" {
* \param array pointer to float vector
* \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
* \param handle a instance of data matrix
@ -100,7 +103,8 @@ extern "C" {
* \param array pointer to float vector
* \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
* \param handle a instance of data matrix
@ -115,7 +119,8 @@ extern "C" {
* \param out_len used to set result length
* \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
* \param handle a instance of data matrix
@ -123,7 +128,8 @@ extern "C" {
* \param out_len used to set result length
* \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
*/