Evaluates argument sets, one per cppFUN() object, all sets in
one call from R and one parallel region.
Arguments
- funs
List of the
evaluateBatchentries ofcppFUN()objects built with forward derivatives, one per set.- sets
List of argument sets, as
evaluateBatchtakes them.- cores
Number of threads over the sets. Default
1.- deriv2
Logical. Second derivatives as well. Default
FALSE.
Examples
# \donttest{
if (codegenAvailable()) {
## Two functions of one variable, compiled together and evaluated on separate
## argument sets; the parameter seeds give the derivatives in a and b.
f1 <- cppFUN(c(y = "a * x"), variables = "x", parameters = "a",
modelname = "many_a", outdir = tempdir())
f2 <- cppFUN(c(y = "exp(-b * x)"), variables = "x", parameters = "b",
modelname = "many_b", outdir = tempdir())
compile(f1, f2, output = "many_example")
x <- matrix(c(0, 1, 2), 3, 1, dimnames = list(NULL, "x"))
seed <- function(p) matrix(1, 1, 1, dimnames = list(p, p))
sets <- list(list(vars = x, params = c(a = 2), tangentP = seed("a")),
list(vars = x, params = c(b = 0.5), tangentP = seed("b")))
out <- evaluateMany(list(f1$evaluateBatch, f2$evaluateBatch), sets)
out[[2]]$y
out[[2]]$tangent[, , "b"]
}
#> using C++ compiler: g++ [-O2 -DNDEBUG -w -fPIC -fopenmp]
#> [1] 0.0000000 -0.6065307 -0.7357589
# }