Skip to content

Commit

Permalink
Merge branch 'ops-dispatch-fixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kalinowski committed Aug 17, 2023
2 parents 4cc1a47 + 64879a0 commit ba484e2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tests/testthat/test-generic-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,25 @@ test_that("generics can handle tensors w/ convert=FALSE", {
skip_if_no_tensorflow()

# this tests that `*` dispatches correctly even of both x and y provide Ops methods
x <- tf$ones(shape(5, 5)) * r_to_py(array(1, dim = c(5, 5)))
expect_true(as.logical(all(x == 1)))
if(getRversion() >= "4.3.0") {
x <- tf$ones(shape(5, 5)) * r_to_py(array(1, dim = c(5, 5)))
expect_true(as.logical(all(x == 1)))
}

# test that as.array / as.raster can work even if convert=FALSE
img <- tf$random$uniform(shape(256, 256, 4), maxval = 256) |>
tf$cast("int8")
x <- np_array(array(c(2, 1, 1, 1), dim = c(1, 1, 4)), dtype = "int8") # convert=FALSE

expect_no_error(as.raster(img))
expect_no_error(as.raster(img %/% x))
expect_no_error(as.raster(r_to_py(img %/% x)))
expect_no_error(as.raster(r_to_py(r_to_py(img) %/% x)))
expect_no_error(as.raster(r_to_py(img %/% r_to_py(x))))
expect_no_error(as.raster(r_to_py(img)))

if (getRversion() >= "4.3.0") {
expect_no_error(as.raster(img %/% x))
expect_no_error(as.raster(r_to_py(img %/% x)))
expect_no_error(as.raster(r_to_py(r_to_py(img) %/% x)))
expect_no_error(as.raster(r_to_py(img %/% r_to_py(x))))
}

})

Expand Down

0 comments on commit ba484e2

Please sign in to comment.