|
| 1 | + |
| 2 | +function symbolify(e::Expr) |
| 3 | + if !(e.args[1] isa Symbol) |
| 4 | + e.args[1] = Symbol(e.args[1]) |
| 5 | + end |
| 6 | + symbolify.(e.args) |
| 7 | + return e |
| 8 | +end |
| 9 | + |
| 10 | +function symbolify(e) |
| 11 | + return e |
| 12 | +end |
| 13 | + |
| 14 | +function rep_pars_vals!(e::Expr, p) |
| 15 | + rep_pars_vals!.(e.args, Ref(p)) |
| 16 | + replace!(e.args, p...) |
| 17 | +end |
| 18 | + |
| 19 | +function rep_pars_vals!(e, p) end |
| 20 | + |
1 | 21 | """
|
2 | 22 | instantiate_function(f, x, ::AbstractADType, p, num_cons = 0)::OptimizationFunction
|
3 | 23 |
|
@@ -30,8 +50,14 @@ function instantiate_function(f, x, ::AbstractADType, p, num_cons = 0)
|
30 | 50 | cons = f.cons === nothing ? nothing : (x)->f.cons(x,p)
|
31 | 51 | cons_j = f.cons_j === nothing ? nothing : (res,x)->f.cons_j(res,x,p)
|
32 | 52 | cons_h = f.cons_h === nothing ? nothing : (res,x)->f.cons_h(res,x,p)
|
| 53 | + hess_prototype = f.hess_prototype === nothing ? nothing : (!(eltype(f.hess_prototype) == eltype(x)) ? convert.(eltype(x), f.hess_prototype) : f.hess_prototype) |
| 54 | + cons_jac_prototype = f.cons_jac_prototype === nothing ? nothing : (!(eltype(f.cons_jac_prototype) == eltype(x)) ? convert.(eltype(x), f.cons_jac_prototype) : f.cons_jac_prototype) |
| 55 | + cons_hess_prototype = f.cons_hess_prototype === nothing ? nothing : (!(eltype(f.cons_hess_prototype) == eltype(x)) ? convert.(eltype(x), f.cons_hess_prototype) : f.cons_hess_prototype) |
| 56 | + expr = symbolify(f.expr) |
| 57 | + cons_expr = symbolify.(f.cons_expr) |
33 | 58 |
|
34 | 59 | return OptimizationFunction{true}(f.f, SciMLBase.NoAD(); grad=grad, hess=hess, hv=hv,
|
35 | 60 | cons=cons, cons_j=cons_j, cons_h=cons_h,
|
36 |
| - hess_prototype=f.hess_prototype, cons_jac_prototype=f.cons_jac_prototype, cons_hess_prototype=f.cons_hess_prototype) |
| 61 | + hess_prototype=hess_prototype, cons_jac_prototype=cons_jac_prototype, |
| 62 | + cons_hess_prototype=cons_hess_prototype, expr=expr, cons_expr=cons_expr) |
37 | 63 | end
|
0 commit comments