From 5a986f2064cf0b2fbd94e636cc4fa56d9939ca42 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 3 Nov 2020 05:08:25 +0100 Subject: C implementation of the SFO function Only pays off for large time series with length >> 100 --- NAMESPACE | 1 + R/parent_solutions.R | 6 ++---- build.log | 25 +++++++++++++++++++++---- src/mkin.so | Bin 0 -> 20920 bytes src/parent_solutions.c | 25 +++++++++++++++++++++++++ src/parent_solutions.o | Bin 0 -> 10176 bytes 6 files changed, 49 insertions(+), 8 deletions(-) create mode 100755 src/mkin.so create mode 100644 src/parent_solutions.c create mode 100644 src/parent_solutions.o diff --git a/NAMESPACE b/NAMESPACE index 9554a0d6..ca5fa4b1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -123,3 +123,4 @@ importFrom(stats,update) importFrom(stats,var) importFrom(utils,getFromNamespace) importFrom(utils,write.table) +useDynLib(mkin,SFO_solution) diff --git a/R/parent_solutions.R b/R/parent_solutions.R index 04226b73..bbdffc21 100644 --- a/R/parent_solutions.R +++ b/R/parent_solutions.R @@ -22,11 +22,9 @@ #' #' \dontrun{plot(function(x) SFO.solution(x, 100, 3), 0, 2)} #' +#' @useDynLib mkin SFO_solution #' @export -SFO.solution <- function(t, parent_0, k) -{ - parent = parent_0 * exp(-k * t) -} +SFO.solution <- function(t, parent_0, k) .Call(SFO_solution, as.double(t), as.double(parent_0), as.double(k)) #' First-Order Multi-Compartment kinetics #' diff --git a/build.log b/build.log index d101d06b..f82ccec6 100644 --- a/build.log +++ b/build.log @@ -1,9 +1,26 @@ * checking for file ‘./DESCRIPTION’ ... OK * preparing ‘mkin’: * checking DESCRIPTION meta-information ... OK +* cleaning src * installing the package to build vignettes -* creating vignettes ... OK -* checking for LF line-endings in source and make files and shell scripts -* checking for empty or unneeded directories -* building ‘mkin_0.9.50.4.tar.gz’ +* creating vignettes ... ERROR +--- re-building ‘FOCUS_D.rmd’ using rmarkdown +Quitting from lines 49-50 (FOCUS_D.rmd) +Error: processing vignette 'FOCUS_D.rmd' failed with diagnostics: +replacement has 21 rows, data has 38 +--- failed re-building ‘FOCUS_D.rmd’ +--- re-building ‘FOCUS_L.rmd’ using rmarkdown +--- finished re-building ‘FOCUS_L.rmd’ + +--- re-building ‘mkin.rmd’ using rmarkdown +--- finished re-building ‘mkin.rmd’ + +--- re-building ‘twa.rmd’ using rmarkdown +--- finished re-building ‘twa.rmd’ + +SUMMARY: processing the following file failed: + ‘FOCUS_D.rmd’ + +Error: Vignette re-building failed. +Execution halted diff --git a/src/mkin.so b/src/mkin.so new file mode 100755 index 00000000..3d515096 Binary files /dev/null and b/src/mkin.so differ diff --git a/src/parent_solutions.c b/src/parent_solutions.c new file mode 100644 index 00000000..4881d708 --- /dev/null +++ b/src/parent_solutions.c @@ -0,0 +1,25 @@ +#include +#include + +SEXP SFO_solution(SEXP t, SEXP parent_0_, SEXP k_) { + + int n = length(t); + + double parent_0 = asReal(parent_0_); + double k = asReal(k_); + + double *pt, *pout; + + SEXP out = PROTECT(allocVector(REALSXP, n)); + + pt = REAL(t); + pout = REAL(out); + + for (int i = 0; i < n; i++) { + pout[i] = parent_0 * exp(- k * pt[i]); + } + + UNPROTECT(1); + + return out; +} diff --git a/src/parent_solutions.o b/src/parent_solutions.o new file mode 100644 index 00000000..9ca88e7d Binary files /dev/null and b/src/parent_solutions.o differ -- cgit v1.2.1