Construct DoubleVisitor
object from Basic
or VecBasic
and use it to numerically evaluate symbolic expressions.
DoubleVisitor(
exprs,
args,
perform_cse = TRUE,
llvm_opt_level = if (symengine_have_component("llvm")) 3L else -1L
)
visitor_call(visitor, input, do_transpose = FALSE)
A Basic object or a VecBasic object to be evaluated.
A VecBasic object indicating order of input arguments. Can be missing.
Boolean.
Integer. If negative, it will return a LambdaDoubleVisitor
,
otherwise it will return a LLVMDoubleVisitor
with the specified optimization level.
A DoubleVisitor object.
A numeric matrix. Each row is input value for one argument.
Boolean. Matters when exprs
is a VecBasic.
If true, output will have each column for one symbolic expression, otherwise
each row for one symbolic expression.
DoubleVisitor
returns a callable LambdaDoubleVisitor
or
LLVMDoubleVisitor
. visitor_call
returns a numeric vector or matrix.
DoubleVisitor
constructs the visitor and visitor itself is callable.
visitor_call
is the low level function to call the visitor with input.
a <- S("a")
b <- S("b")
c <- S("c")
vec <- c(log(a), log(a)/log(b) + c)
func <- DoubleVisitor(vec, args = c(a, b, c))
args(func)
#> function (a, b, c)
#> NULL
## Use closure
func(a = 1:10, b = 10:1, c = 1.43)
#> [,1] [,2]
#> [1,] 0.0000000 1.430000
#> [2,] 0.6931472 1.745465
#> [3,] 1.0986123 1.958321
#> [4,] 1.3862944 2.142414
#> [5,] 1.6094379 2.328244
#> [6,] 1.7917595 2.543283
#> [7,] 1.9459101 2.833677
#> [8,] 2.0794415 3.322789
#> [9,] 2.1972246 4.599925
#> [10,] 2.3025851 Inf
## Use visitor_call
input <- rbind(a = 1:10, b = 10:1, c = 1.43)
visitor_call(func, input, do_transpose = TRUE)
#> [,1] [,2]
#> [1,] 0.0000000 1.430000
#> [2,] 0.6931472 1.745465
#> [3,] 1.0986123 1.958321
#> [4,] 1.3862944 2.142414
#> [5,] 1.6094379 2.328244
#> [6,] 1.7917595 2.543283
#> [7,] 1.9459101 2.833677
#> [8,] 2.0794415 3.322789
#> [9,] 2.1972246 4.599925
#> [10,] 2.3025851 Inf