зеркало из https://github.com/microsoft/LightGBM.git
[R-package] Turn matrix to storage mode "double" (#3140)
* Turn matrix to storage mode "double" * added "test_Predictor.R" to R tests with check for integer storage mode during prediction * Explicit integers in test_Preditor to avoid TravisCI failure * properly aligning comment on storage.mode Co-authored-by: James Lamb <jaylamb20@gmail.com> * split double assignment into two lines Co-authored-by: James Lamb <jaylamb20@gmail.com>
This commit is contained in:
Родитель
a2a38b6cd5
Коммит
9d433033f2
|
@ -142,6 +142,10 @@ Predictor <- R6::R6Class(
|
|||
|
||||
# Check if data is a matrix
|
||||
if (is.matrix(data)) {
|
||||
# Check whether matrix is the correct type first ("double")
|
||||
if (storage.mode(data) != "double") {
|
||||
storage.mode(data) <- "double"
|
||||
}
|
||||
preds <- lgb.call(
|
||||
"LGBM_BoosterPredictForMat_R"
|
||||
, ret = preds
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
context("Predictor")
|
||||
|
||||
test_that("predictions do not fail for integer input", {
|
||||
X <- as.matrix(as.integer(iris[, "Species"]), ncol = 1L)
|
||||
y <- iris[["Sepal.Length"]]
|
||||
dtrain <- lgb.Dataset(X, label = y)
|
||||
fit <- lgb.train(
|
||||
data = dtrain
|
||||
, objective = "regression"
|
||||
, verbose = -1L
|
||||
)
|
||||
X_double <- X[c(1L, 51L, 101L), , drop = FALSE]
|
||||
X_integer <- X_double
|
||||
storage.mode(X_double) <- "double"
|
||||
pred_integer <- predict(fit, X_integer)
|
||||
pred_double <- predict(fit, X_double)
|
||||
expect_equal(pred_integer, pred_double)
|
||||
})
|
Загрузка…
Ссылка в новой задаче