fix the zero length vector

This commit is contained in:
tqchen 2014-09-01 22:50:48 -07:00
parent 9100ffc12a
commit 29a7027dba
2 changed files with 11 additions and 4 deletions

View File

@ -121,8 +121,8 @@ xgb.iter.eval <- function(booster, watchlist, iter) {
stop("xgb.eval: watch list can only contain xgb.DMatrix")
}
}
evnames <- list()
if (length(watchlist) != 0) {
evnames <- list()
for (i in 1:length(watchlist)) {
w <- watchlist[i]
if (length(names(w)) == 0) {
@ -130,8 +130,10 @@ xgb.iter.eval <- function(booster, watchlist, iter) {
}
evnames <- append(evnames, names(w))
}
msg <- .Call("XGBoosterEvalOneIter_R", booster, as.integer(iter), watchlist,
evnames, PACKAGE = "xgboost")
} else {
msg <- ""
}
msg <- .Call("XGBoosterEvalOneIter_R", booster, as.integer(iter), watchlist,
evnames, PACKAGE = "xgboost")
return(msg)
}

View File

@ -197,7 +197,12 @@ extern "C" {
for (int i = 0; i < len; ++i){
dvec.push_back(R_ExternalPtrAddr(VECTOR_ELT(dmats, i)));
}
void *handle = XGBoosterCreate(&dvec[0], dvec.size());
void *handle;
if (dvec.size() == 0) {
handle = XGBoosterCreate(NULL, 0);
} else {
handle = XGBoosterCreate(&dvec[0], dvec.size());
}
SEXP ret = PROTECT(R_MakeExternalPtr(handle, R_NilValue, R_NilValue));
R_RegisterCFinalizerEx(ret, _BoosterFinalizer, TRUE);
UNPROTECT(1);