From bebad0eb9c723d729dc2fecb826cd677c2cb1611 Mon Sep 17 00:00:00 2001 From: Matthew Fidler Date: Sun, 22 Sep 2024 22:32:28 -0500 Subject: [PATCH] Revert "Reduce arguments in preparation for DRY script indexer use" This reverts commit 7f29919ce2892106dd3e50ecd6be99829f003646. --- R/RcppExports.R | 4 ++-- R/poped.R | 7 ++++--- .../ex.1.a.PK.1.comp.oral.md.intro.babelmixr2.R | 10 ---------- src/RcppExports.cpp | 11 ++++++++--- src/init.c | 4 ++-- src/poped.cpp | 17 +++++++++-------- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index 7edbefd2..97659764 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -149,8 +149,8 @@ popedSetup <- function(e, full) { .Call(`_babelmixr2_popedSetup`, e, full) } -popedSolveIdME <- function(theta, id) { - .Call(`_babelmixr2_popedSolveIdME`, theta, id) +popedSolveIdME <- function(theta, umt, mt, ms, nend, id, totn) { + .Call(`_babelmixr2_popedSolveIdME`, theta, umt, mt, ms, nend, id, totn) } popedSolveIdME2 <- function(theta, umt, mt, ms, nend, id, totn) { diff --git a/R/poped.R b/R/poped.R index 5bcef56f..861124fa 100644 --- a/R/poped.R +++ b/R/poped.R @@ -42,8 +42,8 @@ #' @export #' @author Matthew L. Fidler #' @keywords internal -.popedSolveIdME <- function(theta, id) { - .Call(`_babelmixr2_popedSolveIdME`, theta, id) +.popedSolveIdME <- function(theta, umt, mt, ms, nend, id, totn) { + .Call(`_babelmixr2_popedSolveIdME`, theta, umt, mt, ms, nend, id, totn) } #' @rdname dot-popedSolveIdME @@ -340,7 +340,8 @@ rxUiGet.popedFfFun <- function(x, ...) { .(.poped$maxn), poped.db$babelmixr2$optTime) .popedRxRunSetup(poped.db) - .ret <- .popedSolveIdME(.p, .id-1) + .ret <- .popedSolveIdME(.p, .u, .xt, model_switch, .(length(.predDf$cond)), + .id-1, .totn) } else if (.lu > .(.poped$maxn)) { .p <- p[-1] .popedRxRunFullSetupMe(poped.db, .xt, model_switch) diff --git a/inst/poped/ex.1.a.PK.1.comp.oral.md.intro.babelmixr2.R b/inst/poped/ex.1.a.PK.1.comp.oral.md.intro.babelmixr2.R index 6823e886..ea8a5a87 100644 --- a/inst/poped/ex.1.a.PK.1.comp.oral.md.intro.babelmixr2.R +++ b/inst/poped/ex.1.a.PK.1.comp.oral.md.intro.babelmixr2.R @@ -46,16 +46,6 @@ e <- et(list(c(0, 10), #xt e$time <- c(1,2,8,240,245) -f <- f() - -babel.db <- nlmixr2(f, e, "poped", - popedControl(groupsize=20, - bUseGrouped_xt=TRUE, - a=list(c(DOSE=20,TAU=24), - c(DOSE=40, TAU=24)), - maxa=c(DOSE=200,TAU=24), - mina=c(DOSE=0,TAU=24), - script=TRUE)) babel.db <- nlmixr2(f, e, "poped", popedControl(groupsize=20, diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 99a87787..abe37bda 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -106,14 +106,19 @@ BEGIN_RCPP END_RCPP } // popedSolveIdME -Rcpp::DataFrame popedSolveIdME(NumericVector& theta, int id); -RcppExport SEXP _babelmixr2_popedSolveIdME(SEXP thetaSEXP, SEXP idSEXP) { +Rcpp::DataFrame popedSolveIdME(NumericVector& theta, NumericVector& umt, NumericVector& mt, IntegerVector& ms, int nend, int id, int totn); +RcppExport SEXP _babelmixr2_popedSolveIdME(SEXP thetaSEXP, SEXP umtSEXP, SEXP mtSEXP, SEXP msSEXP, SEXP nendSEXP, SEXP idSEXP, SEXP totnSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< NumericVector& >::type theta(thetaSEXP); + Rcpp::traits::input_parameter< NumericVector& >::type umt(umtSEXP); + Rcpp::traits::input_parameter< NumericVector& >::type mt(mtSEXP); + Rcpp::traits::input_parameter< IntegerVector& >::type ms(msSEXP); + Rcpp::traits::input_parameter< int >::type nend(nendSEXP); Rcpp::traits::input_parameter< int >::type id(idSEXP); - rcpp_result_gen = Rcpp::wrap(popedSolveIdME(theta, id)); + Rcpp::traits::input_parameter< int >::type totn(totnSEXP); + rcpp_result_gen = Rcpp::wrap(popedSolveIdME(theta, umt, mt, ms, nend, id, totn)); return rcpp_result_gen; END_RCPP } diff --git a/src/init.c b/src/init.c index fd8d2244..f26569b5 100644 --- a/src/init.c +++ b/src/init.c @@ -14,7 +14,7 @@ SEXP _babelmixr2_iniRxodePtrs(SEXP in); SEXP _babelmixr2_popedFree(void); SEXP _babelmixr2_popedSetup(SEXP eSEXP, SEXP fullSEXP); -SEXP _babelmixr2_popedSolveIdME(SEXP thetaSEXP, SEXP idSEXP); +SEXP _babelmixr2_popedSolveIdME(SEXP thetaSEXP, SEXP umtSEXP, SEXP mtSEXP, SEXP msSEXP, SEXP nendSEXP, SEXP idSEXP, SEXP totnSEXP); SEXP _babelmixr2_popedSolveIdME2(SEXP thetaSEXP, SEXP umtSEXP, SEXP mtSEXP, SEXP msSEXP, SEXP nendSEXP, SEXP idSEXP, SEXP totnSEXP); SEXP _babelmixr2_popedGetMultipleEndpointModelingTimes(SEXP, SEXP, SEXP); SEXP _babelmixr2_popedMultipleEndpointResetTimeIndex(void); @@ -30,7 +30,7 @@ static const R_CallMethodDef CallEntries[] = { (DL_FUNC) &_babelmixr2_popedGetMultipleEndpointModelingTimes, 3}, {"_babelmixr2_popedFree", (DL_FUNC) &_babelmixr2_popedFree, 0}, {"_babelmixr2_popedSetup", (DL_FUNC) &_babelmixr2_popedSetup, 2}, - {"_babelmixr2_popedSolveIdME", (DL_FUNC) &_babelmixr2_popedSolveIdME, 2}, + {"_babelmixr2_popedSolveIdME", (DL_FUNC) &_babelmixr2_popedSolveIdME, 7}, {"_babelmixr2_popedSolveIdME2", (DL_FUNC) &_babelmixr2_popedSolveIdME2, 7}, {"_babelmixr2_iniRxodePtrs", (DL_FUNC) &_babelmixr2_iniRxodePtrs, 1}, {"_babelmixr2_convertDataBack", (DL_FUNC) &_babelmixr2_convertDataBack, 13}, diff --git a/src/poped.cpp b/src/poped.cpp index 82d94651..b3116229 100644 --- a/src/poped.cpp +++ b/src/poped.cpp @@ -491,14 +491,15 @@ void popedSolveFidMat(arma::mat &matMT, NumericVector &theta, int id, int nrow, } //[[Rcpp::export]] -Rcpp::DataFrame popedSolveIdME(NumericVector &theta, int id) { +Rcpp::DataFrame popedSolveIdME(NumericVector &theta, + NumericVector &umt, + NumericVector &mt, IntegerVector &ms, + int nend, int id, int totn) { if (solveCached(theta, id)) return(as(_popedE["s"])); - size_t totn = globalTimeIndexer.getTimes().size(); - size_t nend = globalTimeIndexer.getNid(); NumericVector t(totn); arma::vec f(totn); arma::vec w(totn); - size_t nrow = globalTimeIndexer.getUniqueTimes().size();//umt.size(); + int nrow = umt.size(); arma::mat matMT(nrow, nend*2+1); List we(nend); for (int i = 0; i < nend; i++) { @@ -524,12 +525,13 @@ Rcpp::DataFrame popedSolveIdME(NumericVector &theta, int id) { // This is not how rxode2/nlmixr2 handles the information, but this // routine should put it in whatever order is supplied to // model_switch and time + size_t nId = globalTimeIndexer.getNid(); std::vector ut = globalTimeIndexer.getUniqueTimes(); for (int i = 0; i < (int)ut.size(); ++i) { double curT = matMT(i, 0); const auto& infos= globalTimeIndexer.getTimeInfo(curT); for (const auto& info : infos) { - if (info.id > (int)nend || + if (info.id > (int)nId || info.id <= 0) { Rcpp::stop("modelSwitch need to be sequential 1, 2, 3, ..., n"); } @@ -540,9 +542,8 @@ Rcpp::DataFrame popedSolveIdME(NumericVector &theta, int id) { } } } - DataFrame ret = DataFrame::create(_["t"]=Rcpp::wrap(globalTimeIndexer.getTimes()), - _["ms"]= - Rcpp::wrap(globalTimeIndexer.getModelSwitch()), + DataFrame ret = DataFrame::create(_["t"]=mt, + _["ms"]=ms, _["rx_pred_"]=f, // match rxode2/nlmixr2 to simplify code of mtime models _["w"]=w); // w = sqrt(rx_r_) _popedE["s"] = ret;