Skip to content

Commit 8f739fb

Browse files
committed
Some progress on LM
1 parent 59a8713 commit 8f739fb

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/jacobian.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
@concrete struct KrylovJᵀJ
2+
JᵀJ
3+
Jᵀ
4+
end
15
sparsity_detection_alg(_, _) = NoSparsityDetection()
26
function sparsity_detection_alg(f, ad::AbstractSparseADType)
37
if f.sparsity === nothing
@@ -54,7 +58,7 @@ function jacobian_caches(alg::AbstractNonlinearSolveAlgorithm, f::F, u, p, ::Val
5458
# NOTE: The deepcopy is needed here since we are using the resid_prototype elsewhere
5559
fu = f.resid_prototype === nothing ? (iip ? _mutable_zero(u) : _mutable(f(u, p))) :
5660
(iip ? deepcopy(f.resid_prototype) : f.resid_prototype)
57-
if !has_analytic_jac && (linsolve_needs_jac || alg_wants_jac) # || needsJᵀJ)
61+
if !has_analytic_jac && (linsolve_needs_jac || alg_wants_jac)
5862
sd = sparsity_detection_alg(f, alg.ad)
5963
ad = alg.ad
6064
jac_cache = iip ? sparse_jacobian_cache(ad, sd, uf, fu, _maybe_mutable(u, ad)) :
@@ -147,11 +151,6 @@ function __init_JᵀJ(J::FunctionOperator, fu, uf, u, args...;
147151
return JᵀJ, Jᵀfu
148152
end
149153

150-
@concrete struct KrylovJᵀJ
151-
JᵀJ
152-
Jᵀ
153-
end
154-
155154
SciMLBase.isinplace(JᵀJ::KrylovJᵀJ) = isinplace(JᵀJ.Jᵀ)
156155

157156
function __concrete_jac_transpose_autodiff(jac_transpose_autodiff, jac_autodiff, uf)

src/levenberg.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ function LevenbergMarquardt(; concrete_jac = nothing, linsolve = nothing,
106106
α_geodesic::Real = 0.75, b_uphill::Real = 1.0, min_damping_D::AbstractFloat = 1e-8,
107107
adkwargs...)
108108
ad = default_adargs_to_adtype(; adkwargs...)
109-
return LevenbergMarquardt{_unwrap_val(concrete_jac)}(ad, linsolve, precs,
109+
_concrete_jac = ifelse(concrete_jac === nothing, true, concrete_jac)
110+
return LevenbergMarquardt{_unwrap_val(_concrete_jac)}(ad, linsolve, precs,
110111
damping_initial, damping_increase_factor, damping_decrease_factor,
111112
finite_diff_step_geodesic, α_geodesic, b_uphill, min_damping_D)
112113
end

0 commit comments

Comments
 (0)