From 503441b0a958c1df50df0ee7cfc3bde4ea1b1865 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 20 Nov 2020 19:43:46 +0100 Subject: 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 --- R/mkinpredict.R | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'R/mkinpredict.R') 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, -- cgit v1.2.1 From 1e3fd1bef2a0ec1c8b73fcfefdd62fd3463bc87c Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 27 Nov 2020 18:35:56 +0100 Subject: Improved way to have persistent DLLs for mkinmod Depends on inline >= 0.16.2 (including the bug fixes from eddelbuettel/inline#18), which provides 'moveDLL' to store the DLL for a compiled function in a safe place in case the argument 'dll_dir' is specified in the call to 'mkinmod'. Huge thanks to Dirk @eddelbuettel for his review and support for the work on the inline package. --- R/mkinpredict.R | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'R/mkinpredict.R') diff --git a/R/mkinpredict.R b/R/mkinpredict.R index a294a114..277c3604 100644 --- a/R/mkinpredict.R +++ b/R/mkinpredict.R @@ -169,18 +169,13 @@ mkinpredict.mkinmod <- function(x, if (solution_type == "deSolve") { if (!is.null(x$cf) & use_compiled[1] != FALSE) { - 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 = cf_env$name, + func = "diffs", initfunc = "initpar", - dllname = cf_env$f, + dllname = inline::getDynLib(x$cf)[["name"]], parms = odeparms[x$parms], # Order matters when using compiled models method = method.ode, atol = atol, -- cgit v1.2.1