aboutsummaryrefslogtreecommitdiff
path: root/R/nlme.mmkin.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-11-16 09:15:36 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2022-11-16 09:15:36 +0100
commit51d63256a7b3020ee11931d61b4db97b9ded02c0 (patch)
treecb6d628211c99cb6dd1938428a18ef4dd5a997dc /R/nlme.mmkin.R
parent679cf716192cdfd91dfd232578cbd4e30d7eac12 (diff)
We get about 25% performance gain
with the custom lsoda call, avoiding repeated getNativeSymbolInfo calls. It's just that we should not be calling foreign functions from different packages, because the may change without notice. Using getNativeSymbolInfo for "call_lsoda" avoids the CRAN note, and a similar call could probably be used for "unlock_solver", avoiding the NOTE in checks for cran, but we should not do this in a CRAN package.
Diffstat (limited to 'R/nlme.mmkin.R')
-rw-r--r--R/nlme.mmkin.R14
1 files changed, 14 insertions, 0 deletions
diff --git a/R/nlme.mmkin.R b/R/nlme.mmkin.R
index 09cb84b8..e193e5e3 100644
--- a/R/nlme.mmkin.R
+++ b/R/nlme.mmkin.R
@@ -186,10 +186,24 @@ nlme.mmkin <- function(model, data = "auto",
thisCall[["control"]] <- control
}
+ # Provide the address of call_lsoda to the fitting function
+ call_lsoda <- getNativeSymbolInfo("call_lsoda", PACKAGE = "deSolve")
+ if (model[[1]]$solution_type == "deSolve" & !is.null(model[[1]]$mkinmod$cf)) {
+ # The mkinmod stored in the first fit will be used by nlme
+ model[[1]]$mkinmod$diffs_address <- getNativeSymbolInfo("diffs",
+ PACKAGE = model[[1]]$mkinmod$dll_info[["name"]])$address
+ model[[1]]$mkinmod$initpar_address <- getNativeSymbolInfo("initpar",
+ PACKAGE = model[[1]]$mkinmod$dll_info[["name"]])$address
+ }
+
fit_time <- system.time(val <- do.call("nlme.formula", thisCall))
val$time <- fit_time
val$mkinmod <- model[[1]]$mkinmod
+ # Don't return addresses that will become invalid
+ val$mkinmod$diffs_address <- NULL
+ val$mkinmod$initpar_address <- NULL
+
val$data <- thisCall[["data"]]
val$mmkin <- model
if (is.list(start)) val$mean_dp_start <- start$fixed

Contact - Imprint