diff --git a/python/Makefile b/python/Makefile new file mode 100644 index 000000000..4b90f7017 --- /dev/null +++ b/python/Makefile @@ -0,0 +1,27 @@ +export CC = gcc +export CXX = g++ +export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fopenmp + +# specify tensor path +SLIB = xgboostpy.so +OBJ = xgboost_python.o +.PHONY: clean all + +all: $(SLIB) +export LDFLAGS= -pthread -lm + +xgboostpy.so: xgboost_python.cpp ../regrank/*.h ../booster/*.h ../booster/*/*.hpp ../booster/*.hpp + +$(SLIB) : + $(CXX) $(CFLAGS) $(LDFLAGS) -shared -o $@ $(filter %.cpp %.o %.c, $^) +$(BIN) : + $(CXX) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.cpp %.o %.c, $^) + +$(OBJ) : + $(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c, $^) ) + +install: + cp -f -r $(BIN) $(INSTALL_PATH) + +clean: + $(RM) $(OBJ) $(BIN) $(SLIB) *~ diff --git a/python/README.md b/python/README.md new file mode 100644 index 000000000..f3bb35401 --- /dev/null +++ b/python/README.md @@ -0,0 +1,2 @@ +beta version: +python wrapper for xgboost using ctypes diff --git a/python/xgboost.py b/python/xgboost.py new file mode 100644 index 000000000..ab7024d4d --- /dev/null +++ b/python/xgboost.py @@ -0,0 +1,15 @@ +# module for xgboost +import ctypes + +# load in xgboost library +#xglib = ctypes.cdll.LoadLibrary('./libxgboostpy.so') + +# entry type of sparse matrix +class REntry(ctypes.Structure): + _fields_ = [("findex", ctypes.c_uint), ("fvalue", ctypes.c_float) ] + + +class DMatrix: + def __init__(fname = None): + self.__handle = xglib. + diff --git a/python/xgboost_python.cpp b/python/xgboost_python.cpp new file mode 100644 index 000000000..5d020066f --- /dev/null +++ b/python/xgboost_python.cpp @@ -0,0 +1,12 @@ +#include "xgboost_python.h" + +void* XGDMatrixCreate(void){ + return NULL; +} +void XGDMatrixFree(void *handle){ +} +void XGDMatrixLoad(void *handle, const char *fname){ +} +void XGDMatrixSaveBinary( void *handle, const char *fname ){ +} + diff --git a/python/xgboost_python.h b/python/xgboost_python.h new file mode 100644 index 000000000..56af7a095 --- /dev/null +++ b/python/xgboost_python.h @@ -0,0 +1,43 @@ +#ifndef XGBOOST_PYTHON_H +#define XGBOOST_PYTHON_H +/*! + * \file xgboost_regrank_data.h + * \brief python wrapper for xgboost, using ctypes, + * hides everything behind functions + * 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 ); + +#endif +