From 6d2db6dbadfffe4ff09c2d8e4ce60941adc933fe Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 24 Sep 2024 21:11:37 -0400 Subject: [PATCH] [r] Push `ndim` down to C++ --- apis/r/R/RcppExports.R | 4 ++++ apis/r/R/TileDBArray.R | 3 +-- apis/r/src/RcppExports.cpp | 13 +++++++++++++ apis/r/src/rinterface.cpp | 10 ++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/apis/r/R/RcppExports.R b/apis/r/R/RcppExports.R index 8e1a938bf9..ad37c6402e 100644 --- a/apis/r/R/RcppExports.R +++ b/apis/r/R/RcppExports.R @@ -192,6 +192,10 @@ has_current_domain <- function(uri, ctxxp) { .Call(`_tiledbsoma_has_current_domain`, uri, ctxxp) } +ndim <- function(uri, ctxxp) { + .Call(`_tiledbsoma_ndim`, uri, ctxxp) +} + resize <- function(uri, new_shape, ctxxp) { invisible(.Call(`_tiledbsoma_resize`, uri, new_shape, ctxxp)) } diff --git a/apis/r/R/TileDBArray.R b/apis/r/R/TileDBArray.R index 64923c82b0..f974022b7a 100644 --- a/apis/r/R/TileDBArray.R +++ b/apis/r/R/TileDBArray.R @@ -248,8 +248,7 @@ TileDBArray <- R6::R6Class( #' @description Retrieve number of dimensions (lifecycle: maturing) #' @return A scalar with the number of dimensions ndim = function() { - dims <- tiledb::dimensions(self$tiledb_schema()) - length(dims) + ndim(self$uri, private$.soma_context) }, #' @description Retrieve the array attributes (lifecycle: maturing) diff --git a/apis/r/src/RcppExports.cpp b/apis/r/src/RcppExports.cpp index 7de387a80c..dceab26f3e 100644 --- a/apis/r/src/RcppExports.cpp +++ b/apis/r/src/RcppExports.cpp @@ -416,6 +416,18 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// ndim +Rcpp::NumericVector ndim(const std::string& uri, Rcpp::XPtr ctxxp); +RcppExport SEXP _tiledbsoma_ndim(SEXP uriSEXP, SEXP ctxxpSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const std::string& >::type uri(uriSEXP); + Rcpp::traits::input_parameter< Rcpp::XPtr >::type ctxxp(ctxxpSEXP); + rcpp_result_gen = Rcpp::wrap(ndim(uri, ctxxp)); + return rcpp_result_gen; +END_RCPP +} // resize void resize(const std::string& uri, Rcpp::NumericVector new_shape, Rcpp::XPtr ctxxp); RcppExport SEXP _tiledbsoma_resize(SEXP uriSEXP, SEXP new_shapeSEXP, SEXP ctxxpSEXP) { @@ -642,6 +654,7 @@ static const R_CallMethodDef CallEntries[] = { {"_tiledbsoma_maybe_soma_joinid_shape", (DL_FUNC) &_tiledbsoma_maybe_soma_joinid_shape, 2}, {"_tiledbsoma_maybe_soma_joinid_maxshape", (DL_FUNC) &_tiledbsoma_maybe_soma_joinid_maxshape, 2}, {"_tiledbsoma_has_current_domain", (DL_FUNC) &_tiledbsoma_has_current_domain, 2}, + {"_tiledbsoma_ndim", (DL_FUNC) &_tiledbsoma_ndim, 2}, {"_tiledbsoma_resize", (DL_FUNC) &_tiledbsoma_resize, 3}, {"_tiledbsoma_tiledbsoma_upgrade_shape", (DL_FUNC) &_tiledbsoma_tiledbsoma_upgrade_shape, 3}, {"_tiledbsoma_sr_setup", (DL_FUNC) &_tiledbsoma_sr_setup, 10}, diff --git a/apis/r/src/rinterface.cpp b/apis/r/src/rinterface.cpp index ca34e14356..4123dd3775 100644 --- a/apis/r/src/rinterface.cpp +++ b/apis/r/src/rinterface.cpp @@ -285,6 +285,16 @@ Rcpp::LogicalVector has_current_domain(const std::string& uri, Rcpp::XPtr ctxxp) { + auto sr = tdbs::SOMAArray::open(OpenMode::read, uri, ctxxp->ctxptr); + auto lib_retval = sr->ndim(); + sr->close(); + + return Rcpp::NumericVector::create(lib_retval); +} + // [[Rcpp::export]] void resize(const std::string& uri, Rcpp::NumericVector new_shape,