116
116
117
117
function _hessian_slice_inner (d, ex, :: Val{CHUNK} ) where {CHUNK}
118
118
T = ForwardDiff. Partials{CHUNK,Float64} # This is our element type.
119
- input_ϵ = _reinterpret_unsafe (T, d. input_ϵ)
120
119
fill! (d. output_ϵ, 0.0 )
121
120
output_ϵ = _reinterpret_unsafe (T, d. output_ϵ)
122
121
subexpr_forward_values_ϵ =
@@ -126,22 +125,10 @@ function _hessian_slice_inner(d, ex, ::Val{CHUNK}) where {CHUNK}
126
125
subexpr_forward_values_ϵ[i] = _forward_eval_ϵ (
127
126
d,
128
127
subexpr,
129
- _reinterpret_unsafe (T, d. storage_ϵ),
130
128
_reinterpret_unsafe (T, subexpr. partials_storage_ϵ),
131
- input_ϵ,
132
- subexpr_forward_values_ϵ,
133
- d. data. operators,
134
129
)
135
130
end
136
- _forward_eval_ϵ (
137
- d,
138
- ex,
139
- _reinterpret_unsafe (T, d. storage_ϵ),
140
- _reinterpret_unsafe (T, d. partials_storage_ϵ),
141
- input_ϵ,
142
- subexpr_forward_values_ϵ,
143
- d. data. operators,
144
- )
131
+ _forward_eval_ϵ (d, ex, _reinterpret_unsafe (T, d. partials_storage_ϵ))
145
132
# do a reverse pass
146
133
subexpr_reverse_values_ϵ =
147
134
_reinterpret_unsafe (T, d. subexpression_reverse_values_ϵ)
180
167
_forward_eval_ϵ(
181
168
d::NLPEvaluator,
182
169
ex::Union{_FunctionStorage,_SubexpressionStorage},
183
- storage_ϵ::AbstractVector{ForwardDiff.Partials{N,T}},
184
170
partials_storage_ϵ::AbstractVector{ForwardDiff.Partials{N,T}},
185
- x_values_ϵ,
186
- subexpression_values_ϵ,
187
- user_operators::Nonlinear.OperatorRegistry,
188
171
) where {N,T}
189
172
190
173
Evaluate the directional derivatives of the expression tree in `ex`.
@@ -198,15 +181,15 @@ This assumes that `_reverse_model(d, x)` has already been called.
198
181
function _forward_eval_ϵ (
199
182
d:: NLPEvaluator ,
200
183
ex:: Union{_FunctionStorage,_SubexpressionStorage} ,
201
- storage_ϵ :: AbstractVector{ForwardDiff.Partials{N,T} } ,
202
- partials_storage_ϵ :: AbstractVector{ ForwardDiff.Partials{N,T}},
203
- x_values_ϵ,
204
- subexpression_values_ϵ,
205
- user_operators :: Nonlinear.OperatorRegistry ,
206
- ) where {N,T}
184
+ partials_storage_ϵ :: AbstractVector{P } ,
185
+ ) where {N,T,P <: ForwardDiff.Partials{N,T} }
186
+ storage_ϵ = _reinterpret_unsafe (P, d . storage_ϵ)
187
+ x_values_ϵ = reinterpret (P, d . input_ϵ)
188
+ subexpression_values_ϵ =
189
+ _reinterpret_unsafe (P, d . subexpression_forward_values_ϵ)
207
190
@assert length (storage_ϵ) >= length (ex. nodes)
208
191
@assert length (partials_storage_ϵ) >= length (ex. nodes)
209
- zero_ϵ = zero (ForwardDiff . Partials{N,T} )
192
+ zero_ϵ = zero (P )
210
193
# ex.nodes is already in order such that parents always appear before children
211
194
# so a backwards pass through ex.nodes is a forward pass through the tree
212
195
children_arr = SparseArrays. rowvals (ex. adj)
@@ -339,16 +322,16 @@ function _forward_eval_ϵ(
339
322
n_children,
340
323
)
341
324
has_hessian = Nonlinear. eval_multivariate_hessian (
342
- user_operators ,
343
- user_operators . multivariate_operators[node. index],
325
+ d . data . operators ,
326
+ d . data . operators . multivariate_operators[node. index],
344
327
H,
345
328
f_input,
346
329
)
347
330
# This might be `false` if we extend this code to all
348
331
# multivariate functions.
349
332
@assert has_hessian
350
333
for col in 1 : n_children
351
- dual = zero (ForwardDiff . Partials{N,T} )
334
+ dual = zero (P )
352
335
for row in 1 : n_children
353
336
# Make sure we get the lower-triangular component.
354
337
h = row >= col ? H[row, col] : H[col, row]
@@ -366,7 +349,7 @@ function _forward_eval_ϵ(
366
349
elseif node. type == Nonlinear. NODE_CALL_UNIVARIATE
367
350
@inbounds child_idx = children_arr[ex. adj. colptr[k]]
368
351
f′′ = Nonlinear. eval_univariate_hessian (
369
- user_operators ,
352
+ d . data . operators ,
370
353
node. index,
371
354
ex. forward_storage[child_idx],
372
355
)
0 commit comments