@@ -22,7 +22,7 @@ function default_chunk_size(len)
22
22
end
23
23
end
24
24
25
- function instantiate_function (f, x, :: AbstractADType , p)
25
+ function instantiate_function (f, x, :: AbstractADType , p, num_cons = 0 )
26
26
grad = f. grad === nothing ? nothing : (G,x)-> f. grad (G,x,p)
27
27
hess = f. hess === nothing ? nothing : (H,x)-> f. hess (H,x,p)
28
28
hv = f. hv === nothing ? nothing : (H,x,v)-> f. hv (H,x,v,p)
@@ -34,10 +34,10 @@ function instantiate_function(f, x, ::AbstractADType, p)
34
34
typeof (hess),typeof (hv),typeof (cons),
35
35
typeof (cons_j),typeof (cons_h)}(f. f,
36
36
DiffEqBase. NoAD (),grad,hess,hv,cons,
37
- cons_j,cons_h,f . num_cons )
37
+ cons_j,cons_h)
38
38
end
39
39
40
- function instantiate_function (f, x, :: AutoForwardDiff{_chunksize} , p) where _chunksize
40
+ function instantiate_function (f, x, :: AutoForwardDiff{_chunksize} , p, num_cons = 0 ) where _chunksize
41
41
42
42
chunksize = _chunksize === nothing ? default_chunk_size (length (x)) : _chunksize
43
43
@@ -86,7 +86,7 @@ function instantiate_function(f, x, ::AutoForwardDiff{_chunksize}, p) where _chu
86
86
87
87
if cons != = nothing && f. cons_h === nothing
88
88
cons_h = function (res, θ)
89
- for i in 1 : f . num_cons
89
+ for i in 1 : num_cons
90
90
hess_config_cache = ForwardDiff. HessianConfig (x -> cons (x)[i], θ,ForwardDiff. Chunk {chunksize} ())
91
91
ForwardDiff. hessian! (res[i], (x) -> cons (x)[i], θ, hess_config_cache,Val {false} ())
92
92
end
@@ -95,11 +95,11 @@ function instantiate_function(f, x, ::AutoForwardDiff{_chunksize}, p) where _chu
95
95
cons_h = f. cons_h
96
96
end
97
97
98
- return OptimizationFunction {true,AutoForwardDiff,typeof(f.f),typeof(grad),typeof(hess),typeof(hv),typeof(cons),typeof(cons_j),typeof(cons_h)} (f. f,AutoForwardDiff (),grad,hess,hv,cons,cons_j,cons_h,f . num_cons )
98
+ return OptimizationFunction {true,AutoForwardDiff,typeof(f.f),typeof(grad),typeof(hess),typeof(hv),typeof(cons),typeof(cons_j),typeof(cons_h)} (f. f,AutoForwardDiff (),grad,hess,hv,cons,cons_j,cons_h)
99
99
end
100
100
101
- function instantiate_function (f, x, :: AutoZygote , p)
102
- f . num_cons != 0 && error (" AutoZygote does not currently support constraints" )
101
+ function instantiate_function (f, x, :: AutoZygote , p, num_cons = 0 )
102
+ num_cons != 0 && error (" AutoZygote does not currently support constraints" )
103
103
104
104
_f = θ -> f (θ,p)[1 ]
105
105
if f. grad === nothing
@@ -135,11 +135,11 @@ function instantiate_function(f, x, ::AutoZygote, p)
135
135
hv = f. hv
136
136
end
137
137
138
- return OptimizationFunction {false,AutoZygote,typeof(f),typeof(grad),typeof(hess),typeof(hv),Nothing,Nothing,Nothing} (f,AutoZygote (),grad,hess,hv,nothing ,nothing ,nothing , 0 )
138
+ return OptimizationFunction {false,AutoZygote,typeof(f),typeof(grad),typeof(hess),typeof(hv),Nothing,Nothing,Nothing} (f,AutoZygote (),grad,hess,hv,nothing ,nothing ,nothing )
139
139
end
140
140
141
- function instantiate_function (f, x, :: AutoReverseDiff , p= DiffEqBase. NullParameters ())
142
- f . num_cons != 0 && error (" AutoReverseDiff does not currently support constraints" )
141
+ function instantiate_function (f, x, :: AutoReverseDiff , p= DiffEqBase. NullParameters (), num_cons = 0 )
142
+ num_cons != 0 && error (" AutoReverseDiff does not currently support constraints" )
143
143
144
144
_f = θ -> f. f (θ,p)[1 ]
145
145
@@ -177,12 +177,12 @@ function instantiate_function(f, x, ::AutoReverseDiff, p=DiffEqBase.NullParamete
177
177
hv = f. hv
178
178
end
179
179
180
- return OptimizationFunction {false,AutoReverseDiff,typeof(f),typeof(grad),typeof(hess),typeof(hv),Nothing,Nothing,Nothing} (f,AutoReverseDiff (),grad,hess,hv,nothing ,nothing ,nothing , 0 )
180
+ return OptimizationFunction {false,AutoReverseDiff,typeof(f),typeof(grad),typeof(hess),typeof(hv),Nothing,Nothing,Nothing} (f,AutoReverseDiff (),grad,hess,hv,nothing ,nothing ,nothing )
181
181
end
182
182
183
183
184
- function instantiate_function (f, x, :: AutoTracker , p)
185
- f . num_cons != 0 && error (" AutoTracker does not currently support constraints" )
184
+ function instantiate_function (f, x, :: AutoTracker , p, num_cons = 0 )
185
+ num_cons != 0 && error (" AutoTracker does not currently support constraints" )
186
186
_f = θ -> f. f (θ,p)[1 ]
187
187
188
188
if f. grad === nothing
@@ -204,12 +204,11 @@ function instantiate_function(f, x, ::AutoTracker, p)
204
204
end
205
205
206
206
207
- return OptimizationFunction {false,AutoTracker,typeof(f),typeof(grad),typeof(hess),typeof(hv),Nothing,Nothing,Nothing} (f,AutoTracker (),grad,hess,hv,nothing ,nothing ,nothing , 0 )
207
+ return OptimizationFunction {false,AutoTracker,typeof(f),typeof(grad),typeof(hess),typeof(hv),Nothing,Nothing,Nothing} (f,AutoTracker (),grad,hess,hv,nothing ,nothing ,nothing )
208
208
end
209
209
210
- function instantiate_function (f, x, adtype:: AutoFiniteDiff , p)
211
-
212
- f. num_cons != 0 && error (" AutoFiniteDiff does not currently support constraints" )
210
+ function instantiate_function (f, x, adtype:: AutoFiniteDiff , p, num_cons = 0 )
211
+ num_cons != 0 && error (" AutoFiniteDiff does not currently support constraints" )
213
212
_f = θ -> f. f (θ,p)[1 ]
214
213
215
214
if f. grad === nothing
@@ -234,5 +233,5 @@ function instantiate_function(f, x, adtype::AutoFiniteDiff, p)
234
233
hv = f. hv
235
234
end
236
235
237
- return OptimizationFunction {false,AutoFiniteDiff,typeof(f),typeof(grad),typeof(hess),typeof(hv),Nothing,Nothing,Nothing} (f,adtype,grad,hess,hv,nothing ,nothing ,nothing , 0 )
236
+ return OptimizationFunction {false,AutoFiniteDiff,typeof(f),typeof(grad),typeof(hess),typeof(hv),Nothing,Nothing,Nothing} (f,adtype,grad,hess,hv,nothing ,nothing ,nothing )
238
237
end
0 commit comments