From 4950ed30c0330e585c17502aa176e66280c57b40 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Mon, 14 Jun 2021 22:29:17 -0500 Subject: [PATCH] more changes for consistency with Python tests --- R-package/tests/testthat/test_basic.R | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/R-package/tests/testthat/test_basic.R b/R-package/tests/testthat/test_basic.R index 3efed31dd6ee..e1e8b7114f8c 100644 --- a/R-package/tests/testthat/test_basic.R +++ b/R-package/tests/testthat/test_basic.R @@ -2129,11 +2129,17 @@ context("monotone constraints") return(any(diff(y) < 0.0) & any(diff(y) > 0.0)) } +# R equivalent of numpy.linspace() +.linspace <- function(start_val, stop_val, num) { + weights <- (seq_len(num) - 1L) / (num - 1L) + return(start_val + weights * (stop_val - start_val)) +} + .is_correctly_constrained <- function(learner, x3_to_categorical) { iterations <- 10L n <- 1000L - variable_x <- seq_len(n) / n - fixed_xs_values <- seq_len(n) / n + variable_x <- .linspace(0L, 1L, n) + fixed_xs_values <- .linspace(0L, 1L, n) for (i in seq_len(iterations)) { fixed_x <- fixed_xs_values[i] * rep(1.0, n) monotonically_increasing_x <- matrix( @@ -2207,7 +2213,7 @@ for (x3_to_categorical in c(TRUE, FALSE)) { params = params , data = dtrain , obj = "regression_l2" - , nrounds = 10L + , nrounds = 100L ) expect_true({ .is_correctly_constrained(