Skip to content

Commit

Permalink
Use the rxInner global def only and make this a R like fun
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Oct 23, 2024
1 parent 1795bc1 commit 906b503
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/poped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ struct rxSolveF {
};

rxSolveF rxInner;
SEXP rxUpdateFuns(SEXP trans, rxSolveF *inner){

SEXP rxUpdateFn(SEXP trans) {
rxSolveF *inner = &rxInner;
const char *lib, *s_dydt, *s_calc_jac, *s_calc_lhs, *s_inis, *s_dydt_lsoda_dum, *s_dydt_jdum_lsoda,
*s_ode_solver_solvedata, *s_ode_solver_get_solvedata, *s_dydt_liblsoda;
lib = CHAR(STRING_ELT(trans, 0));
Expand Down Expand Up @@ -311,6 +313,7 @@ SEXP rxUpdateFuns(SEXP trans, rxSolveF *inner){
return R_NilValue;
}


void rxClearFuns(rxSolveF *inner){
inner->calc_lhs = NULL;
inner->dydt = NULL;
Expand Down Expand Up @@ -374,7 +377,7 @@ RObject popedSetup(Environment e, Environment eglobal, bool full) {
List mvp = rxode2::rxModelVars_(model);
CharacterVector trans = mvp["trans"];
_popedEglobal["curTrans"] = trans;
rxUpdateFuns(as<SEXP>(trans), &rxInner);
rxUpdateFn(as<SEXP>(trans));

// initial value of parameters
CharacterVector pars = mvp[RxMv_params];
Expand Down Expand Up @@ -457,7 +460,7 @@ static inline bool solveCached(NumericVector &theta, int &id) {
}

void popedSolveFidMat(arma::mat &matMT, NumericVector &theta, int id, int nrow, int nend) {
rxUpdateFuns(_popedEglobal["curTrans"], &rxInner);
rxUpdateFn(_popedEglobal["curTrans"]);
// arma::vec ret(retD, nobs, false, true);
rx_solving_options_ind *ind = updateParamRetInd(theta, id);
rx_solving_options *op = getSolvingOptions(rx);
Expand Down Expand Up @@ -509,7 +512,7 @@ Rcpp::DataFrame popedSolveIdME(NumericVector &theta,
NumericVector &mt, IntegerVector &ms,
int nend, int id, int totn) {
if (solveCached(theta, id)) return(as<Rcpp::DataFrame>(_popedE["s"]));
rxUpdateFuns(_popedEglobal["curTrans"], &rxInner);
rxUpdateFn(_popedEglobal["curTrans"]);
NumericVector t(totn);
arma::vec f(totn);
arma::vec w(totn);
Expand Down

0 comments on commit 906b503

Please sign in to comment.