Skip to content

Commit

Permalink
[r] Proper prefixing for shape-related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Oct 25, 2024
1 parent fe534fd commit 5b4695e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 31 deletions.
12 changes: 6 additions & 6 deletions apis/r/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ c_schema <- function(uri, ctxxp) {
.Call(`_tiledbsoma_c_schema`, uri, ctxxp)
}

resize <- function(uri, new_shape, ctxxp) {
invisible(.Call(`_tiledbsoma_resize`, uri, new_shape, ctxxp))
resize <- function(uri, new_shape, function_name_for_messages, ctxxp) {
invisible(.Call(`_tiledbsoma_resize`, uri, new_shape, function_name_for_messages, ctxxp))
}

resize_soma_joinid_shape <- function(uri, new_shape, ctxxp) {
invisible(.Call(`_tiledbsoma_resize_soma_joinid_shape`, uri, new_shape, ctxxp))
resize_soma_joinid_shape <- function(uri, new_shape, function_name_for_messages, ctxxp) {
invisible(.Call(`_tiledbsoma_resize_soma_joinid_shape`, uri, new_shape, function_name_for_messages, ctxxp))
}

tiledbsoma_upgrade_shape <- function(uri, new_shape, ctxxp) {
invisible(.Call(`_tiledbsoma_tiledbsoma_upgrade_shape`, uri, new_shape, ctxxp))
tiledbsoma_upgrade_shape <- function(uri, new_shape, function_name_for_messages, ctxxp) {
invisible(.Call(`_tiledbsoma_tiledbsoma_upgrade_shape`, uri, new_shape, function_name_for_messages, ctxxp))
}

c_update_dataframe_schema <- function(uri, ctxxp, column_names_to_drop, add_cols_types, add_cols_enum_value_types, add_cols_enum_ordered) {
Expand Down
6 changes: 4 additions & 2 deletions apis/r/R/SOMADataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,15 @@ SOMADataFrame <- R6::R6Class(
#' @param new_shape An integer, greater than or equal to 1 + the
#' `soma_joinid` domain slot.
#' @return No return value
resize_soma_joinid_shape = function(new_shape) {
tiledbsoma_resize_soma_joinid_shape = function(new_shape) {

stopifnot("'new_shape' must be an integer" = rlang::is_integerish(new_shape, n = 1) ||
(bit64::is.integer64(new_shape) && length(new_shape) == 1)
)
# Checking slotwise new shape >= old shape, and <= max_shape, is already done in libtiledbsoma
invisible(resize_soma_joinid_shape(self$uri, new_shape, private$.soma_context))
invisible(
resize_soma_joinid_shape(
self$uri, new_shape, "tiledbsoma_resize_soma_joinid_shape", private$.soma_context))
}

),
Expand Down
4 changes: 2 additions & 2 deletions apis/r/R/SOMANDArrayBase.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ SOMANDArrayBase <- R6::R6Class(
(bit64::is.integer64(new_shape) && length(new_shape) == self$ndim())
)
# Checking slotwise new shape >= old shape, and <= max_shape, is already done in libtiledbsoma
resize(self$uri, new_shape, private$.soma_context)
resize(self$uri, new_shape, "resize", private$.soma_context)
},

#' @description Allows the array to have a resizeable shape as described in the
Expand All @@ -125,7 +125,7 @@ SOMANDArrayBase <- R6::R6Class(
(bit64::is.integer64(shape) && length(shape) == self$ndim())
)
# Checking slotwise new shape >= old shape, and <= max_shape, is already done in libtiledbsoma
tiledbsoma_upgrade_shape(self$uri, shape, private$.soma_context)
tiledbsoma_upgrade_shape(self$uri, shape, "tiledbsoma_upgrade_shape", private$.soma_context)
}

),
Expand Down
2 changes: 1 addition & 1 deletion apis/r/R/write_soma.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ write_soma.data.frame <- function(
}
}
if (ingest_mode %in% c('resume') && sdf$tiledbsoma_has_upgraded_domain()) {
sdf$resize_soma_joinid_shape(nrow(x))
sdf$tiledbsoma_resize_soma_joinid_shape(nrow(x))
}
if (!is.null(tbl)) {
sdf$write(tbl)
Expand Down
27 changes: 15 additions & 12 deletions apis/r/src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,38 +553,41 @@ BEGIN_RCPP
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) {
void resize(const std::string& uri, Rcpp::NumericVector new_shape, std::string function_name_for_messages, Rcpp::XPtr<somactx_wrap_t> ctxxp);
RcppExport SEXP _tiledbsoma_resize(SEXP uriSEXP, SEXP new_shapeSEXP, SEXP function_name_for_messagesSEXP, SEXP ctxxpSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const std::string& >::type uri(uriSEXP);
Rcpp::traits::input_parameter< Rcpp::NumericVector >::type new_shape(new_shapeSEXP);
Rcpp::traits::input_parameter< std::string >::type function_name_for_messages(function_name_for_messagesSEXP);
Rcpp::traits::input_parameter< Rcpp::XPtr<somactx_wrap_t> >::type ctxxp(ctxxpSEXP);
resize(uri, new_shape, ctxxp);
resize(uri, new_shape, function_name_for_messages, ctxxp);
return R_NilValue;
END_RCPP
}
// resize_soma_joinid_shape
void resize_soma_joinid_shape(const std::string& uri, Rcpp::NumericVector new_shape, Rcpp::XPtr<somactx_wrap_t> ctxxp);
RcppExport SEXP _tiledbsoma_resize_soma_joinid_shape(SEXP uriSEXP, SEXP new_shapeSEXP, SEXP ctxxpSEXP) {
void resize_soma_joinid_shape(const std::string& uri, Rcpp::NumericVector new_shape, std::string function_name_for_messages, Rcpp::XPtr<somactx_wrap_t> ctxxp);
RcppExport SEXP _tiledbsoma_resize_soma_joinid_shape(SEXP uriSEXP, SEXP new_shapeSEXP, SEXP function_name_for_messagesSEXP, SEXP ctxxpSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const std::string& >::type uri(uriSEXP);
Rcpp::traits::input_parameter< Rcpp::NumericVector >::type new_shape(new_shapeSEXP);
Rcpp::traits::input_parameter< std::string >::type function_name_for_messages(function_name_for_messagesSEXP);
Rcpp::traits::input_parameter< Rcpp::XPtr<somactx_wrap_t> >::type ctxxp(ctxxpSEXP);
resize_soma_joinid_shape(uri, new_shape, ctxxp);
resize_soma_joinid_shape(uri, new_shape, function_name_for_messages, ctxxp);
return R_NilValue;
END_RCPP
}
// tiledbsoma_upgrade_shape
void tiledbsoma_upgrade_shape(const std::string& uri, Rcpp::NumericVector new_shape, Rcpp::XPtr<somactx_wrap_t> ctxxp);
RcppExport SEXP _tiledbsoma_tiledbsoma_upgrade_shape(SEXP uriSEXP, SEXP new_shapeSEXP, SEXP ctxxpSEXP) {
void tiledbsoma_upgrade_shape(const std::string& uri, Rcpp::NumericVector new_shape, std::string function_name_for_messages, Rcpp::XPtr<somactx_wrap_t> ctxxp);
RcppExport SEXP _tiledbsoma_tiledbsoma_upgrade_shape(SEXP uriSEXP, SEXP new_shapeSEXP, SEXP function_name_for_messagesSEXP, SEXP ctxxpSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const std::string& >::type uri(uriSEXP);
Rcpp::traits::input_parameter< Rcpp::NumericVector >::type new_shape(new_shapeSEXP);
Rcpp::traits::input_parameter< std::string >::type function_name_for_messages(function_name_for_messagesSEXP);
Rcpp::traits::input_parameter< Rcpp::XPtr<somactx_wrap_t> >::type ctxxp(ctxxpSEXP);
tiledbsoma_upgrade_shape(uri, new_shape, ctxxp);
tiledbsoma_upgrade_shape(uri, new_shape, function_name_for_messages, ctxxp);
return R_NilValue;
END_RCPP
}
Expand Down Expand Up @@ -816,9 +819,9 @@ static const R_CallMethodDef CallEntries[] = {
{"_tiledbsoma_c_dimnames", (DL_FUNC) &_tiledbsoma_c_dimnames, 2},
{"_tiledbsoma_c_attrnames", (DL_FUNC) &_tiledbsoma_c_attrnames, 2},
{"_tiledbsoma_c_schema", (DL_FUNC) &_tiledbsoma_c_schema, 2},
{"_tiledbsoma_resize", (DL_FUNC) &_tiledbsoma_resize, 3},
{"_tiledbsoma_resize_soma_joinid_shape", (DL_FUNC) &_tiledbsoma_resize_soma_joinid_shape, 3},
{"_tiledbsoma_tiledbsoma_upgrade_shape", (DL_FUNC) &_tiledbsoma_tiledbsoma_upgrade_shape, 3},
{"_tiledbsoma_resize", (DL_FUNC) &_tiledbsoma_resize, 4},
{"_tiledbsoma_resize_soma_joinid_shape", (DL_FUNC) &_tiledbsoma_resize_soma_joinid_shape, 4},
{"_tiledbsoma_tiledbsoma_upgrade_shape", (DL_FUNC) &_tiledbsoma_tiledbsoma_upgrade_shape, 4},
{"_tiledbsoma_c_update_dataframe_schema", (DL_FUNC) &_tiledbsoma_c_update_dataframe_schema, 6},
{"_tiledbsoma_sr_setup", (DL_FUNC) &_tiledbsoma_sr_setup, 10},
{"_tiledbsoma_sr_complete", (DL_FUNC) &_tiledbsoma_sr_complete, 1},
Expand Down
9 changes: 6 additions & 3 deletions apis/r/src/rinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,41 +421,44 @@ SEXP c_schema(const std::string& uri, Rcpp::XPtr<somactx_wrap_t> ctxxp) {
void resize(
const std::string& uri,
Rcpp::NumericVector new_shape,
std::string function_name_for_messages,
Rcpp::XPtr<somactx_wrap_t> ctxxp) {
// This function is solely for SparseNDArray and DenseNDArray for which the
// dims are required by the SOMA spec to be of type int64. Domain-resize for
// variant-indexed dataframes will be separate work as tracked on
// https://github.com/single-cell-data/TileDB-SOMA/issues/2407.
auto sr = tdbs::SOMAArray::open(OpenMode::write, uri, ctxxp->ctxptr);
std::vector<int64_t> new_shape_i64 = i64_from_rcpp_numeric(new_shape);
sr->resize(new_shape_i64, "resize");
sr->resize(new_shape_i64, function_name_for_messages);
sr->close();
}

// [[Rcpp::export]]
void resize_soma_joinid_shape(
const std::string& uri,
Rcpp::NumericVector new_shape,
std::string function_name_for_messages,
Rcpp::XPtr<somactx_wrap_t> ctxxp) {
// This function is solely for SOMADataFrame.
auto sr = tdbs::SOMADataFrame::open(uri, OpenMode::write, ctxxp->ctxptr);
std::vector<int64_t> new_shape_i64 = i64_from_rcpp_numeric(new_shape);
sr->resize_soma_joinid_shape(new_shape_i64[0], "resize_soma_joinid_shape");
sr->resize_soma_joinid_shape(new_shape_i64[0], function_name_for_messages);
sr->close();
}

// [[Rcpp::export]]
void tiledbsoma_upgrade_shape(
const std::string& uri,
Rcpp::NumericVector new_shape,
std::string function_name_for_messages,
Rcpp::XPtr<somactx_wrap_t> ctxxp) {
// This function is solely for SparseNDArray and DenseNDArray for which the
// dims are required by the SOMA spec to be of type int64. Domain-resize for
// variant-indexed dataframes will be separate work as tracked on
// https://github.com/single-cell-data/TileDB-SOMA/issues/2407.
auto sr = tdbs::SOMAArray::open(OpenMode::write, uri, ctxxp->ctxptr);
std::vector<int64_t> new_shape_i64 = i64_from_rcpp_numeric(new_shape);
sr->upgrade_shape(new_shape_i64, "tiledbsoma_upgrade_shape");
sr->upgrade_shape(new_shape_i64, function_name_for_messages);
sr->close();
}

Expand Down
8 changes: 4 additions & 4 deletions apis/r/tests/testthat/test-shape.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ test_that("SOMADataFrame shape", {
sdf <- SOMADataFrameOpen(uri, "WRITE")
if (has_soma_joinid_dim) {
# It's an error to downsize
expect_error(sdf$resize_soma_joinid_shape(new_shape))
expect_error(sdf$tiledbsoma_resize_soma_joinid_shape(new_shape))
} else {
# There is no problem when soma_joinid is not a dim --
# sdf$resize_soma_joinid_shape is a no-op in that case
expect_no_condition(sdf$resize_soma_joinid_shape(new_shape))
# sdf$tiledbsoma_resize_soma_joinid_shape is a no-op in that case
expect_no_condition(sdf$tiledbsoma_resize_soma_joinid_shape(new_shape))
}
sdf$close()

Expand Down Expand Up @@ -238,7 +238,7 @@ test_that("SOMADataFrame shape", {

# Test resize
sdf <- SOMADataFrameOpen(uri, "WRITE")
sdf$resize_soma_joinid_shape(new_shape)
sdf$tiledbsoma_resize_soma_joinid_shape(new_shape)
sdf$close();

# Test writes out of old bounds, within new bounds, after resize
Expand Down
2 changes: 1 addition & 1 deletion apis/r/tests/testthat/test-write-soma-resume.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ test_that("Resume-mode data frames", {

if (.new_shape_feature_flag_is_enabled()) {
sdfp$reopen("WRITE")
sdfp$resize_soma_joinid_shape(nrow(co2))
sdfp$tiledbsoma_resize_soma_joinid_shape(nrow(co2))
}

expect_s3_class(
Expand Down

0 comments on commit 5b4695e

Please sign in to comment.