Skip to content

Commit

Permalink
Revert "add popedPostSolveMat() for use in script"
Browse files Browse the repository at this point in the history
This reverts commit 8553764.
  • Loading branch information
mattfidler committed Sep 23, 2024
1 parent e073c15 commit 563bbe8
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 180 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export(popedGetMultipleEndpointModelingTimes)
export(popedMultipleEndpointIndexDataFrame)
export(popedMultipleEndpointParam)
export(popedMultipleEndpointResetTimeIndex)
export(popedPostSolveMat)
export(rxModelVars)
export(rxToMonolix)
export(rxToNonmem)
Expand Down
47 changes: 0 additions & 47 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,53 +149,6 @@ popedSetup <- function(e, full) {
.Call(`_babelmixr2_popedSetup`, e, full)
}

#' @title Get Solved f based on matched solving times
#' @description
#'
#' This function takes the solved matrix and matches it to the order
#' of the input times and model_switch from `PopED`. It assumes
#' the global time indexer has been setup with something like
#' `babelmixr2::popedMultipleEndpointParam()`
#'
#'
#'
#' @param matMT This is the solved matrix that with the following columns (in order):
#'
#' - `time`
#'
#' - For each endpoint it needs the following (repeated for each endpoint):
#'
#' - endpoint prediction (f)
#' - endpoint prediction variance (w)
#'
#' @param env This is an R environment where the boolean indexes of
#' which item is a which modeling switch is saved (as well as the
#' last data frame solved created by this method)
#'
#' @return A data.frame with the following output items:
#'
#' - `t` The time points
#'
#' - `ms` The model switch
#'
#' - `rx_pred_` The predicted value
#'
#' - `w` The variance of the predicted value
#'
#' This also has a side effect of saving the data.frame in the
#' environment as `s` and the boolean indexes of which item is a
#' which modeling switch is saved in the environment as `we`
#'
#' (i.e. env$we[[1]] is a boolean vector of which items are model switch 1,
#' env$we[[2]] is a boolean vector of which items are model switch 2, etc.)
#'
#' @keywords internal
#'
#' @export
popedPostSolveMat <- function(matMT, env) {
.Call(`_babelmixr2_popedPostSolveMat`, matMT, env)
}

popedSolveIdME <- function(theta, id) {
.Call(`_babelmixr2_popedSolveIdME`, theta, id)
}
Expand Down
6 changes: 3 additions & 3 deletions man/dot-popedSolveIdME.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 0 additions & 46 deletions man/popedPostSolveMat.Rd

This file was deleted.

