Skip to content

Commit

Permalink
Fix R load raw.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Feb 21, 2022
1 parent 131858e commit 6627d90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 10 additions & 2 deletions R-package/R/xgb.load.raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
#' @param buffer the buffer returned by xgb.save.raw
#'
#' @export
xgb.load.raw <- function(buffer) {
xgb.load.raw <- function(buffer, as_booster = TRUE) {
cachelist <- list()
handle <- .Call(XGBoosterCreate_R, cachelist)
.Call(XGBoosterLoadModelFromRaw_R, handle, buffer)
class(handle) <- "xgb.Booster.handle"
return (handle)

if (as_booster) {
booster <- list(handle = handle, raw = NULL)
class(booster) <- "xgb.Booster"
booster <- xgb.Booster.complete(booster, saveraw = TRUE)
return(booster)
} else {
return (handle)
}
}
9 changes: 0 additions & 9 deletions R-package/tests/testthat/test_io.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ test_that("load/save raw works", {
from_json <- xgb.load.raw(json_bytes)
from_ubj <- xgb.load.raw(ubj_bytes)

## FIXME(jiamingy): Should we include these 3 lines into `xgb.load.raw`?
from_json <- list(handle = from_json, raw = NULL)
class(from_json) <- "xgb.Booster"
from_json <- xgb.Booster.complete(from_json, saveraw = TRUE)

from_ubj <- list(handle = from_ubj, raw = NULL)
class(from_ubj) <- "xgb.Booster"
from_ubj <- xgb.Booster.complete(from_ubj, saveraw = TRUE)

json2old <- xgb.save.raw(from_json, raw_format = "deprecated")
ubj2old <- xgb.save.raw(from_ubj, raw_format = "deprecated")

Expand Down

0 comments on commit 6627d90

Please sign in to comment.