Hi, so I’d like to to create a function that allows me to automate the creation of generated functions.
Here is an example of the type of generated function I’d like to create:
using Reduce
expr = :(x^2)
@generated function fun(x,::Val{p}) where p
:(@fastmath $(horner(df(expr,:x,p))))
end
However, I’d like to create a function that creates this function for me, so I want to be able to do
genfun(:fun,expr)
where :fun
symbol will be the name of the generated function and expr
is substituted into it.
An approximation of what I want looks like this:
function genfun(fun::Symbol,expr)
@eval begin
@generated function $fun(x,::Val{p}) where p
:(@fastmath $(horner(df($$(QuoteNode(expr)),:x,p))))
end
end
end
However, I’m not exactly sure how to properly interpolate the expressions for the desired result.
Does anyone know how to do something like this?
NOTE this requires the master branch of Reduce
, so Pkg.checkout