Skip to content

Commit

Permalink
[r] Push ndim down to C++
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Sep 25, 2024
1 parent fd1537f commit 6d2db6d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions apis/r/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
3 changes: 1 addition & 2 deletions apis/r/R/TileDBArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions apis/r/src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// ndim
Rcpp::NumericVector ndim(const std::string& uri, Rcpp::XPtr<somactx_wrap_t> 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<somactx_wrap_t> >::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<somactx_wrap_t> ctxxp);
RcppExport SEXP _tiledbsoma_resize(SEXP uriSEXP, SEXP new_shapeSEXP, SEXP ctxxpSEXP) {
Expand Down Expand Up @@ -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},
Expand Down
10 changes: 10 additions & 0 deletions apis/r/src/rinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ Rcpp::LogicalVector has_current_domain(const std::string& uri, Rcpp::XPtr<somact
return retval;
}

// [[Rcpp::export]]
Rcpp::NumericVector ndim(
const std::string& uri, Rcpp::XPtr<somactx_wrap_t> 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,
Expand Down

0 comments on commit 6d2db6d

Please # to comment.