Skip to content

Commit

Permalink
make tests pass?
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 25, 2023
1 parent 2700fce commit b76a3ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/broyden.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function perform_step!(cache::GeneralBroydenCache{true})
else
mul!(_vec(J⁻¹df), J⁻¹, _vec(dfu))
mul!(J⁻¹₂, _vec(du)', J⁻¹)
du .= (du .- J⁻¹df) ./ (dot(du, J⁻¹df) .+ T(1e-5))
denom = dot(du, J⁻¹df)
du .= (du .- J⁻¹df) ./ ifelse(iszero(denom), T(1e-5), denom)
mul!(J⁻¹, _vec(du), J⁻¹₂, 1, 1)
end
fu .= fu2
Expand Down Expand Up @@ -136,7 +137,8 @@ function perform_step!(cache::GeneralBroydenCache{false})
else
cache.J⁻¹df = _restructure(cache.J⁻¹df, cache.J⁻¹ * _vec(cache.dfu))
cache.J⁻¹₂ = _vec(cache.du)' * cache.J⁻¹
cache.du = (cache.du .- cache.J⁻¹df) ./ (dot(cache.du, cache.J⁻¹df) .+ T(1e-5))
denom = dot(cache.du, cache.J⁻¹df)
cache.du = (cache.du .- cache.J⁻¹df) ./ ifelse(iszero(denom), T(1e-5), denom)
cache.J⁻¹ = cache.J⁻¹ .+ _vec(cache.du) * cache.J⁻¹₂
end
cache.fu = cache.fu2
Expand Down
8 changes: 4 additions & 4 deletions src/lbroyden.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ function perform_step!(cache::LimitedMemoryBroydenCache{true})
__lbroyden_matvec!(_vec(cache.vᵀ_cache), cache.Ux, U_part, Vᵀ_part, _vec(cache.du))
__lbroyden_rmatvec!(_vec(cache.u_cache), cache.xᵀVᵀ, U_part, Vᵀ_part,
_vec(cache.dfu))
cache.u_cache .= (du .- cache.u_cache) ./
(dot(cache.vᵀ_cache, cache.dfu) .+ T(1e-5))
denom = dot(cache.vᵀ_cache, cache.dfu)
cache.u_cache .= (du .- cache.u_cache) ./ ifelse(iszero(denom), T(1e-5), denom)

idx = mod1(cache.iterations_since_reset + 1, size(cache.U, 1))
selectdim(cache.U, 1, idx) .= _vec(cache.u_cache)
Expand Down Expand Up @@ -179,8 +179,8 @@ function perform_step!(cache::LimitedMemoryBroydenCache{false})
__lbroyden_matvec(U_part, Vᵀ_part, _vec(cache.du)))
cache.u_cache = _restructure(cache.u_cache,
__lbroyden_rmatvec(U_part, Vᵀ_part, _vec(cache.dfu)))
cache.u_cache = (cache.du .- cache.u_cache) ./
(dot(cache.vᵀ_cache, cache.dfu) .+ T(1e-5))
denom = dot(cache.vᵀ_cache, cache.dfu)
cache.u_cache = (cache.du .- cache.u_cache) ./ ifelse(iszero(denom), T(1e-5), denom)

idx = mod1(cache.iterations_since_reset + 1, size(cache.U, 1))
selectdim(cache.U, 1, idx) .= _vec(cache.u_cache)
Expand Down
8 changes: 4 additions & 4 deletions test/23_test_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function test_on_library(problems, dicts, alg_ops, broken_tests, ϵ = 1e-4)
for (idx, (problem, dict)) in enumerate(zip(problems, dicts))
x = dict["start"]
res = similar(x)
nlprob = NonlinearProblem(problem, x)
nlprob = NonlinearProblem(problem, copy(x))
@testset "$idx: $(dict["title"])" begin
for alg in alg_ops
try
Expand Down Expand Up @@ -86,9 +86,9 @@ end
GeneralBroyden(; linesearch = BackTracking()))

broken_tests = Dict(alg => Int[] for alg in alg_ops)
broken_tests[alg_ops[1]] = [1, 3, 4, 5, 6, 11, 12, 13, 14]
broken_tests[alg_ops[2]] = [1, 2, 3, 4, 5, 6, 9, 11, 13, 15, 16, 21, 22]
broken_tests[alg_ops[3]] = [1, 2, 4, 5, 6, 11, 12, 13, 14, 21]
broken_tests[alg_ops[1]] = [1, 2, 4, 5, 6, 11, 12, 13, 14]
broken_tests[alg_ops[2]] = [1, 2, 3, 4, 5, 6, 9, 11, 13, 22]
broken_tests[alg_ops[3]] = [1, 4, 5, 6, 11, 12, 13, 14, 21]

test_on_library(problems, dicts, alg_ops, broken_tests)
end
Expand Down

0 comments on commit b76a3ce

Please sign in to comment.