fix python windows installation problem, enable mingw compile, but seems mingw dll was not fast in loading

This commit is contained in:
Tianqi Chen 2015-04-25 15:30:42 -07:00
parent 4275434ec5
commit 84515cd2a8
7 changed files with 59 additions and 28 deletions

View File

@ -4,6 +4,11 @@ export MPICXX = mpicxx
export LDFLAGS= -pthread -lm
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -fPIC
ifeq ($(OS), Windows_NT)
export CXX = g++ -m64
export CC = gcc -m64
endif
ifeq ($(no_omp),1)
CFLAGS += -DDISABLE_OPENMP
else
@ -33,12 +38,20 @@ else
LIBDMLC=dmlc_simple.o
endif
ifeq ($(OS), Windows_NT)
LIBRABIT = subtree/rabit/lib/librabit_empty.a
SLIB = wrapper/xgboost_wrapper.dll
else
LIBRABIT = subtree/rabit/lib/librabit.a
SLIB = wrapper/libxgboostwrapper.so
endif
# specify tensor path
BIN = xgboost
MOCKBIN = xgboost.mock
OBJ = updater.o gbm.o io.o main.o dmlc_simple.o
MPIBIN =
SLIB = wrapper/libxgboostwrapper.so
TARGET = $(BIN) $(OBJ) $(SLIB)
.PHONY: clean all mpi python Rpack
@ -52,8 +65,8 @@ dmlc_simple.o: src/io/dmlc_simple.cpp src/utils/*.h
gbm.o: src/gbm/gbm.cpp src/gbm/*.hpp src/gbm/*.h
io.o: src/io/io.cpp src/io/*.hpp src/utils/*.h src/learner/dmatrix.h src/*.h
main.o: src/xgboost_main.cpp src/utils/*.h src/*.h src/learner/*.hpp src/learner/*.h
xgboost: updater.o gbm.o io.o main.o subtree/rabit/lib/librabit.a $(LIBDMLC)
wrapper/libxgboostwrapper.so: wrapper/xgboost_wrapper.cpp src/utils/*.h src/*.h src/learner/*.hpp src/learner/*.h updater.o gbm.o io.o subtree/rabit/lib/librabit.a $(LIBDMLC)
xgboost: updater.o gbm.o io.o main.o $(LIBRABIT) $(LIBDMLC)
wrapper/xgboost_wrapper.dll wrapper/libxgboostwrapper.so: wrapper/xgboost_wrapper.cpp src/utils/*.h src/*.h src/learner/*.hpp src/learner/*.h updater.o gbm.o io.o $(LIBRABIT) $(LIBDMLC)
# dependency on rabit
subtree/rabit/lib/librabit.a: subtree/rabit/src/engine.cc
@ -72,7 +85,7 @@ $(MOCKBIN) :
$(CXX) $(CFLAGS) -o $@ $(filter %.cpp %.o %.c %.cc %.a, $^) $(LDFLAGS)
$(SLIB) :
$(CXX) $(CFLAGS) -fPIC -shared -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) $(LDFLAGS)
$(CXX) $(CFLAGS) -fPIC -shared -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) $(LDFLAGS) $(DLLFLAGS)
$(OBJ) :
$(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c %.cc, $^) )

View File

@ -343,7 +343,9 @@ class BaseMaker: public IUpdater {
// push to sketch
sketch->temp.data[sketch->temp.size] =
utils::WXQuantileSketch<bst_float, bst_float>::
Entry(rmin, rmax, wmin, last_fvalue);
Entry(static_cast<bst_float>(rmin),
static_cast<bst_float>(rmax),
static_cast<bst_float>(wmin), last_fvalue);
utils::Assert(sketch->temp.size < max_size,
"invalid maximum size max_size=%u, stemp.size=%lu\n",
max_size, sketch->temp.size);
@ -377,7 +379,9 @@ class BaseMaker: public IUpdater {
// push to sketch
sketch->temp.data[sketch->temp.size] =
utils::WXQuantileSketch<bst_float, bst_float>::
Entry(rmin, rmax, wmin, last_fvalue);
Entry(static_cast<bst_float>(rmin),
static_cast<bst_float>(rmax),
static_cast<bst_float>(wmin), last_fvalue);
++sketch->temp.size;
}
sketch->PushTemp();

View File

@ -525,7 +525,7 @@ class CQHistMaker: public HistMaker<TStats> {
if (c[0].fvalue == c[c.length-1].fvalue) {
for (size_t i = 0; i < this->qexpand.size(); ++i) {
const int nid = this->qexpand[i];
sbuilder[nid].sketch->Push(c[0].fvalue, sbuilder[nid].sum_total);
sbuilder[nid].sketch->Push(c[0].fvalue, static_cast<bst_float>(sbuilder[nid].sum_total));
}
return;
}

View File

@ -217,7 +217,7 @@ class SketchMaker: public BaseMaker {
for (size_t i = 0; i < this->qexpand.size(); ++i) {
const int nid = this->qexpand[i];
for (int k = 0; k < 3; ++k) {
sbuilder[3 * nid + k].sketch->Push(c[0].fvalue, sbuilder[3 * nid + k].sum_total);
sbuilder[3 * nid + k].sketch->Push(c[0].fvalue, static_cast<bst_float>(sbuilder[3 * nid + k].sum_total));
}
}
return;

View File

@ -7,22 +7,26 @@ class XGBoostLibraryNotFound(Exception):
pass
cur_dir = os.path.dirname(os.path.abspath(__file__))
curr_dir = os.path.dirname(os.path.abspath(__file__))
dll_path = [curr_dir]
if os.name == 'nt':
dll_path = os.path.join(cur_dir,
'../windows/x64/Release/xgboost_wrapper.dll')
else:
dll_path = os.path.join(cur_dir, 'libxgboostwrapper.so')
dll_path.append(os.path.join(curr_dir, '../windows/x64/Release/'))
if not os.path.exists(dll_path):
if os.name == 'nt':
dll_path = [os.path.join(p, 'xgboost_wrapper.dll') for p in dll_path]
else:
dll_path = [os.path.join(p, 'libxgboostwrapper.so') for p in dll_path]
lib_path = [p for p in dll_path if os.path.exists(p) and os.path.isfile(p)]
if len(lib_path) == 0:
raise XGBoostLibraryNotFound("XGBoost library not found. Did you run "
"../make?")
setup(name="xgboost",
version="0.32",
description="Python wrappers for XGBoost: eXtreme Gradient Boosting",
zip_safe=False,
py_modules=['xgboost'],
data_files=[dll_path],
data_files=[('.', [lib_path[0]])],
url="https://github.com/dmlc/xgboost")

View File

@ -26,6 +26,8 @@ try:
except ImportError:
SKLEARN_INSTALLED = False
class XGBoostLibraryNotFound(Exception):
pass
__all__ = ['DMatrix', 'CVPack', 'Booster', 'aggcv', 'cv', 'mknfold', 'train']
@ -36,14 +38,18 @@ else:
def load_xglib():
dll_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
if os.name == 'nt':
dll_path = os.path.join(dll_path, '../windows/x64/Release/xgboost_wrapper.dll')
else:
dll_path = os.path.join(dll_path, 'libxgboostwrapper.so')
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
dll_path = [curr_path]
dll_path.append(os.path.join(curr_path, '../windows/x64/Release/'))
# load the xgboost wrapper library
lib = ctypes.cdll.LoadLibrary(dll_path)
if os.name == 'nt':
dll_path = [os.path.join(p, 'xgboost_wrapper.dll') for p in dll_path]
else:
dll_path = [os.path.join(p, 'libxgboostwrapper.so') for p in dll_path]
lib_path = [p for p in dll_path if os.path.exists(p) and os.path.isfile(p)]
if len(dll_path) == 0:
raise XGBoostLibraryNotFound('cannot find find the files in the candicate path ' + str(dll_path))
lib = ctypes.cdll.LoadLibrary(lib_path[0])
# DMatrix functions
lib.XGDMatrixCreateFromFile.restype = ctypes.c_void_p
@ -762,12 +768,16 @@ def cv(params, dtrain, num_boost_round=10, nfold=3, metrics=(),
return results
# used for compatiblity without sklearn
XGBModelBase = object
XGBClassifier = object
XGBRegressor = object
if SKLEARN_INSTALLED:
XGBModelBase = BaseEstimator
XGBRegressor = RegressorMixin
XGBClassifier = ClassifierMixin
class XGBModel(BaseEstimator):
class XGBModel(XGBModelBase):
"""
Implementation of the Scikit-Learn API for XGBoost.
@ -844,7 +854,7 @@ class XGBModel(BaseEstimator):
return self._Booster.predict(testDmatrix)
class XGBClassifier(XGBModel, ClassifierMixin):
class XGBClassifier(XGBModel, XGBClassifier):
def __init__(self, max_depth=3, learning_rate=0.1, n_estimators=100, silent=True, objective="binary:logistic",
nthread=-1, gamma=0, min_child_weight=1, max_delta_step=0, subsample=1, colsample_bytree=1,
base_score=0.5, seed=0):
@ -895,5 +905,5 @@ class XGBClassifier(XGBModel, ClassifierMixin):
return np.vstack((classzero_probs, classone_probs)).transpose()
class XGBRegressor(XGBModel, RegressorMixin):
class XGBRegressor(XGBModel, XGBRegressor):
pass

View File

@ -6,7 +6,7 @@
* \brief a C style wrapper of xgboost
* can be used to create wrapper of other languages
*/
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(_WIN32)
#define XGB_DLL __declspec(dllexport)
#else
#define XGB_DLL