Thank you for your answer. I have read those files before. My question is mostly how can I get the generatedruntimefunction that comes out of build_function working in another file.
For instance if I do this in first script:
using Symbolics
# Import JuliaTarget from Symbolics
import Symbolics: JuliaTarget, build_function
# Define symbolic variables and expression
@variables x y
f = x^2 + 2x*y + y^2
t = x + y
println("Expression: ", f)
# Generate a Julia function
generated_code = build_function([f,t], [x, y]; target=JuliaTarget(), expression=Val{true})[2]
println("Generated code: ", generated_code)
write("generated_function.jl", string(generated_code))
and If I use it in the second script as follows
# Include the generated function
using Symbolics
using NaNMath
# Include the generated function
f = include("generated_function.jl")
# Define input and output arrays
out = [0.0, 0.0]
f(out, [1.0, 2.0])
println(out[1])
println(out[2])
I can easily get the output I want, but I read on some other documents that runtimegeneratedfunction is faster. Therefore, I made the expression=val{false}, so that I can get the function in this runtimegeneratedfunction format:
RuntimeGeneratedFunction{(:ˍ₋out, :ˍ₋arg1), Symbolics.var"#_RGF_ModTag", Symbolics.var"#_RGF_ModTag", (0x2e47bddd, 0xf8cec6ab, 0x587ece1d, 0x1361e09f, 0x8e477015), Expr}(:(#= C:\Users\milad\.julia\packages\Symbolics\PxO3a\src\build_function.jl:342 =# @inbounds begin
#= C:\Users\milad\.julia\packages\Symbolics\PxO3a\src\build_function.jl:342 =#
begin
#= C:\Users\milad\.julia\packages\SymbolicUtils\99RP6\src\code.jl:388 =#
#= C:\Users\milad\.julia\packages\SymbolicUtils\99RP6\src\code.jl:389 =#
#= C:\Users\milad\.julia\packages\SymbolicUtils\99RP6\src\code.jl:390 =#
begin
begin
#= C:\Users\milad\.julia\packages\Symbolics\PxO3a\src\build_function.jl:558 =#
#= C:\Users\milad\.julia\packages\SymbolicUtils\99RP6\src\code.jl:437 =# @inbounds begin
#= C:\Users\milad\.julia\packages\SymbolicUtils\99RP6\src\code.jl:433 =#
ˍ₋out[1] = (+)((+)((NaNMath.pow)(ˍ₋arg1[1], 2), (*)((*)(2, ˍ₋arg1[1]), ˍ₋arg1[2])), (NaNMath.pow)(ˍ₋arg1[2], 2))
ˍ₋out[2] = (+)(ˍ₋arg1[1], ˍ₋arg1[2])
#= C:\Users\milad\.julia\packages\SymbolicUtils\99RP6\src\code.jl:435 =#
nothing
end
end
end
end
end))
But I don’t know how can I include it in the second script and execute it.