diff --git a/DESCRIPTION b/DESCRIPTION index 9230653970..28dec37e85 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tiledb Type: Package -Version: 0.29.0.1 +Version: 0.29.0.2 Title: Modern Database Engine for Complex Data Based on Multi-Dimensional Arrays Authors@R: c(person("TileDB, Inc.", role = c("aut", "cph")), person("Dirk", "Eddelbuettel", email = "dirk@tiledb.com", role = "cre")) diff --git a/NEWS.md b/NEWS.md index 5c0e4a6860..f7d940cbdf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ * Error messages displayed when a mismatched external pointer is detected now show both expected and encountered types (#740) +* `NDRectangle` types can now be instantiated for more domain data types (#741) + ## Documentation * The documentation website now uses favicon symbols for all pages rendered (#739) diff --git a/inst/tinytest/test_ndrectangle.R b/inst/tinytest/test_ndrectangle.R index 6c80314be9..5a9a75c9cb 100644 --- a/inst/tinytest/test_ndrectangle.R +++ b/inst/tinytest/test_ndrectangle.R @@ -6,26 +6,41 @@ ctx <- tiledb_ctx(limitTileDBCores()) if (tiledb_version(TRUE) < "2.25.0") exit_file("These tests needs TileDB 2.25.0 or later") -## INT32 -expect_silent(intdim <- tiledb_dim("dim", c(1L, 100L), type = "INT32")) -expect_true(is(intdim, "tiledb_dim")) -expect_silent(intdom <- tiledb_domain(dim = intdim)) -expect_true(is(intdom, "tiledb_domain")) - -expect_error(ndr <- tiledb_ndrectangle(intdim)) -expect_silent(ndr <- tiledb_ndrectangle(intdom)) -expect_true(is(ndr, "tiledb_ndrectangle")) - -expect_error(tiledb_ndrectangle_set_range(intdim, "dim", 1, 2)) # wrong type -expect_error(tiledb_ndrectangle_set_range(ndr, "notdim", 1, 2)) # wrong name -expect_error(tiledb_ndrectangle_set_range(ndr, "dim", 1, 2L)) # wrong type -expect_error(tiledb_ndrectangle_set_range(ndr, "dim", 1L, 2)) # wrong type -expect_silent(ndr <- tiledb_ndrectangle_set_range(ndr, "dim", 1L, 20L)) - -expect_error(tiledb_ndrectangle_get_range(intdim, "dim")) # wrong type -expect_error(tiledb_ndrectangle_set_range(ndr, "notdim")) # wrong name -expect_equal(tiledb_ndrectangle_get_range(ndr, "dim"), c(1L, 20L)) - +for (tp in c("INT32", "UINT32", "INT16", "UINT16", "INT64", "UINT64", "INT8", "UINT8")) { + if (grepl("INT64", tp)) { + expect_silent(intdim <- tiledb_dim("dim", bit64::as.integer64(c(1L, 100L)), + bit64::as.integer64(50L), type = tp)) + } else { + expect_silent(intdim <- tiledb_dim("dim", c(1L, 100L), 50L, type = tp)) + } + expect_true(is(intdim, "tiledb_dim")) + expect_silent(intdom <- tiledb_domain(dim = intdim)) + expect_true(is(intdom, "tiledb_domain")) + + expect_error(ndr <- tiledb_ndrectangle(intdim)) + expect_silent(ndr <- tiledb_ndrectangle(intdom)) + expect_true(is(ndr, "tiledb_ndrectangle")) + + expect_error(tiledb_ndrectangle_set_range(intdim, "dim", 1, 2)) # wrong type + expect_error(tiledb_ndrectangle_set_range(ndr, "notdim", 1, 2)) # wrong name + expect_error(tiledb_ndrectangle_set_range(ndr, "dim", 1, 2L)) # wrong type + expect_error(tiledb_ndrectangle_set_range(ndr, "dim", 1L, 2)) # wrong type + if (grepl("INT64", tp)) { + expect_silent(ndr <- tiledb_ndrectangle_set_range(ndr, "dim", + bit64::as.integer64(1L), + bit64::as.integer64(20L))) + } else { + expect_silent(ndr <- tiledb_ndrectangle_set_range(ndr, "dim", 1L, 20L)) + } + + expect_error(tiledb_ndrectangle_get_range(intdim, "dim")) # wrong type + expect_error(tiledb_ndrectangle_set_range(ndr, "notdim")) # wrong name + if (grepl("INT64", tp)) { + expect_equal(tiledb_ndrectangle_get_range(ndr, "dim"), bit64::as.integer64(c(1L, 20L))) + } else { + expect_equal(tiledb_ndrectangle_get_range(ndr, "dim"), c(1L, 20L)) + } +} ## ASCII expect_silent(strdim <- tiledb_dim("strdim", c(NULL, NULL), NULL, type = "ASCII")) diff --git a/src/libtiledb.cpp b/src/libtiledb.cpp index de10947c76..e283e00095 100644 --- a/src/libtiledb.cpp +++ b/src/libtiledb.cpp @@ -5449,7 +5449,27 @@ XPtr libtiledb_ndrectangle_set_range(XPtr(Rcpp::fromInteger64(Rcpp::as(start))), static_cast(Rcpp::fromInteger64(Rcpp::as(end)))); } else if (dtype == TILEDB_INT32) { - ndr->set_range(dimname, as(start), as(end)); + ndr->set_range(dimname, Rcpp::as(start), Rcpp::as(end)); + } else if (dtype == TILEDB_UINT32) { + ndr->set_range(dimname, + static_cast(Rcpp::as(start)), + static_cast(Rcpp::as(end))); + } else if (dtype == TILEDB_INT16) { + ndr->set_range(dimname, + static_cast(Rcpp::as(start)), + static_cast(Rcpp::as(end))); + } else if (dtype == TILEDB_UINT16) { + ndr->set_range(dimname, + static_cast(Rcpp::as(start)), + static_cast(Rcpp::as(end))); + } else if (dtype == TILEDB_INT8) { + ndr->set_range(dimname, + static_cast(Rcpp::as(start)), + static_cast(Rcpp::as(end))); + } else if (dtype == TILEDB_UINT8) { + ndr->set_range(dimname, + static_cast(Rcpp::as(start)), + static_cast(Rcpp::as(end))); } else { Rcpp::stop("Domain datatype '%s' of dimname '%s' is not currently supported", _tiledb_datatype_to_string(dtype), dimname); @@ -5466,17 +5486,37 @@ SEXP libtiledb_ndrectangle_get_range(XPtr ndr, #if TILEDB_VERSION >= TileDB_Version(2,25,0) if (dtype == "CHAR" || dtype == "ASCII" || dtype == "UTF8") { auto range = ndr->range(dimname); - return Rcpp::CharacterVector::create(std::get<0>(range), std::get<1>(range)); + return Rcpp::CharacterVector::create(range[0], range[1]); } else if (dtype == "INT64") { auto range = ndr->range(dimname); - return Rcpp::toInteger64( std::vector{ std::get<0>(range), std::get<1>(range) } ); + return Rcpp::toInteger64( std::vector{range[0], range[1] } ); } else if (dtype == "UINT64") { auto range = ndr->range(dimname); - return Rcpp::toInteger64( std::vector{ static_cast(std::get<0>(range)), - static_cast(std::get<1>(range)) } ); + return Rcpp::toInteger64( std::vector{ static_cast(range[0]), + static_cast(range[1]) } ); } else if (dtype == "INT32") { auto range = ndr->range(dimname); - return Rcpp::IntegerVector::create( std::get<0>(range), std::get<1>(range) ); + return Rcpp::IntegerVector::create(range[0], range[1]); + } else if (dtype == "UINT32") { + auto range = ndr->range(dimname); + return Rcpp::IntegerVector::create( static_cast(range[0]), + static_cast(range[1]) ); + } else if (dtype == "INT16") { + auto range = ndr->range(dimname); + return Rcpp::IntegerVector::create( static_cast(range[0]), + static_cast(range[1]) ); + } else if (dtype == "UINT16") { + auto range = ndr->range(dimname); + return Rcpp::IntegerVector::create( static_cast(range[0]), + static_cast(range[1]) ); + } else if (dtype == "INT8") { + auto range = ndr->range(dimname); + return Rcpp::IntegerVector::create( static_cast(range[0]), + static_cast(range[1]) ); + } else if (dtype == "UINT8") { + auto range = ndr->range(dimname); + return Rcpp::IntegerVector::create( static_cast(range[0]), + static_cast(range[1]) ); } else { Rcpp::stop("Domain datatype '%s' of dimname '%s' is not currently supported", dtype, dimname); }