-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[R] Implement new save raw in R. (#7571)
- Loading branch information
1 parent
ef4dae4
commit d262503
Showing
7 changed files
with
88 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
context("Test model IO.") | ||
## some other tests are in test_basic.R | ||
require(xgboost) | ||
require(testthat) | ||
|
||
data(agaricus.train, package = "xgboost") | ||
data(agaricus.test, package = "xgboost") | ||
train <- agaricus.train | ||
test <- agaricus.test | ||
|
||
test_that("load/save raw works", { | ||
nrounds <- 8 | ||
booster <- xgboost( | ||
data = train$data, label = train$label, | ||
nrounds = nrounds, objective = "binary:logistic" | ||
) | ||
|
||
json_bytes <- xgb.save.raw(booster, raw_format = "json") | ||
ubj_bytes <- xgb.save.raw(booster, raw_format = "ubj") | ||
old_bytes <- xgb.save.raw(booster, raw_format = "deprecated") | ||
|
||
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") | ||
|
||
expect_equal(json2old, ubj2old) | ||
expect_equal(json2old, old_bytes) | ||
}) |