Skip to content

Commit

Permalink
Typer assertions and simplify function eval all around
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaibhavdixit02 committed Jan 12, 2024
1 parent 9cfa30c commit 8cb560b
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/linesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ end
end

function (alg::__LiFukushimaLineSearch)(prob, fu, u)
@bb u_cache = similar(u)
@bb fu_cache = similar(fu)
T = promote_type(eltype(fu), eltype(u))

Check warning on line 28 in src/linesearch.jl

View check run for this annotation

Codecov / codecov/patch

src/linesearch.jl#L27-L28

Added lines #L27 - L28 were not covered by tests

ϕ = @closure (u, δu, α) -> begin
@bb @. u_cache = u + α * δu
return NONLINEARSOLVE_DEFAULT_NORM(__eval_f(prob, fu_cache, u_cache))
u_cache = @. u + α * δu
return NONLINEARSOLVE_DEFAULT_NORM(prob.f(u_cache, prob.p))

Check warning on line 32 in src/linesearch.jl

View check run for this annotation

Codecov / codecov/patch

src/linesearch.jl#L30-L32

Added lines #L30 - L32 were not covered by tests
end

return __LiFukushimaLineSearchCache(ϕ, T(alg.lambda_0), T(alg.beta), T(alg.sigma_1),

Check warning on line 35 in src/linesearch.jl

View check run for this annotation

Codecov / codecov/patch

src/linesearch.jl#L35

Added line #L35 was not covered by tests
Expand All @@ -45,22 +43,22 @@ function (cache::__LiFukushimaLineSearchCache)(u, δu)
fx_norm = ϕ(T(0))::T

Check warning on line 43 in src/linesearch.jl

View check run for this annotation

Codecov / codecov/patch

src/linesearch.jl#L43

Added line #L43 was not covered by tests

# Non-Blocking exit if the norm is NaN or Inf
DiffEqBase.NAN_CHECK(fx_norm) && return cache.α
DiffEqBase.NAN_CHECK(fx_norm)::Bool && return cache.α

Check warning on line 46 in src/linesearch.jl

View check run for this annotation

Codecov / codecov/patch

src/linesearch.jl#L46

Added line #L46 was not covered by tests

# Early Terminate based on Eq. 2.7
du_norm = NONLINEARSOLVE_DEFAULT_NORM(δu)
fxλ_norm = ϕ(cache.α)
du_norm = NONLINEARSOLVE_DEFAULT_NORM(δu)::T
fxλ_norm = ϕ(cache.α)::T
fxλ_norm cache.ρ * fx_norm - cache.σ₂ * du_norm^2 && return cache.α

Check warning on line 51 in src/linesearch.jl

View check run for this annotation

Codecov / codecov/patch

src/linesearch.jl#L49-L51

Added lines #L49 - L51 were not covered by tests

λ₂, λ₁ = cache.λ₀, cache.λ₀
fxλp_norm = ϕ(λ₂)
fxλp_norm = ϕ(λ₂)::T

Check warning on line 54 in src/linesearch.jl

View check run for this annotation

Codecov / codecov/patch

src/linesearch.jl#L53-L54

Added lines #L53 - L54 were not covered by tests

if DiffEqBase.NAN_CHECK(fxλp_norm)
if DiffEqBase.NAN_CHECK(fxλp_norm)::Bool
nan_converged = false
for _ in 1:(cache.nan_maxiters)
λ₁, λ₂ = λ₂, cache.β * λ₂
fxλp_norm = ϕ(λ₂)
nan_converged = DiffEqBase.NAN_CHECK(fxλp_norm)
nan_converged = DiffEqBase.NAN_CHECK(fxλp_norm)::Bool
nan_converged && break
end
nan_converged || return cache.α

Check warning on line 64 in src/linesearch.jl

View check run for this annotation

Codecov / codecov/patch

src/linesearch.jl#L56-L64

Added lines #L56 - L64 were not covered by tests
Expand Down

0 comments on commit 8cb560b

Please sign in to comment.