From 0cabd18baa53fbf44ac07445421b255faf1799b3 Mon Sep 17 00:00:00 2001 From: fis Date: Tue, 14 Jan 2020 13:07:28 +0800 Subject: [PATCH] Name space. --- R-package/NAMESPACE | 2 ++ R-package/R/xgb.Booster.R | 16 ++++++++-------- R-package/R/xgb.serialize.R | 4 ++-- R-package/R/xgb.unserialize.R | 6 +++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/R-package/NAMESPACE b/R-package/NAMESPACE index 625bd0f3e749..a3a8ad2ee944 100644 --- a/R-package/NAMESPACE +++ b/R-package/NAMESPACE @@ -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) @@ -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) diff --git a/R-package/R/xgb.Booster.R b/R-package/R/xgb.Booster.R index 9a700bd69111..73675c0bfb24 100644 --- a/R-package/R/xgb.Booster.R +++ b/R-package/R/xgb.Booster.R @@ -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 { @@ -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) } @@ -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. @@ -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 } @@ -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 } @@ -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 } @@ -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 } diff --git a/R-package/R/xgb.serialize.R b/R-package/R/xgb.serialize.R index 9e808d94164a..0cc3b37b63ad 100644 --- a/R-package/R/xgb.serialize.R +++ b/R-package/R/xgb.serialize.R @@ -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) } diff --git a/R-package/R/xgb.unserialize.R b/R-package/R/xgb.unserialize.R index def30852680b..1a62e4cde304 100644 --- a/R-package/R/xgb.unserialize.R +++ b/R-package/R/xgb.unserialize.R @@ -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)