diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2020-11-20 19:43:46 +0100 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2020-11-24 01:46:57 +0100 |
commit | 503441b0a958c1df50df0ee7cfc3bde4ea1b1865 (patch) | |
tree | 39908b25499ff38696daa364869e5394ccfce225 /R/mkinpredict.R | |
parent | 3ded5c1c45d9dbd64d3d40835e68e8cf47932346 (diff) |
Support storing mkinmod compiled code as CFunc objects
With automatic reloading in mkinfit and mkinpredict in case the
DLL is not loaded and the original DLL path has been cleaned up.
Depends on jranke/inline@974bdea04fcedfafaab231e6f359c88270b56cb9
See inline#13
Diffstat (limited to 'R/mkinpredict.R')
-rw-r--r-- | R/mkinpredict.R | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/R/mkinpredict.R b/R/mkinpredict.R index 7222e247..a294a114 100644 --- a/R/mkinpredict.R +++ b/R/mkinpredict.R @@ -38,7 +38,6 @@ #' @param \dots Further arguments passed to the ode solver in case such a #' solver is used. #' @import deSolve -#' @importFrom inline getDynLib #' @return A matrix with the numeric solution in wide format #' @author Johannes Ranke #' @examples @@ -117,7 +116,7 @@ mkinpredict.mkinmod <- function(x, solution_type = "deSolve", use_compiled = "auto", method.ode = "lsoda", atol = 1e-8, rtol = 1e-10, - map_output = TRUE, + map_output = TRUE, na_stop = TRUE, ...) { @@ -170,12 +169,18 @@ mkinpredict.mkinmod <- function(x, if (solution_type == "deSolve") { if (!is.null(x$cf) & use_compiled[1] != FALSE) { - out <- ode( + DLL <- try(inline::getDynLib(x$cf)) + if (inherits(DLL, "try-error")) { + x$cf <- inline::readDynLib(x$cf_name, x$cf_dir) + } + cf_env <- environment(x$cf) + + out <- deSolve::ode( y = odeini, times = outtimes, - func = "func", + func = cf_env$name, initfunc = "initpar", - dllname = getDynLib(x$cf)[["name"]], + dllname = cf_env$f, parms = odeparms[x$parms], # Order matters when using compiled models method = method.ode, atol = atol, @@ -195,7 +200,7 @@ mkinpredict.mkinmod <- function(x, } return(list(c(diffs))) } - out <- ode( + out <- deSolve::ode( y = odeini, times = outtimes, func = mkindiff, |