Skip to content

Commit

Permalink
Merge pull request #753 from njtierney/remove-log-base-arg
Browse files Browse the repository at this point in the history
remove `base` argument from `log`. Resolves #597.
  • Loading branch information
njtierney authored Dec 17, 2024
2 parents 39ef12f + 172ea61 commit d475f88
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 7 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Imports:
coda,
future (>= 1.22.1),
glue (>= 1.5.1),
lifecycle,
methods,
parallelly (>= 1.29.0),
progress (>= 1.2.0),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# greta (development version)

## Changes

- `log.greta_array()` function warns if user uses the `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!
Expand Down
19 changes: 15 additions & 4 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,7 +121,18 @@
NULL

#' @export
log.greta_array <- function(x, base = exp(1)) {
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 {
Expand Down
1 change: 1 addition & 0 deletions greta.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 425469f5-737a-40a5-856a-8078552f4e50

RestoreWorkspace: Default
SaveWorkspace: Default
Expand Down
6 changes: 3 additions & 3 deletions man/functions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions tests/testthat/_snaps/functions.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
# log.greta_array has a warning when base argument used

Code
log(x)
Message
greta array <operation>
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 <data>
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
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test_functions.R
Original file line number Diff line number Diff line change
@@ -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())

Expand Down

0 comments on commit d475f88

Please sign in to comment.