Skip to content

Commit

Permalink
Add rxSolveSetup
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Mar 20, 2024
1 parent 9257dc3 commit 0beb789
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ export(rxShiny)
export(rxSimThetaOmega)
export(rxSolve)
export(rxSolveFree)
export(rxSolveSetup)
export(rxSplitPlusQ)
export(rxStack)
export(rxState)
Expand Down
10 changes: 10 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ rxSolveFree <- function() {
.Call(`_rxode2_rxSolveFree`)
}

#' See if the memory is installed for a solve
#'
#' @return boolean saying if the memnory is currently free for rxode2
#' @keywords internal
#' @export
#' @author Matthew L. Fidler
rxSolveSetup <- function() {
.Call(`_rxode2_rxSolveSetup`)
}

rxSolve_ <- function(obj, rxControl, specParams, extraArgs, params, events, inits, setupOnly) {
.Call(`_rxode2_rxSolve_`, obj, rxControl, specParams, extraArgs, params, events, inits, setupOnly)
}
Expand Down
21 changes: 21 additions & 0 deletions inst/include/rxode2_RcppExports.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,27 @@ namespace rxode2 {
return Rcpp::as<LogicalVector >(rcpp_result_gen);
}

inline LogicalVector rxSolveSetup() {
typedef SEXP(*Ptr_rxSolveSetup)();
static Ptr_rxSolveSetup p_rxSolveSetup = NULL;
if (p_rxSolveSetup == NULL) {
validateSignature("LogicalVector(*rxSolveSetup)()");
p_rxSolveSetup = (Ptr_rxSolveSetup)R_GetCCallable("rxode2", "_rxode2_rxSolveSetup");
}
RObject rcpp_result_gen;
{
RNGScope RCPP_rngScope_gen;
rcpp_result_gen = p_rxSolveSetup();
}
if (rcpp_result_gen.inherits("interrupted-error"))
throw Rcpp::internal::InterruptedException();
if (Rcpp::internal::isLongjumpSentinel(rcpp_result_gen))
throw Rcpp::LongjumpException(rcpp_result_gen);
if (rcpp_result_gen.inherits("try-error"))
throw Rcpp::exception(Rcpp::as<std::string>(rcpp_result_gen).c_str());
return Rcpp::as<LogicalVector >(rcpp_result_gen);
}