12 changes: 0 additions & 12 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// popedPostSolveMat
Rcpp::DataFrame popedPostSolveMat(Rcpp::NumericMatrix& matMT, Rcpp::Environment& env);
RcppExport SEXP _babelmixr2_popedPostSolveMat(SEXP matMTSEXP, SEXP envSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Rcpp::NumericMatrix& >::type matMT(matMTSEXP);
Rcpp::traits::input_parameter< Rcpp::Environment& >::type env(envSEXP);
rcpp_result_gen = Rcpp::wrap(popedPostSolveMat(matMT, env));
return rcpp_result_gen;
END_RCPP
}
// popedSolveIdME
Rcpp::DataFrame popedSolveIdME(NumericVector& theta, int id);
RcppExport SEXP _babelmixr2_popedSolveIdME(SEXP thetaSEXP, SEXP idSEXP) {
Expand Down
2 changes: 0 additions & 2 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ SEXP _babelmixr2_popedGetMultipleEndpointModelingTimes(SEXP, SEXP, SEXP);
SEXP _babelmixr2_popedMultipleEndpointResetTimeIndex(void);
SEXP _babelmixr2_popedMultipleEndpointIndexDataFrame(SEXP);
SEXP _babelmixr2_popedMultipleEndpointParam(SEXP, SEXP, SEXP, SEXP, SEXP);
SEXP _babelmixr2_popedPostSolveMat(SEXP, SEXP);

static const R_CallMethodDef CallEntries[] = {
{"_babelmixr2_popedPostSolveMat", (DL_FUNC) &_babelmixr2_popedPostSolveMat, 2},
{"_babelmixr2_popedMultipleEndpointParam",
(DL_FUNC) &_babelmixr2_popedMultipleEndpointParam, 5},
{"_babelmixr2_popedMultipleEndpointIndexDataFrame", (DL_FUNC) &_babelmixr2_popedMultipleEndpointIndexDataFrame, 1},
Expand Down
79 changes: 10 additions & 69 deletions src/poped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,16 @@ void popedSolveFidMat(arma::mat &matMT, NumericVector &theta, int id, int nrow,
}
}

Rcpp::DataFrame popedPostSolveMat(arma::mat& matMT, Rcpp::Environment& env) {
if (!globalTimeIndexer.isInitialized()) {
Rcpp::stop("time indexer has not been initialized");
}
size_t nrow = globalTimeIndexer.getUniqueTimes().size();//umt.size();
size_t nend = globalTimeIndexer.getNid();
//[[Rcpp::export]]
Rcpp::DataFrame popedSolveIdME(NumericVector &theta, int id) {
if (solveCached(theta, id)) return(as<Rcpp::DataFrame>(_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();
arma::mat matMT(nrow, nend*2+1);
List we(nend);
for (int i = 0; i < nend; i++) {
LogicalVector curLV = LogicalVector(totn);
Expand All @@ -507,7 +508,7 @@ Rcpp::DataFrame popedPostSolveMat(arma::mat& matMT, Rcpp::Environment& env) {
we[i] = curLV;
}


popedSolveFidMat(matMT, theta, id, nrow, nend);
// this gets the information from:
// - the model time
// - the model_switch
Expand Down Expand Up @@ -544,72 +545,12 @@ Rcpp::DataFrame popedPostSolveMat(arma::mat& matMT, Rcpp::Environment& env) {
Rcpp::wrap(globalTimeIndexer.getModelSwitch()),
_["rx_pred_"]=f, // match rxode2/nlmixr2 to simplify code of mtime models
_["w"]=w); // w = sqrt(rx_r_)
env["s"] = ret;
env["we"] = we;
_popedE["s"] = ret;
_popedE["we"] = we;
return ret;
}


//' @title Get Solved f based on matched solving times
//' @description
//'
//' This function takes the solved matrix and matches it to the order
//' of the input times and model_switch from `PopED`. It assumes
//' the global time indexer has been setup with something like
//' `babelmixr2::popedMultipleEndpointParam()`
//'
//'
//'
//' @param matMT This is the solved matrix that with the following columns (in order):
//'
//' - `time`
//'
//' - For each endpoint it needs the following (repeated for each endpoint):
//'
//' - endpoint prediction (f)
//' - endpoint prediction variance (w)
//'
//' @param env This is an R environment where the boolean indexes of
//' which item is a which modeling switch is saved (as well as the
//' last data frame solved created by this method)
//'
//' @return A data.frame with the following output items:
//'
//' - `t` The time points
//'
//' - `ms` The model switch
//'
//' - `rx_pred_` The predicted value
//'
//' - `w` The variance of the predicted value
//'
//' This also has a side effect of saving the data.frame in the
//' environment as `s` and the boolean indexes of which item is a
//' which modeling switch is saved in the environment as `we`
//'
//' (i.e. env$we[[1]] is a boolean vector of which items are model switch 1,
//' env$we[[2]] is a boolean vector of which items are model switch 2, etc.)
//'
//' @keywords internal
//'
//' @export
//[[Rcpp::export]]
Rcpp::DataFrame popedPostSolveMat(Rcpp::NumericMatrix& matMT, Rcpp::Environment& env) {
arma::mat matMT2 = as<arma::mat>(matMT);
return popedPostSolveMat(matMT2, env);
}

//[[Rcpp::export]]
Rcpp::DataFrame popedSolveIdME(NumericVector &theta, int id) {
if (solveCached(theta, id)) return(as<Rcpp::DataFrame>(_popedE["s"]));
size_t nrow = globalTimeIndexer.getUniqueTimes().size();//umt.size();
size_t nend = globalTimeIndexer.getNid();
arma::mat matMT(nrow, nend*2+1);
popedSolveFidMat(matMT, theta, id, nrow, nend);
return popedPostSolveMat(matMT, _popedE);
}


void popedSolveFidMat2(arma::mat &matMT, NumericVector &theta, int id, int nrow, int nend) {
// arma::vec ret(retD, nobs, false, true);
rx_solving_options_ind *ind = updateParamRetInd(theta, id);
Expand Down

0 comments on commit 563bbe8

Please sign in to comment.