Skip to content

Commit

Permalink
fix shape() for R 4.4.0 (is.atomic(NULL) == FALSE now)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kalinowski committed May 7, 2024
1 parent bd60176 commit 0b0d103
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 8 additions & 8 deletions R/shape.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,19 @@ shape <- function(...) {
# if (!is.null(dim(x)) && length(x) > 200)
# warning("Did you pass an R array to shape()? Did you mean to use dim()?")

if (!is.atomic(x) || length(x) > 1)
lapply(x, fix)
else if (is.null(x) ||
identical(x, NA_integer_) ||
identical(x, NA_real_) ||
identical(x, NA) ||
(is.numeric(x) && isTRUE(suppressWarnings(x == -1L))))
if (is.null(x) ||
identical(x, NA_integer_) ||
identical(x, NA_real_) ||
identical(x, NA) ||
(is.numeric(x) && isTRUE(suppressWarnings(x == -1L))))
NA_integer_ # so we can safely unlist()
else if (!is.atomic(x) || length(x) > 1)
lapply(x, fix)
else
as.integer(x)
}

shp <- unlist(fix(list(...)), use.names = FALSE)
shp <- unlist(lapply(list(...), fix), use.names = FALSE)
shp <- lapply(shp, function(x) if (identical(x, NA_integer_)) NULL else x)
class(shp) <- "keras_shape"
shp
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-shape.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("shape() works", {

expect_identical(shape(NULL, 28),
structure(list(NULL, 28L), class = "keras_shape"))

})

0 comments on commit 0b0d103

Please sign in to comment.