@@ -224,7 +224,7 @@ function SciMLBase.__init(prob::Union{NonlinearProblem{uType, iip},
224224 @bb u_cache = copy (u)
225225 @bb u_cache_2 = similar (u)
226226 @bb fu_cache_2 = similar (fu)
227- Jv = J * v
227+ Jv = J * _vec (v)
228228 @bb v_cache = zero (v)
229229
230230 return LevenbergMarquardtCache {iip, fastls} (f, alg, u, u_cache, u_cache_2, fu, fu_cache,
@@ -265,16 +265,15 @@ function perform_step!(cache::LevenbergMarquardtCache{iip, fastls}) where {iip,
265265 end
266266 linres = dolinsolve (alg. precs, linsolve; A = cache. mat_tmp,
267267 b = cache. rhs_tmp, linu = _vec (cache. v), cache. p, reltol = cache. abstol)
268- cache. linsolve = linres. cache
269- @bb @. cache. v = - linres. u
270268 else
271269 @bb cache. u_cache_2 = transpose (cache. J) × cache. fu
272270 @bb @. cache. mat_tmp = cache. JᵀJ + cache. λ * cache. DᵀD
273271 linres = dolinsolve (alg. precs, linsolve; A = __maybe_symmetric (cache. mat_tmp),
274272 b = _vec (cache. u_cache_2), linu = _vec (cache. v), cache. p, reltol = cache. abstol)
275- cache. linsolve = linres. cache
276- @bb @. cache. v = - linres. u
277273 end
274+ cache. linsolve = linres. cache
275+ linu = _restructure (cache. v, linres. u)
276+ @bb @. cache. v = - linu
278277
279278 update_trace! (cache. trace, cache. stats. nsteps + 1 , get_u (cache), get_fu (cache), cache. J,
280279 cache. v)
@@ -285,9 +284,9 @@ function perform_step!(cache::LevenbergMarquardtCache{iip, fastls}) where {iip,
285284
286285 # The following lines do: cache.a = -cache.mat_tmp \ cache.fu_tmp
287286 # NOTE: Don't pass `A`` in again, since we want to reuse the previous solve
288- @bb cache. Jv = cache. J × cache. v
289- @bb @. cache. fu_cache_2 = ( 2 / cache. h) *
290- ((cache. fu_cache_2 - cache. fu) / cache. h - cache . Jv)
287+ @bb cache. Jv = cache. J × vec ( cache. v)
288+ Jv = _restructure ( cache. fu_cache_2, cache. Jv)
289+ @bb @. cache . fu_cache_2 = ( 2 / cache . h) * ((cache. fu_cache_2 - cache. fu) / cache. h - Jv)
291290 if fastls
292291 if setindex_trait (cache. rhs_tmp) === CanSetindex ()
293292 cache. rhs_tmp[1 : length (cache. fu)] .= _vec (cache. fu_cache_2)
@@ -296,15 +295,14 @@ function perform_step!(cache::LevenbergMarquardtCache{iip, fastls}) where {iip,
296295 end
297296 linres = dolinsolve (alg. precs, linsolve; b = cache. rhs_tmp, linu = _vec (cache. a),
298297 cache. p, reltol = cache. abstol)
299- cache. linsolve = linres. cache
300- @bb @. cache. a = - linres. u
301298 else
302299 @bb cache. u_cache_2 = transpose (cache. J) × cache. fu_cache_2
303300 linres = dolinsolve (alg. precs, linsolve; b = _vec (cache. u_cache_2),
304301 linu = _vec (cache. a), cache. p, reltol = cache. abstol)
305- cache. linsolve = linres. cache
306- @bb @. cache. a = - linres. u
307302 end
303+ cache. linsolve = linres. cache
304+ linu = _restructure (cache. a, linres. u)
305+ @bb @. cache. a = - linu
308306
309307 cache. stats. nsolve += 2
310308 cache. stats. nfactors += 2
0 commit comments