important change to regrank interface, need some more test
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
export CC = gcc
|
||||
export CXX = g++
|
||||
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fopenmp
|
||||
export CFLAGS = -Wall -msse2 -Wno-unknown-pragmas -fopenmp
|
||||
|
||||
# specify tensor path
|
||||
SLIB = xgboostpy.so
|
||||
OBJ = xgboost_python.o
|
||||
SLIB = libxgboostpy.so
|
||||
.PHONY: clean all
|
||||
|
||||
all: $(SLIB)
|
||||
export LDFLAGS= -pthread -lm
|
||||
|
||||
xgboostpy.so: xgboost_python.cpp ../regrank/*.h ../booster/*.h ../booster/*/*.hpp ../booster/*.hpp
|
||||
libxgboostpy.so: xgboost_python.cpp ../regrank/*.h ../booster/*.h ../booster/*/*.hpp ../booster/*.hpp
|
||||
|
||||
$(SLIB) :
|
||||
$(CXX) $(CFLAGS) $(LDFLAGS) -shared -o $@ $(filter %.cpp %.o %.c, $^)
|
||||
$(CXX) $(CFLAGS) -fPIC $(LDFLAGS) -shared -o $@ $(filter %.cpp %.o %.c, $^)
|
||||
$(BIN) :
|
||||
$(CXX) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.cpp %.o %.c, $^)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import ctypes
|
||||
|
||||
# load in xgboost library
|
||||
#xglib = ctypes.cdll.LoadLibrary('./libxgboostpy.so')
|
||||
xglib = ctypes.cdll.LoadLibrary('./libxgboostpy.so')
|
||||
|
||||
# entry type of sparse matrix
|
||||
class REntry(ctypes.Structure):
|
||||
@@ -10,6 +10,13 @@ class REntry(ctypes.Structure):
|
||||
|
||||
|
||||
class DMatrix:
|
||||
def __init__(fname = None):
|
||||
self.__handle = xglib.
|
||||
|
||||
def __init__(self,fname = None):
|
||||
self.__handle = xglib.XGDMatrixCreate();
|
||||
if fname != None:
|
||||
xglib.XGDMatrixLoad(self.__handle, ctypes.c_char_p(fname), 0)
|
||||
def __del__(self):
|
||||
xglib.XGDMatrixFree(self.__handle)
|
||||
|
||||
dmata = DMatrix('xx.buffer')
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,41 @@
|
||||
#include "xgboost_python.h"
|
||||
#include "../regrank/xgboost_regrank.h"
|
||||
#include "../regrank/xgboost_regrank_data.h"
|
||||
|
||||
void* XGDMatrixCreate(void){
|
||||
return NULL;
|
||||
}
|
||||
void XGDMatrixFree(void *handle){
|
||||
}
|
||||
void XGDMatrixLoad(void *handle, const char *fname){
|
||||
}
|
||||
void XGDMatrixSaveBinary( void *handle, const char *fname ){
|
||||
}
|
||||
namespace xgboost{
|
||||
namespace python{
|
||||
class DMatrix: public regrank::DMatrix{
|
||||
public:
|
||||
// whether column is initialized
|
||||
bool init_col_;
|
||||
public:
|
||||
DMatrix(void){
|
||||
init_col_ = false;
|
||||
}
|
||||
~DMatrix(void){}
|
||||
public:
|
||||
inline void Load(const char *fname, bool silent){
|
||||
this->CacheLoad(fname, silent);
|
||||
init_col_ = this->data.HaveColAccess();
|
||||
}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
using namespace xgboost::python;
|
||||
|
||||
extern "C"{
|
||||
void* XGDMatrixCreate(void){
|
||||
return new DMatrix();
|
||||
}
|
||||
void XGDMatrixFree(void *handle){
|
||||
delete static_cast<DMatrix*>(handle);
|
||||
}
|
||||
void XGDMatrixLoad(void *handle, const char *fname, int silent){
|
||||
static_cast<DMatrix*>(handle)->Load(fname, silent!=0);
|
||||
}
|
||||
void XGDMatrixSaveBinary(void *handle, const char *fname, int silent){
|
||||
static_cast<DMatrix*>(handle)->SaveBinary(fname, silent!=0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -7,37 +7,51 @@
|
||||
* use c style interface
|
||||
*/
|
||||
#include "../booster/xgboost_data.h"
|
||||
/*! \brief type of row entry */
|
||||
typedef xgboost::booster::FMatrixS::REntry XGEntry;
|
||||
|
||||
/*!
|
||||
* \brief create a data matrix
|
||||
* \return a new data matrix
|
||||
*/
|
||||
void* XGDMatrixCreate(void);
|
||||
/*!
|
||||
* \brief free space in data matrix
|
||||
*/
|
||||
void XGDMatrixFree(void *handle);
|
||||
/*!
|
||||
* \brief load a data matrix from text file or buffer(if exists)
|
||||
* \param handle a instance of data matrix
|
||||
* \param fname file name
|
||||
*/
|
||||
void XGDMatrixLoad(void *handle, const char *fname);
|
||||
/*!
|
||||
* \brief load a data matrix into binary file
|
||||
* \param handle a instance of data matrix
|
||||
* \param fname file name
|
||||
*/
|
||||
void XGDMatrixSaveBinary( void *handle, const char *fname );
|
||||
/*!
|
||||
* \brief add row
|
||||
* \param handle a instance of data matrix
|
||||
* \param fname file name
|
||||
* \return a new data matrix
|
||||
*/
|
||||
//void XGDMatrixPush( void *handle, const std::pair<int,> );
|
||||
extern "C"{
|
||||
/*! \brief type of row entry */
|
||||
typedef xgboost::booster::FMatrixS::REntry XGEntry;
|
||||
|
||||
/*!
|
||||
* \brief create a data matrix
|
||||
* \return a new data matrix
|
||||
*/
|
||||
void* XGDMatrixCreate(void);
|
||||
/*!
|
||||
* \brief free space in data matrix
|
||||
*/
|
||||
void XGDMatrixFree(void *handle);
|
||||
/*!
|
||||
* \brief load a data matrix from text file or buffer(if exists)
|
||||
* \param handle a instance of data matrix
|
||||
* \param fname file name
|
||||
* \param silent print statistics when loading
|
||||
*/
|
||||
void XGDMatrixLoad(void *handle, const char *fname, int silent);
|
||||
/*!
|
||||
* \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);
|
||||
/*!
|
||||
* \brief add row
|
||||
* \param handle a instance of data matrix
|
||||
* \param fname file name
|
||||
* \return a new data matrix
|
||||
*/
|
||||
void XGDMatrixPush(void *handle, const XGEntry *data, int len);
|
||||
|
||||
/*!
|
||||
* \brief create a booster
|
||||
*/
|
||||
void* XGBoostCreate(void);
|
||||
|
||||
/*!
|
||||
* \brief create a booster
|
||||
*/
|
||||
void* XGBoost(void);
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user