11module DynamicExpressionsOptimExt
22
3- using DynamicExpressions: Node, eval_tree_array
3+ using DynamicExpressions: AbstractExpressionNode, eval_tree_array
4+ using Compat: @inline
45
5- import Compat: @inline
66import Optim: optimize
77
88""" Wrap f with insertion of values of the constant nodes."""
99function get_wrapped_f (
1010 f:: F , tree:: N , constant_nodes:: AbstractArray{N}
11- ) where {F,T,N<: Node {T} }
11+ ) where {F,T,N<: AbstractExpressionNode {T} }
1212 function wrapped_f (x)
1313 for (ci, xi) in zip (constant_nodes, x)
1414 ci. val:: T = xi:: T
2121""" Wrap g! or h! with insertion of values of the constant nodes."""
2222function get_wrapped_gh! (
2323 gh!:: GH , tree:: N , constant_nodes:: AbstractArray{N}
24- ) where {GH,T,N<: Node {T} }
24+ ) where {GH,T,N<: AbstractExpressionNode {T} }
2525 function wrapped_gh! (G, x)
2626 for (ci, xi) in zip (constant_nodes, x)
2727 ci. val:: T = xi:: T
@@ -32,9 +32,9 @@ function get_wrapped_gh!(
3232 return wrapped_gh!
3333end
3434
35- function optimize (f:: F , g!:: G , h!:: H , tree:: Node {T} , args... ; kwargs... ) where {F,G,H,T}
35+ function optimize (f:: F , g!:: G , h!:: H , tree:: AbstractExpressionNode {T} , args... ; kwargs... ) where {F,G,H,T}
3636 constant_nodes = filter (t -> t. degree == 0 && t. constant, tree)
37- x0 = [t. val:: T for t in constant_nodes]
37+ x0 = T [t. val:: T for t in constant_nodes]
3838 if g! === nothing
3939 @assert h! === nothing
4040 return optimize (get_wrapped_f (f, tree, constant_nodes), x0, args... ; kwargs... )
@@ -57,10 +57,10 @@ function optimize(f::F, g!::G, h!::H, tree::Node{T}, args...; kwargs...) where {
5757 )
5858 end
5959end
60- function optimize (f:: F , g!:: G , tree:: Node , args... ; kwargs... ) where {F,G}
60+ function optimize (f:: F , g!:: G , tree:: AbstractExpressionNode , args... ; kwargs... ) where {F,G}
6161 return optimize (f, g!, nothing , tree, args... ; kwargs... )
6262end
63- function optimize (f:: F , tree:: Node , args... ; kwargs... ) where {F}
63+ function optimize (f:: F , tree:: AbstractExpressionNode , args... ; kwargs... ) where {F}
6464 return optimize (f, nothing , tree, args... ; kwargs... )
6565end
6666
0 commit comments