Unverified Commit 9d433033 authored by Michael Mayer's avatar Michael Mayer Committed by GitHub
Browse files

[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: default avatarJames Lamb <jaylamb20@gmail.com>

* split double assignment into two lines
Co-authored-by: default avatarJames Lamb <jaylamb20@gmail.com>
parent a2a38b6c
...@@ -142,6 +142,10 @@ Predictor <- R6::R6Class( ...@@ -142,6 +142,10 @@ Predictor <- R6::R6Class(
# Check if data is a matrix # Check if data is a matrix
if (is.matrix(data)) { 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( preds <- lgb.call(
"LGBM_BoosterPredictForMat_R" "LGBM_BoosterPredictForMat_R"
, ret = preds , ret = preds
......
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)
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment