try add R wrapper
This commit is contained in:
parent
9d210f9bd3
commit
5e23f6577f
2
python/xgboost.R
Normal file
2
python/xgboost.R
Normal file
@ -0,0 +1,2 @@
|
||||
#su
|
||||
dyn.load()
|
||||
19
python/xgboost_wrapper_R.cpp
Normal file
19
python/xgboost_wrapper_R.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "xgboost_wrapper_R.h"
|
||||
#include "xgboost_wrapper.h"
|
||||
#include "../src/utils/utils.h"
|
||||
using namespace xgboost;
|
||||
|
||||
extern "C" {
|
||||
void _DMatrixFinalizer(SEXP ext) {
|
||||
if (R_ExternalPtrAddr(ext) == NULL) return;
|
||||
XGDMatrixFree(R_ExternalPtrAddr(ext));
|
||||
R_ClearExternalPtr(ext);
|
||||
}
|
||||
SEXP XGDMatrixCreateFromFile_R(SEXP fname) {
|
||||
void *handle = XGDMatrixCreateFromFile(CHAR(asChar(fname)), 0);
|
||||
SEXP ret = PROTECT(R_MakeExternalPtr(handle, R_NilValue, R_NilValue));
|
||||
R_RegisterCFinalizerEx(ret, _DMatrixFinalizer, TRUE);
|
||||
UNPROTECT(1);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
20
python/xgboost_wrapper_R.h
Normal file
20
python/xgboost_wrapper_R.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef XGBOOST_WRAPPER_R_H_
|
||||
#define XGBOOST_WRAPPER_R_H_
|
||||
/*!
|
||||
* \file xgboost_wrapper_R.h
|
||||
* \author Tianqi Chen
|
||||
* \brief R wrapper of xgboost
|
||||
*/
|
||||
extern "C" {
|
||||
#include <Rinternals.h>
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
/*!
|
||||
* \brief load a data matrix
|
||||
* \return a loaded data matrix
|
||||
*/
|
||||
SEXP XGDMatrixCreateFromFile_R(SEXP fname);
|
||||
|
||||
};
|
||||
#endif // XGBOOST_WRAPPER_H_
|
||||
Loading…
x
Reference in New Issue
Block a user