diff --git a/R/symengine.R b/R/symengine.R index 42347a807..b2a56f15c 100644 --- a/R/symengine.R +++ b/R/symengine.R @@ -264,7 +264,10 @@ regIfOrElse <- rex::rex(or(regIf, regElse)) "rt" = 1 ) -#' @inherit rxode2parse::rxFunParse +#' Add/Create C functions for use in rxode2 +#' +#' @inheritParams rxode2parse::rxFunParse +#' #' @param name This can either give the name of the user function or #' be a simple R function that you wish to convert to C. If you #' have rxode2 convert the R function to C, the name of the function @@ -272,6 +275,7 @@ regIfOrElse <- rex::rex(or(regIf, regElse)) #' will match the R function provided. Hence, if you are providing #' an R function for conversion to C, the rest of the arguments are #' implied. +#' @export #' @examples #' \donttest{ #' ## Right now rxode2 is not aware of the function fun @@ -361,7 +365,6 @@ regIfOrElse <- rex::rex(or(regIf, regElse)) #' rm(gg) #' rm(f) #' } -#' @export rxFun <- function(name, args, cCode) { if (missing(args) && missing(cCode)) { .funName <- as.character(substitute(name)) @@ -3489,6 +3492,19 @@ rxSupportedFuns <- function() { } } +#' Calculate derivatives/C code from a R function +#' +#' @param fun Function to convert to C +#' +#' @param name function name to convert to C, implied if needed +#' +#' @param onlyF Only calculate the C for the function, don't calculate the derivatives +#' +#' @return A list with C code and derivative information +#' +#' @keywords internal +#' +#' @noRd rxFun2c <- function(fun, name, onlyF=FALSE) { .env <- new.env(parent=emptyenv()) .env$vars <- character(0) @@ -3577,10 +3593,6 @@ rxFun2c <- function(fun, name, onlyF=FALSE) { .v <- eval(str2lang(.v)) .dName <- paste0("rx_", .funName, "_d_", v) .v <- rxFun2c(.v, .dName, onlyF=TRUE) - #' function(a, b, c) { - #' paste0("2*", a, "+", b) - #' }, - #' .v2 <- paste0("function(", paste(.env$args, collapse=", "), "){\n", "paste0(\"", .dName, "(\", ", paste(.env$args, collapse=", \", \", "), ", \")\")", diff --git a/inst/include/rxode2_control.h b/inst/include/rxode2_control.h index fec561cf8..e54cb3dc8 100644 --- a/inst/include/rxode2_control.h +++ b/inst/include/rxode2_control.h @@ -2,5 +2,100 @@ #ifndef __rxode2_control_H__ #define __rxode2_control_H__ #include - +#define Rxc_scale 0 +#define Rxc_method 1 +#define Rxc_atol 2 +#define Rxc_rtol 3 +#define Rxc_maxsteps 4 +#define Rxc_hmin 5 +#define Rxc_hmax 6 +#define Rxc_hini 7 +#define Rxc_maxordn 8 +#define Rxc_maxords 9 +#define Rxc_covsInterpolation 10 +#define Rxc_addCov 11 +#define Rxc_returnType 12 +#define Rxc_sigma 13 +#define Rxc_sigmaDf 14 +#define Rxc_nCoresRV 15 +#define Rxc_sigmaIsChol 16 +#define Rxc_sigmaSeparation 17 +#define Rxc_sigmaXform 18 +#define Rxc_nDisplayProgress 19 +#define Rxc_amountUnits 20 +#define Rxc_timeUnits 21 +#define Rxc_addDosing 22 +#define Rxc_stateTrim 23 +#define Rxc_updateObject 24 +#define Rxc_omega 25 +#define Rxc_omegaDf 26 +#define Rxc_omegaIsChol 27 +#define Rxc_omegaSeparation 28 +#define Rxc_omegaXform 29 +#define Rxc_nSub 30 +#define Rxc_thetaMat 31 +#define Rxc_thetaDf 32 +#define Rxc_thetaIsChol 33 +#define Rxc_nStud 34 +#define Rxc_dfSub 35 +#define Rxc_dfObs 36 +#define Rxc_seed 37 +#define Rxc_nsim 38 +#define Rxc_minSS 39 +#define Rxc_maxSS 40 +#define Rxc_strictSS 41 +#define Rxc_infSSstep 42 +#define Rxc_istateReset 43 +#define Rxc_subsetNonmem 44 +#define Rxc_hmaxSd 45 +#define Rxc_maxAtolRtolFactor 46 +#define Rxc_from 47 +#define Rxc_to 48 +#define Rxc_by 49 +#define Rxc_length_out 50 +#define Rxc_iCov 51 +#define Rxc_keep 52 +#define Rxc_keepF 53 +#define Rxc_drop 54 +#define Rxc_warnDrop 55 +#define Rxc_omegaLower 56 +#define Rxc_omegaUpper 57 +#define Rxc_sigmaLower 58 +#define Rxc_sigmaUpper 59 +#define Rxc_thetaLower 60 +#define Rxc_thetaUpper 61 +#define Rxc_indLinPhiM 62 +#define Rxc_indLinPhiTol 63 +#define Rxc_indLinMatExpType 64 +#define Rxc_indLinMatExpOrder 65 +#define Rxc_idFactor 66 +#define Rxc_mxhnil 67 +#define Rxc_hmxi 68 +#define Rxc_warnIdSort 69 +#define Rxc_ssAtol 70 +#define Rxc_ssRtol 71 +#define Rxc_safeZero 72 +#define Rxc_sumType 73 +#define Rxc_prodType 74 +#define Rxc_sensType 75 +#define Rxc_linDiff 76 +#define Rxc_linDiffCentral 77 +#define Rxc_resample 78 +#define Rxc_resampleID 79 +#define Rxc_maxwhile 80 +#define Rxc_cores 81 +#define Rxc_atolSens 82 +#define Rxc_rtolSens 83 +#define Rxc_ssAtolSens 84 +#define Rxc_ssRtolSens 85 +#define Rxc_simVariability 86 +#define Rxc_nLlikAlloc 87 +#define Rxc_useStdPow 88 +#define Rxc_naTimeHandle 89 +#define Rxc_addlKeepsCov 90 +#define Rxc_addlDropSs 91 +#define Rxc_ssAtDoseTime 92 +#define Rxc_ss2cancelAllPending 93 +#define Rxc_envir 94 +#define Rxc__zeros 95 #endif // __rxode2_control_H__ diff --git a/man/as.rxUi.Rd b/man/as.rxUi.Rd index f54aeb03f..3256eec73 100644 --- a/man/as.rxUi.Rd +++ b/man/as.rxUi.Rd @@ -10,25 +10,22 @@ \alias{as.rxUi.default} \title{As rxode2 ui} \usage{ -as.rxUi(x, envir = parent.frame()) +as.rxUi(x) -\method{as.rxUi}{rxode2}(x, envir = parent.frame()) +\method{as.rxUi}{rxode2}(x) -\method{as.rxUi}{rxode2tos}(x, envir = parent.frame()) +\method{as.rxUi}{rxode2tos}(x) -\method{as.rxUi}{rxModelVars}(x, envir = parent.frame()) +\method{as.rxUi}{rxModelVars}(x) -\method{as.rxUi}{`function`}(x, envir = parent.frame()) +\method{as.rxUi}{`function`}(x) -\method{as.rxUi}{rxUi}(x, envir = parent.frame()) +\method{as.rxUi}{rxUi}(x) -\method{as.rxUi}{default}(x, envir = parent.frame()) +\method{as.rxUi}{default}(x) } \arguments{ \item{x}{Object to convert to \code{rxUi} object} - -\item{envir}{is the environment to look for R user functions -(defaults to parent environment)} } \value{ rxUi object (or error if it cannot be converted) @@ -40,7 +37,7 @@ As rxode2 ui mod1 <- function() { ini({ - # central + # central KA=2.94E-01 CL=1.86E+01 V2=4.02E+01 @@ -50,7 +47,7 @@ mod1 <- function() { # effects Kin=1 Kout=1 - EC50=200 + EC50=200 }) model({ C2 <- centr/V2 diff --git a/man/reexports.Rd b/man/reexports.Rd index 365c14ab7..f1310e9e9 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -82,4 +82,3 @@ below to see their documentation. \item{rxode2random}{\code{\link[rxode2random:dot-cbindOme]{.cbindOme}}, \code{\link[rxode2random:dot-expandPars]{.expandPars}}, \code{\link[rxode2random:dot-vecDf]{.vecDf}}, \code{\link[rxode2random]{cvPost}}, \code{\link[rxode2random]{invWR1d}}, \code{\link[rxode2random]{phi}}, \code{\link[rxode2random]{rinvchisq}}, \code{\link[rxode2random]{rLKJ1}}, \code{\link[rxode2random]{rxGetSeed}}, \code{\link[rxode2random]{rxGetSeed}}, \code{\link[rxode2random]{rxRmvn}}, \code{\link[rxode2random]{rxSeedEng}}, \code{\link[rxode2random]{rxSetSeed}}, \code{\link[rxode2random]{rxSetSeed}}, \code{\link[rxode2random]{rxSetSeed}}, \code{\link[rxode2random:rxWithSeed]{rxWithPreserveSeed}}, \code{\link[rxode2random]{rxWithSeed}}, \code{\link[rxode2random]{rxWithSeed}}} }} -\value{ Inherited from parent routine } diff --git a/man/rxFun.Rd b/man/rxFun.Rd index 836a7fc2a..77c8e3c6f 100644 --- a/man/rxFun.Rd +++ b/man/rxFun.Rd @@ -3,7 +3,7 @@ \name{rxFun} \alias{rxFun} \alias{rxRmFun} -\title{Add user function to rxode2} +\title{Add/Create C functions for use in rxode2} \usage{ rxFun(name, args, cCode) @@ -22,14 +22,8 @@ implied.} \item{cCode}{This is the C-code for the new function} } -\value{ -nothing -} \description{ -This adds a user function to rxode2 that can be called. If needed, -these functions can be differentiated by numerical differences or -by adding the derivatives to rxode2's internal derivative table -with rxode2's \code{rxD} function +Add/Create C functions for use in rxode2 } \examples{ \donttest{ @@ -121,6 +115,3 @@ rm(gg) rm(f) } } -\author{ -Matthew L. Fidler -} diff --git a/man/rxS.Rd b/man/rxS.Rd index 898eca1ff..b55404472 100644 --- a/man/rxS.Rd +++ b/man/rxS.Rd @@ -4,7 +4,7 @@ \alias{rxS} \title{Load a model into a symengine environment} \usage{ -rxS(x, doConst = TRUE, promoteLinSens = FALSE) +rxS(x, doConst = TRUE, promoteLinSens = FALSE, envir = parent.frame()) } \arguments{ \item{x}{rxode2 object} @@ -13,6 +13,9 @@ rxS(x, doConst = TRUE, promoteLinSens = FALSE) \item{promoteLinSens}{Promote solved linear compartment systems to sensitivity-based solutions.} + +\item{envir}{default is \code{NULL}; Environment to put symengine +variables in.} } \value{ rxode2/symengine environment diff --git a/man/rxSolve.Rd b/man/rxSolve.Rd index 54f0a6d80..f90f627a3 100644 --- a/man/rxSolve.Rd +++ b/man/rxSolve.Rd @@ -144,7 +144,8 @@ rxSolve( inits = NULL, ..., theta = NULL, - eta = NULL + eta = NULL, + envir = parent.frame() ) \method{rxSolve}{rxUi}( @@ -194,7 +195,8 @@ rxSolve( inits = NULL, ..., theta = NULL, - eta = NULL + eta = NULL, + envir = parent.frame() ) \method{update}{rxSolve}(object, ...) diff --git a/man/rxode2.Rd b/man/rxode2.Rd index 0fa54404b..1a7a3c176 100644 --- a/man/rxode2.Rd +++ b/man/rxode2.Rd @@ -180,7 +180,7 @@ consisting of the following list of strings and functions: `atol`: a numeric absolute tolerance (1e-08 by default); - `rtol`: a numeric relative tolerance (1e-06 by default).e + `rtol`: a numeric relative tolerance (1e-06 by default). The output of \\dQuote\{solve\} is a matrix with as many rows as there are sampled time points and as many columns as system variables @@ -232,9 +232,6 @@ mod <- rxode2(\{ d/dt(centr) <- F*KA*depot - CL*C2 - Q*C2 + Q*C3; \}) }\if{html}{\out{}} - -\if{html}{\out{
}}\preformatted{## using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’ -}\if{html}{\out{
}} \itemize{ \item Inside a \code{rxode2("")} string statement: }\if{html}{\out{ @@ -250,9 +247,6 @@ mod <- rxode2(\{ d/dt(centr) <- F*KA*depot - CL*C2 - Q*C2 + Q*C3; ") }\if{html}{\out{}} - -\if{html}{\out{
}}\preformatted{## using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’ -}\if{html}{\out{
}} \itemize{ \item In a file name to be loaded by rxode2: }\if{html}{\out{ @@ -331,9 +325,7 @@ compilation model. \if{html}{\out{
}}\preformatted{mod$simulationModel }\if{html}{\out{
}} -\if{html}{\out{
}}\preformatted{## using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’ - -## rxode2 2.0.14.9000 model named rx_78dcb8ef8275ff5e33a47163f4239e19 model (ready). +\if{html}{\out{
}}\preformatted{## rxode2 2.0.14.9000 model named rx_8223e497c83db9e334c52254bd575c98 model (ready). ## x$state: depot, center ## x$stateExtra: cp ## x$params: tka, tcl, tv, add.sd, eta.ka, eta.cl, eta.v, rxerr.cp @@ -344,9 +336,7 @@ compilation model. mod$simulationIniModel }\if{html}{\out{
}} -\if{html}{\out{
}}\preformatted{## using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’ - -## rxode2 2.0.14.9000 model named rx_baef7cfc602529d2843782858fc2f522 model (ready). +\if{html}{\out{
}}\preformatted{## rxode2 2.0.14.9000 model named rx_182c47efea379394bbab84d957305170 model (ready). ## x$state: depot, center ## x$stateExtra: cp ## x$params: tka, tcl, tv, add.sd, eta.ka, eta.cl, eta.v, rxerr.cp