Skip to content

Commit

Permalink
Name space.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Jan 14, 2020
1 parent 83b9790 commit 0cabd18
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions R-package/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export(xgb.ggplot.importance)
export(xgb.importance)
export(xgb.load)
export(xgb.load.raw)
export(xgb.unserialize)
export(xgb.model.dt.tree)
export(xgb.plot.deepness)
export(xgb.plot.importance)
Expand All @@ -49,6 +50,7 @@ export(xgb.plot.shap)
export(xgb.plot.tree)
export(xgb.save)
export(xgb.save.raw)
export(xgb.serialize)
export(xgb.train)
export(xgboost)
import(methods)
Expand Down
16 changes: 8 additions & 8 deletions R-package/R/xgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ xgb.Booster.handle <- function(params = list(), cachelist = list(), modelfile =
return(handle)
} else if (typeof(modelfile) == "raw") {
## A memory buffer
bst <- xgb.unserialize.raw(modelfile)
bst <- xgb.unserialize(modelfile)
xgb.parameters(bst) <- params
return (bst)
} else if (inherits(modelfile, "xgb.Booster")) {
## A booster object
bst <- xgb.Booster.complete(modelfile, saveraw = TRUE)
bst <- xgb.unserialize.raw(bst$raw)
bst <- xgb.unserialize(bst$raw)
xgb.parameters(bst) <- params
return (bst)
} else {
Expand Down Expand Up @@ -128,7 +128,7 @@ xgb.Booster.complete <- function(object, saveraw = TRUE) {
object$handle <- xgb.Booster.handle(modelfile = object$raw)
} else {
if (is.null(object$raw) && saveraw)
object$raw <- xgb.serialize.raw(object$handle)
object$raw <- xgb.serialize(object$handle)
}
return(object)
}
Expand Down Expand Up @@ -411,7 +411,7 @@ predict.xgb.Booster.handle <- function(object, ...) {
#' That would only matter if attributes need to be set many times.
#' Note, however, that when feeding a handle of an \code{xgb.Booster} object to the attribute setters,
#' the raw model cache of an \code{xgb.Booster} object would not be automatically updated,
#' and it would be user's responsibility to call \code{xgb.serialize.raw} to update it.
#' and it would be user's responsibility to call \code{xgb.serialize} to update it.
#'
#' The \code{xgb.attributes<-} setter either updates the existing or adds one or several attributes,
#' but it doesn't delete the other existing attributes.
Expand Down Expand Up @@ -470,7 +470,7 @@ xgb.attr <- function(object, name) {
}
.Call(XGBoosterSetAttr_R, handle, as.character(name[1]), value)
if (is(object, 'xgb.Booster') && !is.null(object$raw)) {
object$raw <- xgb.serialize.raw(object$handle)
object$raw <- xgb.serialize(object$handle)
}
object
}
Expand Down Expand Up @@ -510,7 +510,7 @@ xgb.attributes <- function(object) {
.Call(XGBoosterSetAttr_R, handle, names(a[i]), a[[i]])
}
if (is(object, 'xgb.Booster') && !is.null(object$raw)) {
object$raw <- xgb.serialize.raw(object$handle)
object$raw <- xgb.serialize(object$handle)
}
object
}
Expand All @@ -532,7 +532,7 @@ xgb.config <- function(object) {
`xgb.config<-` <- function(object, value) {
handle <- xgb.get.handle(object)
.Call(XGBoosterLoadJsonConfig_R, handle, value)
object$raw <- xgb.serialize.raw(object)
object$raw <- xgb.serialize(object)
object
}

Expand Down Expand Up @@ -572,7 +572,7 @@ xgb.config <- function(object) {
.Call(XGBoosterSetParam_R, handle, names(p[i]), p[[i]])
}
if (is(object, 'xgb.Booster') && !is.null(object$raw)) {
object$raw <- xgb.serialize.raw(object$handle)
object$raw <- xgb.serialize(object$handle)
}
object
}
Expand Down
4 changes: 2 additions & 2 deletions R-package/R/xgb.serialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param booster the booster instance
#'
#' @export
xgb.serialize.raw <- function(booster) {
handle <- xgb.get.handle(model)
xgb.serialize <- function(booster) {
handle <- xgb.get.handle(booster)
.Call(XGBoosterSerializeToBuffer_R, handle)
}
6 changes: 3 additions & 3 deletions R-package/R/xgb.unserialize.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Load the instance back from \code{\link{xgb.serialize.raw}}
#' Load the instance back from \code{\link{xgb.serialize}}
#'
#' @param buffer the buffer containing booster instance saved by \code{\link{xgb.serialize.raw}}
#' @param buffer the buffer containing booster instance saved by \code{\link{xgb.serialize}}
#'
#' @export
xgb.unserialize.raw <- function(buffer) {
xgb.unserialize <- function(buffer) {
cachelist <- list()
handle <- .Call(XGBoosterCreate_R, cachelist)
.Call(XGBoosterUnserializeFromBuffer_R, handle, buffer)
Expand Down

0 comments on commit 0cabd18

Please sign in to comment.