Skip to content

Commit 25953a0

Browse files
authored
Merge pull request #98 from JuliaNLSolvers/fixinstat
Fix InitialStatic bug
2 parents 264c375 + 57df7ff commit 25953a0

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/initialguess.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ is scaled with the `l_2` norm of the step direction.
1313
end
1414

1515
function (is::InitialStatic{T})(ls, state, phi_0, dphi_0, df) where T
16-
state.alpha = is.alpha
17-
if is.scaled == true && (ns = vecnorm(state.s)) > zero(T)
18-
# TODO: Type instability if there's a type mismatch between is.alpha and ns
19-
state.alpha *= min(is.alpha, ns) / ns
16+
PT = promote_type(T, eltype(state.s))
17+
if is.scaled == true && (ns = vecnorm(state.s)) > zero(PT)
18+
# TODO: Type instability if there's a type mismatch between is.alpha and ns?
19+
state.alpha = PT(min(is.alpha, ns)) / ns
20+
else
21+
state.alpha = PT(is.alpha)
2022
end
2123
end
2224

test/initial.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@
4343
state = getstate()
4444
is = InitialStatic(alpha = 0.5, scaled = true)
4545
is(ls, state, phi_0, dphi_0, df)
46-
@test state.alpha == 0.08838834764831843
46+
@test state.alpha == 0.5 / vecnorm(state.s)
47+
@test ls.mayterminate[] == false
48+
is = InitialStatic(alpha = 0.5, scaled = true)
49+
state.s .= (is.alpha / 100)
50+
is(ls, state, phi_0, dphi_0, df)
51+
@test state.alpha == 1.0
4752
@test ls.mayterminate[] == false
4853

4954
# Test Previous

0 commit comments

Comments
 (0)