From c9f536b9f23f496524d493b8aa0e1c3a5b008e12 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 25 Sep 2024 11:03:29 -0400 Subject: [PATCH 1/2] [r] Push dimnames down to C++ --- apis/r/R/RcppExports.R | 4 ++++ apis/r/R/TileDBArray.R | 7 +------ apis/r/src/RcppExports.cpp | 13 +++++++++++++ apis/r/src/rinterface.cpp | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/apis/r/R/RcppExports.R b/apis/r/R/RcppExports.R index a4c0f9aaf0..32dcee6ac5 100644 --- a/apis/r/R/RcppExports.R +++ b/apis/r/R/RcppExports.R @@ -198,6 +198,10 @@ ndim <- function(uri, ctxxp) { .Call(`_tiledbsoma_ndim`, uri, ctxxp) } +dimnames <- function(uri, ctxxp) { + .Call(`_tiledbsoma_dimnames`, 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 8ed0bfd571..4f4eb088a9 100644 --- a/apis/r/R/TileDBArray.R +++ b/apis/r/R/TileDBArray.R @@ -260,12 +260,7 @@ TileDBArray <- R6::R6Class( #' @description Retrieve dimension names (lifecycle: maturing) #' @return A character vector with the array's dimension names dimnames = function() { - vapply( - self$dimensions(), - FUN = tiledb::name, - FUN.VALUE = vector("character", 1L), - USE.NAMES = FALSE - ) + dimnames(self$uri, private$.soma_context) }, #' @description Retrieve attribute names (lifecycle: maturing) diff --git a/apis/r/src/RcppExports.cpp b/apis/r/src/RcppExports.cpp index dceab26f3e..8658929323 100644 --- a/apis/r/src/RcppExports.cpp +++ b/apis/r/src/RcppExports.cpp @@ -428,6 +428,18 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// dimnames +Rcpp::CharacterVector dimnames(const std::string& uri, Rcpp::XPtr ctxxp); +RcppExport SEXP _tiledbsoma_dimnames(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(dimnames(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) { @@ -655,6 +667,7 @@ static const R_CallMethodDef CallEntries[] = { {"_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_dimnames", (DL_FUNC) &_tiledbsoma_dimnames, 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 ced9ba4951..04fe817458 100644 --- a/apis/r/src/rinterface.cpp +++ b/apis/r/src/rinterface.cpp @@ -329,6 +329,20 @@ Rcpp::NumericVector ndim( sr->close(); return Rcpp::NumericVector::create(lib_retval); + +// [[Rcpp::export]] +Rcpp::CharacterVector dimnames( + const std::string& uri, Rcpp::XPtr ctxxp) { + auto sr = tdbs::SOMAArray::open(OpenMode::read, uri, ctxxp->ctxptr); + auto lib_retval = sr->dimension_names(); + sr->close(); + + size_t n = lib_retval.size(); + Rcpp::CharacterVector retval(n); + for (size_t i = 0; i < n; i++) { + retval[i] = lib_retval[i]; + } + return retval; } // [[Rcpp::export]] From 32b577e40a44d55b38b3a0a5cdac50a61e802c66 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Thu, 26 Sep 2024 19:32:58 -0400 Subject: [PATCH 2/2] fix error message "argument ctxxp is missing with no default" --- apis/r/R/RcppExports.R | 4 ++-- apis/r/R/TileDBArray.R | 2 +- apis/r/src/RcppExports.cpp | 10 +++++----- apis/r/src/rinterface.cpp | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/apis/r/R/RcppExports.R b/apis/r/R/RcppExports.R index 32dcee6ac5..f5906c2c9b 100644 --- a/apis/r/R/RcppExports.R +++ b/apis/r/R/RcppExports.R @@ -198,8 +198,8 @@ ndim <- function(uri, ctxxp) { .Call(`_tiledbsoma_ndim`, uri, ctxxp) } -dimnames <- function(uri, ctxxp) { - .Call(`_tiledbsoma_dimnames`, uri, ctxxp) +c_dimnames <- function(uri, ctxxp) { + .Call(`_tiledbsoma_c_dimnames`, uri, ctxxp) } resize <- function(uri, new_shape, ctxxp) { diff --git a/apis/r/R/TileDBArray.R b/apis/r/R/TileDBArray.R index 4f4eb088a9..fb7719544e 100644 --- a/apis/r/R/TileDBArray.R +++ b/apis/r/R/TileDBArray.R @@ -260,7 +260,7 @@ TileDBArray <- R6::R6Class( #' @description Retrieve dimension names (lifecycle: maturing) #' @return A character vector with the array's dimension names dimnames = function() { - dimnames(self$uri, private$.soma_context) + c_dimnames(self$uri, private$.soma_context) }, #' @description Retrieve attribute names (lifecycle: maturing) diff --git a/apis/r/src/RcppExports.cpp b/apis/r/src/RcppExports.cpp index 8658929323..332271939d 100644 --- a/apis/r/src/RcppExports.cpp +++ b/apis/r/src/RcppExports.cpp @@ -428,15 +428,15 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// dimnames -Rcpp::CharacterVector dimnames(const std::string& uri, Rcpp::XPtr ctxxp); -RcppExport SEXP _tiledbsoma_dimnames(SEXP uriSEXP, SEXP ctxxpSEXP) { +// c_dimnames +Rcpp::CharacterVector c_dimnames(const std::string& uri, Rcpp::XPtr ctxxp); +RcppExport SEXP _tiledbsoma_c_dimnames(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(dimnames(uri, ctxxp)); + rcpp_result_gen = Rcpp::wrap(c_dimnames(uri, ctxxp)); return rcpp_result_gen; END_RCPP } @@ -667,7 +667,7 @@ static const R_CallMethodDef CallEntries[] = { {"_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_dimnames", (DL_FUNC) &_tiledbsoma_dimnames, 2}, + {"_tiledbsoma_c_dimnames", (DL_FUNC) &_tiledbsoma_c_dimnames, 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 04fe817458..3cb7acf25e 100644 --- a/apis/r/src/rinterface.cpp +++ b/apis/r/src/rinterface.cpp @@ -329,9 +329,10 @@ Rcpp::NumericVector ndim( sr->close(); return Rcpp::NumericVector::create(lib_retval); +} // [[Rcpp::export]] -Rcpp::CharacterVector dimnames( +Rcpp::CharacterVector c_dimnames( const std::string& uri, Rcpp::XPtr ctxxp) { auto sr = tdbs::SOMAArray::open(OpenMode::read, uri, ctxxp->ctxptr); auto lib_retval = sr->dimension_names();