Skip to content

Commit

Permalink
Fixed a test on NA (#179)
Browse files Browse the repository at this point in the history
* added github actions to check the repo

* added build ignore for gh action checks; set system path to include h5cc

* minor fix for non-osx

* updated to HDF5 1.12.1

* See #178 and r-lib/bit64#19
  • Loading branch information
dipterix authored Aug 14, 2021
1 parent b57532f commit 7e2d84d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tests/testthat/test-64bit_support.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ test_that("Dataset with more than 2^31 rows", {
## but will only support to the length of LONG accuracy
## just as normal R arrays
large_space <- H5S$new(type="simple", dim=as.integer64(2)^33)

## first try that writing a hyperslab is done correctly
large_space$select_hyperslab(start=1, count=1, stride=1, block=as.integer64(2)^32)
expect_equal(large_space$get_select_hyper_blocklist()[,1], setNames(c(1, 2^32), c("block_1_start", "block_1_end")))

## now test that the reading also works correctly using the high-level array functionality
large_space$select_none()
large_space[2:2^32]
expect_equal(large_space$get_select_hyper_blocklist()[,1], setNames(c(2, 2^32), c("block_1_start", "block_1_end")))
large_space$select_none()
large_space[as.integer64(2):(as.integer64(2)^32)]
expect_equal(large_space$get_select_hyper_blocklist()[,1], setNames(c(2, 2^32), c("block_1_start", "block_1_end")))

## create a large dataset on disk for read/write test (won't actually be physically large in size
test_file <- tempfile(fileext=".h5")
## open a new one, truncate if it exists
Expand All @@ -43,7 +43,7 @@ test_that("Dataset with more than 2^31 rows", {
expect_equal(large_ds[(2^32-20):(2^32+20)], c(rep(0L,10), 1:21, rep(0L, 10)))
file.h5$close_all()
file.remove(test_file)

})

truncateVec <- function(x, min, max) {
Expand All @@ -66,7 +66,7 @@ test_that("Datatype conversion with 64bit", {
LLONG_MAX <- value_LLONG_MAX()
dtype_uint64 <- h5types$H5T_NATIVE_ULLONG
dtype_int64 <- h5types$H5T_NATIVE_LLONG

## first test the uint64 behaviour
## Should differ between truncation, NA and FLOAT_FORCE
dbl_vec_pos <- c(1, 2, 2^31-1, 2^31, 2^32, 2^33, 2^62, 2^63, 1.5 * 2^63, 2^65)
Expand All @@ -83,6 +83,9 @@ test_that("Datatype conversion with 64bit", {
dbl_vec_int64_trunc[dbl_vec < 0] <- 0
dbl_vec_int64_trunc[is.na(dbl_vec_int64_trunc)] <- LLONG_MAX
dbl_vec_int64_na <- suppressWarnings(bit64::as.integer64(dbl_vec))
suppressWarnings({
dbl_vec_int64_na[18] <- dbl_vec_int64_na[18] + 1
})
dbl_vec_int64_na[dbl_vec < 0] <- 0
expect_equal(suppressWarnings(truncateVec(dbl_vec_int64_trunc, 0, LLONG_MAX)), res_dbl_uint64_default$output)
expect_equal(suppressWarnings(truncateVec(dbl_vec_int64_na, 0, LLONG_MAX)), res_dbl_uint64_na$output)
Expand All @@ -100,15 +103,15 @@ test_that("Datatype conversion with 64bit", {
res_dbl_int64_int_noloss_short_int <- hdf5r:::convertRoundTrip(dbl_vec[abs(dbl_vec) < 2^31], dtype_int64,
flags=h5const$H5TOR_CONV_INT64_INT_NOLOSS)
expect_equal(as.integer(dbl_vec[abs(dbl_vec) < 2^31]), res_dbl_int64_int_noloss_short_int$output)

res_dbl_int64_int_noloss_short_int_withNA <- hdf5r:::convertRoundTrip(c(dbl_vec[abs(dbl_vec) < 2^31], NA), dtype_int64,
flags=h5const$H5TOR_CONV_INT64_INT_NOLOSS)
expect_equal(as.integer(c(dbl_vec[abs(dbl_vec) < 2^31], NA)), res_dbl_int64_int_noloss_short_int_withNA$output)

res_dbl_int64_int_noloss <- suppressWarnings(hdf5r:::convertRoundTrip(dbl_vec, dtype_int64,
flags=h5const$H5TOR_CONV_INT64_INT_NOLOSS))
expect_equal(dbl_vec_int64, res_dbl_int64_int_noloss$output)

## covnersion to float if no loss is incurred
res_dbl_int64_float_noloss_short_float <- hdf5r:::convertRoundTrip(dbl_vec[abs(dbl_vec) < 2^51], dtype_int64,
flags=h5const$H5TOR_CONV_INT64_FLOAT_NOLOSS)
Expand All @@ -117,7 +120,7 @@ test_that("Datatype conversion with 64bit", {
res_dbl_int64_float_noloss_short_float_withNA <- hdf5r:::convertRoundTrip(c(dbl_vec[abs(dbl_vec) < 2^51], NA), dtype_int64,
flags=h5const$H5TOR_CONV_INT64_FLOAT_NOLOSS)
expect_equal(as.numeric(c(dbl_vec[abs(dbl_vec) < 2^51], NA)), res_dbl_int64_float_noloss_short_float_withNA$output)

res_dbl_int64_float_noloss <- suppressWarnings(hdf5r:::convertRoundTrip(dbl_vec, dtype_int64,
flags=h5const$H5TOR_CONV_INT64_FLOAT_NOLOSS))
expect_equal(dbl_vec_int64, res_dbl_int64_int_noloss$output)
Expand All @@ -126,7 +129,7 @@ test_that("Datatype conversion with 64bit", {
## conversion to integer or float if no loss is incurred
res_dbl_int64_noloss <- suppressWarnings(hdf5r:::convertRoundTrip(dbl_vec, dtype_int64, flags=h5const$H5TOR_CONV_INT64_NOLOSS))
expect_equal(dbl_vec_int64, res_dbl_int64_noloss$output)

res_dbl_int64_noloss_short_int <- hdf5r:::convertRoundTrip(dbl_vec[abs(dbl_vec) < 2^31], dtype_int64,
flags=h5const$H5TOR_CONV_INT64_NOLOSS)
expect_equal(as.integer(dbl_vec[abs(dbl_vec) < 2^31]), res_dbl_int64_noloss_short_int$output)
Expand All @@ -138,6 +141,6 @@ test_that("Datatype conversion with 64bit", {
## forced coercion to double
suppressWarnings(res_dbl_int64_force <- hdf5r:::convertRoundTrip(dbl_vec, dtype_int64, flags=h5const$H5TOR_CONV_INT64_FLOAT_FORCE))
expect_equal(suppressWarnings(as.numeric(dbl_vec_int64)), res_dbl_int64_force$output)


})

0 comments on commit 7e2d84d

Please sign in to comment.