fix compilation on mac
This commit is contained in:
parent
b381c842f1
commit
46d41a2b43
9
Makefile
9
Makefile
@ -3,7 +3,6 @@ export CXX = g++
|
|||||||
export LDFLAGS= -pthread -lm
|
export LDFLAGS= -pthread -lm
|
||||||
# note for R module
|
# note for R module
|
||||||
# add include path to Rinternals.h here
|
# add include path to Rinternals.h here
|
||||||
export CPLUS_INCLUDE_PATH=/usr/share/R/include
|
|
||||||
|
|
||||||
ifeq ($(no_omp),1)
|
ifeq ($(no_omp),1)
|
||||||
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -DDISABLE_OPENMP
|
export CFLAGS = -Wall -O3 -msse2 -Wno-unknown-pragmas -DDISABLE_OPENMP
|
||||||
@ -14,7 +13,8 @@ endif
|
|||||||
# specify tensor path
|
# specify tensor path
|
||||||
BIN = xgboost
|
BIN = xgboost
|
||||||
OBJ =
|
OBJ =
|
||||||
SLIB = wrapper/libxgboostwrapper.so wrapper/libxgboostR.so
|
SLIB = wrapper/libxgboostwrapper.so
|
||||||
|
RLIB = wrapper/libxgboostR.so
|
||||||
.PHONY: clean all R
|
.PHONY: clean all R
|
||||||
|
|
||||||
all: $(BIN) wrapper/libxgboostwrapper.so
|
all: $(BIN) wrapper/libxgboostwrapper.so
|
||||||
@ -31,6 +31,9 @@ $(BIN) :
|
|||||||
$(SLIB) :
|
$(SLIB) :
|
||||||
$(CXX) $(CFLAGS) -fPIC $(LDFLAGS) -shared -o $@ $(filter %.cpp %.o %.c, $^)
|
$(CXX) $(CFLAGS) -fPIC $(LDFLAGS) -shared -o $@ $(filter %.cpp %.o %.c, $^)
|
||||||
|
|
||||||
|
$(RLIB) :
|
||||||
|
R CMD SHLIB -c -o $@ $(filter %.cpp %.o %.c, $^)
|
||||||
|
|
||||||
$(OBJ) :
|
$(OBJ) :
|
||||||
$(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c, $^) )
|
$(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c, $^) )
|
||||||
|
|
||||||
@ -38,4 +41,4 @@ install:
|
|||||||
cp -f -r $(BIN) $(INSTALL_PATH)
|
cp -f -r $(BIN) $(INSTALL_PATH)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(OBJ) $(BIN) $(SLIB) *~ */*~ */*/*~
|
$(RM) $(OBJ) $(BIN) $(SLIB) $(RLIB) *~ */*~ */*/*~
|
||||||
|
|||||||
@ -35,7 +35,7 @@ bst <- xgb.train(param, dtrain, nround=2, watchlist=watchlist)
|
|||||||
# make prediction
|
# make prediction
|
||||||
preds <- xgb.predict(bst, dtest)
|
preds <- xgb.predict(bst, dtest)
|
||||||
labels <- xgb.getinfo(dtest, "label")
|
labels <- xgb.getinfo(dtest, "label")
|
||||||
err <- as.real(sum(as.integer(preds > 0.5) != labels)) / length(labels)
|
err <- as.numeric(sum(as.integer(preds > 0.5) != labels)) / length(labels)
|
||||||
# print error rate
|
# print error rate
|
||||||
print(paste("error=",err))
|
print(paste("error=",err))
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ logregobj <- function(preds, dtrain) {
|
|||||||
# Take this in mind when you use the customization, and maybe you need write customized evaluation function
|
# Take this in mind when you use the customization, and maybe you need write customized evaluation function
|
||||||
evalerror <- function(preds, dtrain) {
|
evalerror <- function(preds, dtrain) {
|
||||||
labels <- xgb.getinfo(dtrain, "label")
|
labels <- xgb.getinfo(dtrain, "label")
|
||||||
err <- as.real(sum(labels != (preds > 0.0))) / length(labels)
|
err <- as.numeric(sum(labels != (preds > 0.0))) / length(labels)
|
||||||
return(list(metric="error", value=err))
|
return(list(metric="error", value=err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,15 +48,15 @@ xgb.setinfo <- function(dmat, name, info) {
|
|||||||
stop("xgb.setinfo: first argument dtrain must be xgb.DMatrix");
|
stop("xgb.setinfo: first argument dtrain must be xgb.DMatrix");
|
||||||
}
|
}
|
||||||
if (name == "label") {
|
if (name == "label") {
|
||||||
.Call("XGDMatrixSetInfo_R", dmat, name, as.real(info))
|
.Call("XGDMatrixSetInfo_R", dmat, name, as.numeric(info))
|
||||||
return(TRUE)
|
return(TRUE)
|
||||||
}
|
}
|
||||||
if (name == "weight") {
|
if (name == "weight") {
|
||||||
.Call("XGDMatrixSetInfo_R", dmat, name, as.real(info))
|
.Call("XGDMatrixSetInfo_R", dmat, name, as.numeric(info))
|
||||||
return(TRUE)
|
return(TRUE)
|
||||||
}
|
}
|
||||||
if (name == "base_margin") {
|
if (name == "base_margin") {
|
||||||
.Call("XGDMatrixSetInfo_R", dmat, name, as.real(info))
|
.Call("XGDMatrixSetInfo_R", dmat, name, as.numeric(info))
|
||||||
return(TRUE)
|
return(TRUE)
|
||||||
}
|
}
|
||||||
if (name == "group") {
|
if (name == "group") {
|
||||||
|
|||||||
@ -165,10 +165,12 @@ extern "C" {
|
|||||||
std::vector<void*> vec_dmats;
|
std::vector<void*> vec_dmats;
|
||||||
std::vector<std::string> vec_names;
|
std::vector<std::string> vec_names;
|
||||||
std::vector<const char*> vec_sptr;
|
std::vector<const char*> vec_sptr;
|
||||||
for (int i = 0; i < len; ++i){
|
for (int i = 0; i < len; ++i) {
|
||||||
vec_dmats.push_back(R_ExternalPtrAddr(VECTOR_ELT(dmats, i)));
|
vec_dmats.push_back(R_ExternalPtrAddr(VECTOR_ELT(dmats, i)));
|
||||||
vec_names.push_back(std::string(CHAR(asChar(VECTOR_ELT(evnames, i)))));
|
vec_names.push_back(std::string(CHAR(asChar(VECTOR_ELT(evnames, i)))));
|
||||||
vec_sptr.push_back(vec_names.back().c_str());
|
}
|
||||||
|
for (int i = 0; i < len; ++i) {
|
||||||
|
vec_sptr.push_back(vec_names[i].c_str());
|
||||||
}
|
}
|
||||||
return mkString(XGBoosterEvalOneIter(R_ExternalPtrAddr(handle),
|
return mkString(XGBoosterEvalOneIter(R_ExternalPtrAddr(handle),
|
||||||
asInteger(iter),
|
asInteger(iter),
|
||||||
|
|||||||
@ -225,6 +225,7 @@ extern "C"{
|
|||||||
for (size_t i = 0; i < len; ++i) {
|
for (size_t i = 0; i < len; ++i) {
|
||||||
mats.push_back(static_cast<DataMatrix*>(dmats[i]));
|
mats.push_back(static_cast<DataMatrix*>(dmats[i]));
|
||||||
names.push_back(std::string(evnames[i]));
|
names.push_back(std::string(evnames[i]));
|
||||||
|
printf("add names: %s\n", names.back().c_str());
|
||||||
}
|
}
|
||||||
bst->CheckInitModel();
|
bst->CheckInitModel();
|
||||||
bst->eval_str = bst->EvalOneIter(iter, mats, names);
|
bst->eval_str = bst->EvalOneIter(iter, mats, names);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user