Skip to content

Commit

Permalink
Support ndrectangle setter and getter for float{32,64} (#742)
Browse files Browse the repository at this point in the history
* Support ndrectangle setter and getter for float{32,64}

* Roll micro version, update NEWS [ci skip]
  • Loading branch information
eddelbuettel authored Jul 31, 2024
1 parent 1b5a65c commit d6bda66
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tiledb
Type: Package
Version: 0.29.0.2
Version: 0.29.0.3
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 = "[email protected]", role = "cre"))
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

* 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)
* `NDRectangle` types can now be instantiated for more domain data types (#741, #742)

## Documentation

Expand Down
25 changes: 14 additions & 11 deletions inst/tinytest/test_ndrectangle.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@ ctx <- tiledb_ctx(limitTileDBCores())

if (tiledb_version(TRUE) < "2.25.0") exit_file("These tests needs TileDB 2.25.0 or later")

for (tp in c("INT32", "UINT32", "INT16", "UINT16", "INT64", "UINT64", "INT8", "UINT8")) {
for (tp in c("INT32", "UINT32", "INT16", "UINT16", "INT64", "UINT64", "INT8", "UINT8", "FLOAT32", "FLOAT64")) {
if (grepl("INT64", tp)) {
expect_silent(intdim <- tiledb_dim("dim", bit64::as.integer64(c(1L, 100L)),
bit64::as.integer64(50L), type = tp))
expect_silent(dim <- tiledb_dim("dim", bit64::as.integer64(c(1L, 100L)), bit64::as.integer64(50L), type = tp))
} else if (grepl("FLOAT", tp)) {
expect_silent(dim <- tiledb_dim("dim", c(1, 100), 50, type = tp))
} else {
expect_silent(intdim <- tiledb_dim("dim", c(1L, 100L), 50L, type = tp))
expect_silent(dim <- 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_true(is(dim, "tiledb_dim"))
expect_silent(dom <- tiledb_domain(dim = dim))
expect_true(is(dom, "tiledb_domain"))

expect_error(ndr <- tiledb_ndrectangle(intdim))
expect_silent(ndr <- tiledb_ndrectangle(intdom))
expect_error(ndr <- tiledb_ndrectangle(dim))
expect_silent(ndr <- tiledb_ndrectangle(dom))
expect_true(is(ndr, "tiledb_ndrectangle"))

expect_error(tiledb_ndrectangle_set_range(intdim, "dim", 1, 2)) # wrong type
expect_error(tiledb_ndrectangle_set_range(dim, "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 if (grepl("FLOAT", tp)) {
expect_silent(ndr <- tiledb_ndrectangle_set_range(ndr, "dim", 1, 20))
} 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_get_range(dim, "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)))
Expand Down
17 changes: 15 additions & 2 deletions src/libtiledb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5468,8 +5468,14 @@ XPtr<tiledb::NDRectangle> libtiledb_ndrectangle_set_range(XPtr<tiledb::NDRectang
static_cast<int8_t>(Rcpp::as<int32_t>(end)));
} else if (dtype == TILEDB_UINT8) {
ndr->set_range<uint8_t>(dimname,
static_cast<uint8_t>(Rcpp::as<int32_t>(start)),
static_cast<uint8_t>(Rcpp::as<int32_t>(end)));
static_cast<uint8_t>(Rcpp::as<int32_t>(start)),
static_cast<uint8_t>(Rcpp::as<int32_t>(end)));
} else if (dtype == TILEDB_FLOAT64) {
ndr->set_range<double>(dimname, Rcpp::as<double>(start), Rcpp::as<double>(end));
} else if (dtype == TILEDB_FLOAT32) {
ndr->set_range<float>(dimname,
static_cast<float>(Rcpp::as<double>(start)),
static_cast<float>(Rcpp::as<double>(end)));
} else {
Rcpp::stop("Domain datatype '%s' of dimname '%s' is not currently supported",
_tiledb_datatype_to_string(dtype), dimname);
Expand Down Expand Up @@ -5517,6 +5523,13 @@ SEXP libtiledb_ndrectangle_get_range(XPtr<tiledb::NDRectangle> ndr,
auto range = ndr->range<uint8_t>(dimname);
return Rcpp::IntegerVector::create( static_cast<int32_t>(range[0]),
static_cast<int32_t>(range[1]) );
} else if (dtype == "FLOAT64") {
auto range = ndr->range<double>(dimname);
return Rcpp::NumericVector::create(range[0], range[1]);
} else if (dtype == "FLOAT32") {
auto range = ndr->range<float>(dimname);
return Rcpp::NumericVector::create( static_cast<double>(range[0]),
static_cast<double>(range[1]));
} else {
Rcpp::stop("Domain datatype '%s' of dimname '%s' is not currently supported", dtype, dimname);
}
Expand Down

0 comments on commit d6bda66

Please sign in to comment.