-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>
- Loading branch information
Showing
2 changed files
with
22 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) |