inline SEXP rxSolve_(const RObject& obj, const List& rxControl, const Nullable<CharacterVector>& specParams, const Nullable<List>& extraArgs, const RObject& params, const RObject& events, const RObject& inits, const int setupOnly) {
typedef SEXP(*Ptr_rxSolve_)(SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP,SEXP);
static Ptr_rxSolve_ p_rxSolve_ = NULL;
Expand Down
18 changes: 18 additions & 0 deletions man/rxSolveSetup.Rd

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

35 changes: 35 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,39 @@ RcppExport SEXP _rxode2_rxSolveFree() {
UNPROTECT(1);
return rcpp_result_gen;
}
// rxSolveSetup
LogicalVector rxSolveSetup();
static SEXP _rxode2_rxSolveSetup_try() {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
rcpp_result_gen = Rcpp::wrap(rxSolveSetup());
return rcpp_result_gen;
END_RCPP_RETURN_ERROR
}
RcppExport SEXP _rxode2_rxSolveSetup() {
SEXP rcpp_result_gen;
{
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = PROTECT(_rxode2_rxSolveSetup_try());
}
Rboolean rcpp_isInterrupt_gen = Rf_inherits(rcpp_result_gen, "interrupted-error");
if (rcpp_isInterrupt_gen) {
UNPROTECT(1);
Rf_onintr();
}
bool rcpp_isLongjump_gen = Rcpp::internal::isLongjumpSentinel(rcpp_result_gen);
if (rcpp_isLongjump_gen) {
Rcpp::internal::resumeJump(rcpp_result_gen);
}
Rboolean rcpp_isError_gen = Rf_inherits(rcpp_result_gen, "try-error");
if (rcpp_isError_gen) {
SEXP rcpp_msgSEXP_gen = Rf_asChar(rcpp_result_gen);
UNPROTECT(1);
Rf_error("%s", CHAR(rcpp_msgSEXP_gen));
}
UNPROTECT(1);
return rcpp_result_gen;
}
// rxSolve_
SEXP rxSolve_(const RObject& obj, const List& rxControl, const Nullable<CharacterVector>& specParams, const Nullable<List>& extraArgs, const RObject& params, const RObject& events, const RObject& inits, const int setupOnly);
static SEXP _rxode2_rxSolve__try(SEXP objSEXP, SEXP rxControlSEXP, SEXP specParamsSEXP, SEXP extraArgsSEXP, SEXP paramsSEXP, SEXP eventsSEXP, SEXP initsSEXP, SEXP setupOnlySEXP) {
Expand Down Expand Up @@ -1966,6 +1999,7 @@ static int _rxode2_RcppExport_validate(const char* sig) {
signatures.insert("void(*atolRtolFactor_)(double)");
signatures.insert("List(*rxSimThetaOmega)(const Nullable<NumericVector>&,const RObject&,const Nullable<NumericVector>&,const NumericVector&,const NumericVector&,const bool&,std::string,const int,int,const Nullable<NumericMatrix>&,const NumericVector&,const NumericVector&,const Nullable<NumericVector>&,const bool&,int,const RObject,const NumericVector&,const NumericVector&,const Nullable<NumericVector>&,const bool&,std::string,const int,int,int,double,double,bool,const LogicalVector&)");
signatures.insert("LogicalVector(*rxSolveFree)()");
signatures.insert("LogicalVector(*rxSolveSetup)()");
signatures.insert("SEXP(*rxSolve_)(const RObject&,const List&,const Nullable<CharacterVector>&,const Nullable<List>&,const RObject&,const RObject&,const RObject&,const int)");
signatures.insert("CharacterVector(*rxSolveDollarNames)(RObject)");
signatures.insert("RObject(*rxSolveGet)(RObject,RObject,LogicalVector)");
Expand Down Expand Up @@ -2025,6 +2059,7 @@ RcppExport SEXP _rxode2_RcppExport_registerCCallable() {
R_RegisterCCallable("rxode2", "_rxode2_atolRtolFactor_", (DL_FUNC)_rxode2_atolRtolFactor__try);
R_RegisterCCallable("rxode2", "_rxode2_rxSimThetaOmega", (DL_FUNC)_rxode2_rxSimThetaOmega_try);
R_RegisterCCallable("rxode2", "_rxode2_rxSolveFree", (DL_FUNC)_rxode2_rxSolveFree_try);
R_RegisterCCallable("rxode2", "_rxode2_rxSolveSetup", (DL_FUNC)_rxode2_rxSolveSetup_try);
R_RegisterCCallable("rxode2", "_rxode2_rxSolve_", (DL_FUNC)_rxode2_rxSolve__try);
R_RegisterCCallable("rxode2", "_rxode2_rxSolveDollarNames", (DL_FUNC)_rxode2_rxSolveDollarNames_try);
R_RegisterCCallable("rxode2", "_rxode2_rxSolveGet", (DL_FUNC)_rxode2_rxSolveGet_try);
Expand Down
15 changes: 15 additions & 0 deletions src/rxData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,8 @@ struct rx_globals {

// time per thread
double *timeThread = NULL;

bool alloc=false;
};


Expand Down Expand Up @@ -1554,6 +1556,7 @@ extern "C" void gFree(){
_globals.gcov=NULL;
if (_rxGetErrs != NULL) free(_rxGetErrs);
_rxGetErrs=NULL;
_globals.alloc = false;
}

extern "C" double *rxGetErrs(){
Expand Down Expand Up @@ -4049,13 +4052,25 @@ static inline void rxSolve_normalizeParms(const RObject &obj, const List &rxCont
}
}
}
_globals.alloc = true;
break;
default:
rxSolveFree();
stop(_("Something is wrong"));
}
}

//' See if the memory is installed for a solve
//'
//' @return boolean saying if the memnory is currently free for rxode2
//' @keywords internal
//' @export
//' @author Matthew L. Fidler
//[[Rcpp::export]]
LogicalVector rxSolveSetup() {
return _globals.alloc;
}

// This creates the final dataset from the currently solved object.
// Most of this is a direct C call, but some items are done in C++
List rxSolve_df(const RObject &obj,
Expand Down

0 comments on commit 0beb789

Please sign in to comment.