@@ -172,7 +172,7 @@ function SciMLBase.__init(prob::Union{NonlinearProblem{uType, iip},
172
172
else
173
173
d = similar (u)
174
174
d .= min_damping_D
175
- DᵀD = Diagonal (d )
175
+ DᵀD = Diagonal (_vec (d) )
176
176
end
177
177
178
178
loss = internalnorm (fu1)
@@ -209,21 +209,21 @@ function perform_step!(cache::LevenbergMarquardtCache{true})
209
209
210
210
# Usual Levenberg-Marquardt step ("velocity").
211
211
# The following lines do: cache.v = -cache.mat_tmp \ cache.u_tmp
212
- mul! (cache. u_tmp, J' , fu1)
212
+ mul! (_vec ( cache. u_tmp) , J' , _vec ( fu1) )
213
213
@. cache. mat_tmp = JᵀJ + λ * DᵀD
214
214
linres = dolinsolve (alg. precs, linsolve; A = __maybe_symmetric (cache. mat_tmp),
215
215
b = _vec (cache. u_tmp), linu = _vec (cache. du), p = p, reltol = cache. abstol)
216
216
cache. linsolve = linres. cache
217
- @. cache. v = - cache. du
217
+ _vec ( cache. v) . = - 1 .* _vec ( cache. du)
218
218
219
219
# Geodesic acceleration (step_size = v + a / 2).
220
220
@unpack v, α_geodesic, h = cache
221
- f (cache. fu_tmp, u .+ h .* v , p)
221
+ f (cache. fu_tmp, _restructure (u, _vec (u) .+ h .* _vec (v)) , p)
222
222
223
223
# The following lines do: cache.a = -J \ cache.fu_tmp
224
- mul! (cache. Jv, J, v )
224
+ mul! (_vec ( cache. Jv) , J, _vec (v) )
225
225
@. cache. fu_tmp = (2 / h) * ((cache. fu_tmp - fu1) / h - cache. Jv)
226
- mul! (cache. u_tmp, J' , cache. fu_tmp)
226
+ mul! (_vec ( cache. u_tmp) , J' , _vec ( cache. fu_tmp) )
227
227
# NOTE: Don't pass `A` in again, since we want to reuse the previous solve
228
228
linres = dolinsolve (alg. precs, linsolve; b = _vec (cache. u_tmp),
229
229
linu = _vec (cache. du), p = p, reltol = cache. abstol)
@@ -235,7 +235,7 @@ function perform_step!(cache::LevenbergMarquardtCache{true})
235
235
# Require acceptable steps to satisfy the following condition.
236
236
norm_v = norm (v)
237
237
if 2 * norm (cache. a) ≤ α_geodesic * norm_v
238
- @. cache. δ = v + cache. a / 2
238
+ _vec ( cache. δ) . = _vec (v) .+ _vec ( cache. a) . / 2
239
239
@unpack δ, loss_old, norm_v_old, v_old, b_uphill = cache
240
240
f (cache. fu_tmp, u .+ δ, p)
241
241
cache. stats. nf += 1
@@ -251,7 +251,7 @@ function perform_step!(cache::LevenbergMarquardtCache{true})
251
251
return nothing
252
252
end
253
253
cache. fu1 .= cache. fu_tmp
254
- cache. v_old .= v
254
+ _vec ( cache. v_old) .= _vec (v)
255
255
cache. norm_v_old = norm_v
256
256
cache. loss_old = loss
257
257
cache. λ_factor = 1 / cache. damping_decrease_factor
@@ -289,7 +289,7 @@ function perform_step!(cache::LevenbergMarquardtCache{false})
289
289
cache. v = - cache. mat_tmp \ (J' * fu1)
290
290
else
291
291
linres = dolinsolve (alg. precs, linsolve; A = - __maybe_symmetric (cache. mat_tmp),
292
- b = _vec (J' * fu1), linu = _vec (cache. v), p, reltol = cache. abstol)
292
+ b = _vec (J' * _vec ( fu1) ), linu = _vec (cache. v), p, reltol = cache. abstol)
293
293
cache. linsolve = linres. cache
294
294
end
295
295
@@ -300,8 +300,8 @@ function perform_step!(cache::LevenbergMarquardtCache{false})
300
300
_vec (J' * ((2 / h) .* ((f (u .+ h .* v, p) .- fu1) ./ h .- J * v)))
301
301
else
302
302
linres = dolinsolve (alg. precs, linsolve;
303
- b = _mutable (_vec (J' *
304
- (( 2 / h) .* ((f (u .+ h .* v , p) .- fu1) ./ h .- J * v )))),
303
+ b = _mutable (_vec (J' * # ((2 / h) .* ((f(u .+ h .* v, p) .- fu1) ./ h .- J * v)))),
304
+ _vec ((( 2 / h) .* ((_vec ( f (u .+ h .* _restructure (u,v) , p)) .- _vec ( fu1)) ./ h .- J * _vec (v)) )))),
305
305
linu = _vec (cache. a), p, reltol = cache. abstol)
306
306
cache. linsolve = linres. cache
307
307
end
@@ -311,7 +311,7 @@ function perform_step!(cache::LevenbergMarquardtCache{false})
311
311
# Require acceptable steps to satisfy the following condition.
312
312
norm_v = norm (v)
313
313
if 2 * norm (cache. a) ≤ α_geodesic * norm_v
314
- cache. δ = v .+ cache. a ./ 2
314
+ cache. δ = _restructure (cache . δ, _vec (v) .+ _vec ( cache. a) ./ 2 )
315
315
@unpack δ, loss_old, norm_v_old, v_old, b_uphill = cache
316
316
fu_new = f (u .+ δ, p)
317
317
cache. stats. nf += 1
@@ -327,7 +327,7 @@ function perform_step!(cache::LevenbergMarquardtCache{false})
327
327
return nothing
328
328
end
329
329
cache. fu1 = fu_new
330
- cache. v_old = v
330
+ cache. v_old = _restructure (cache . v_old,v)
331
331
cache. norm_v_old = norm_v
332
332
cache. loss_old = loss
333
333
cache. λ_factor = 1 / cache. damping_decrease_factor
0 commit comments