From da3f5327a3fbf98683607505c17906d7b2b2b086 Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 12 Nov 2024 17:12:58 +1100 Subject: [PATCH 1/4] remove `base` argument from `log`. Resolves #597. --- NEWS.md | 6 ++++++ R/functions.R | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index b16019cf..165de692 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# greta 0.5.1.90000 + +## Changes + +- `log.greta_array()` function drops `base` arg, as it was unused, (#597). + # greta 0.5.0 This version of greta uses Tensorflow 2.0.0, which comes with it a host of new very exciting features! diff --git a/R/functions.R b/R/functions.R index 02d5d513..def08a3e 100644 --- a/R/functions.R +++ b/R/functions.R @@ -121,7 +121,7 @@ NULL #' @export -log.greta_array <- function(x, base = exp(1)) { +log.greta_array <- function(x) { if (has_representation(x, "log")) { result <- copy_representation(x, "log") } else { From 36d86eb8162ff74b219320365087b251d6ef2473 Mon Sep 17 00:00:00 2001 From: njtierney Date: Tue, 17 Dec 2024 09:35:42 +1000 Subject: [PATCH 2/4] Use the `lifecycle` package to communicate to the user that the base argument is deprecated --- DESCRIPTION | 1 + R/functions.R | 19 +++++++++++---- man/functions.Rd | 6 ++--- tests/testthat/_snaps/functions.md | 38 ++++++++++++++++++++++++++++++ tests/testthat/test_functions.R | 23 ++++++++++++++++++ 5 files changed, 80 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 34621f12..e5cf407c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,6 +39,7 @@ Imports: coda, future (>= 1.22.1), glue (>= 1.5.1), + lifecycle, methods, parallelly (>= 1.29.0), progress (>= 1.2.0), diff --git a/R/functions.R b/R/functions.R index def08a3e..fcbaa584 100644 --- a/R/functions.R +++ b/R/functions.R @@ -87,9 +87,9 @@ #' @details TensorFlow only enables rounding to integers, so `round()` will #' error if `digits` is set to anything other than `0`. #' -#' Any additional arguments to `chol()`, `chol2inv`, and -#' `solve()` will be ignored, see the TensorFlow documentation for -#' details of these routines. +#' Any additional arguments to `chol()`, `chol2inv`, `solve()`, and `log()` +#' will be ignored, see the TensorFlow documentation for details of these +#' routines. #' #' `sweep()` only works on two-dimensional greta arrays (so `MARGIN` #' can only be either 1 or 2), and only for subtraction, addition, division @@ -121,7 +121,18 @@ NULL #' @export -log.greta_array <- function(x) { +log.greta_array <- function(x, base = lifecycle::deprecated()) { + + if (lifecycle::is_present(base)) { + lifecycle::deprecate_warn( + when = "0.5.1", + what = "log(base)", + details = "The `base` argument is (and actually was) never used in \\ + `log.greta_array()`. See the TensorFlow documentation for details of \\ + this routine." + ) + } + if (has_representation(x, "log")) { result <- copy_representation(x, "log") } else { diff --git a/man/functions.Rd b/man/functions.Rd index aa97c949..445d0203 100644 --- a/man/functions.Rd +++ b/man/functions.Rd @@ -12,9 +12,9 @@ and \link{transforms}. TensorFlow only enables rounding to integers, so \code{round()} will error if \code{digits} is set to anything other than \code{0}. -Any additional arguments to \code{chol()}, \code{chol2inv}, and -\code{solve()} will be ignored, see the TensorFlow documentation for -details of these routines. +Any additional arguments to \code{chol()}, \code{chol2inv}, \code{solve()}, and \code{log()} +will be ignored, see the TensorFlow documentation for details of these +routines. \code{sweep()} only works on two-dimensional greta arrays (so \code{MARGIN} can only be either 1 or 2), and only for subtraction, addition, division diff --git a/tests/testthat/_snaps/functions.md b/tests/testthat/_snaps/functions.md index d733e41f..ef645347 100644 --- a/tests/testthat/_snaps/functions.md +++ b/tests/testthat/_snaps/functions.md @@ -1,3 +1,41 @@ +# log.greta_array has a warning when base argument used + + Code + log(x) + Message + greta array + + Output + [,1] + [1,] ? + Message + + +--- + + The `base` argument of `log()` is deprecated as of greta 0.5.1. + i The `base` argument is (and actually was) never used in `log.greta_array()`. See the TensorFlow documentation for details of this routine. + +--- + + Code + y + Message + greta array + + Output + [,1] [,2] [,3] + [1,] 1 4 7 + [2,] 2 5 8 + [3,] 3 6 9 + Message + + +--- + + The `base` argument of `log()` is deprecated as of greta 0.5.1. + i The `base` argument is (and actually was) never used in `log.greta_array()`. See the TensorFlow documentation for details of this routine. + # cummax and cummin functions error informatively Code diff --git a/tests/testthat/test_functions.R b/tests/testthat/test_functions.R index d04c43f7..56a41a78 100644 --- a/tests/testthat/test_functions.R +++ b/tests/testthat/test_functions.R @@ -1,5 +1,28 @@ set.seed(2020 - 02 - 11) +test_that("log.greta_array has a warning when base argument used",{ + skip_if_not(check_tf_version()) + + x <- normal(0, 1) + expect_snapshot( + log(x) + ) + + expect_snapshot_warning( + log(x, base = 3) + ) + + y <- as_data(matrix(1:9, nrow = 3, ncol = 3)) + expect_snapshot( + y + ) + + expect_snapshot_warning( + log(exp(x), base = 3) + ) + +}) + test_that("simple functions work as expected", { skip_if_not(check_tf_version()) From 0915b5ce1dffbbf6bd8f8d7efaad88d6284a58da Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 18 Dec 2024 09:16:10 +1000 Subject: [PATCH 3/4] added ID tag from new RStudio update --- greta.Rproj | 1 + 1 file changed, 1 insertion(+) diff --git a/greta.Rproj b/greta.Rproj index 57cdc9a0..bd8b718f 100644 --- a/greta.Rproj +++ b/greta.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 425469f5-737a-40a5-856a-8078552f4e50 RestoreWorkspace: Default SaveWorkspace: Default From 172ea61fb34f125b84a5c83b70edfe149ec42f7f Mon Sep 17 00:00:00 2001 From: njtierney Date: Wed, 18 Dec 2024 09:17:06 +1000 Subject: [PATCH 4/4] news bump --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 601c9d20..4c8d954d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ ## Changes -- `log.greta_array()` function drops `base` arg, as it was unused, (#597). +- `log.greta_array()` function warns if user uses the `base` arg, as it was unused, (#597). # greta 0.5.0