Skip to content

Commit

Permalink
Fix and test warn_maxiter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic2020 committed Aug 22, 2024
1 parent 1744542 commit 8446b04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stackedtime/sim_nr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function sim_nr!(x::AbstractArray{Float64}, sd::StackedTimeSolverData,
nFx = norm(Fx, Inf)
nΔx = Inf
_, λ = damping(0, 1.0, nFx, Fx)::Tuple{Bool,Float64}
while (it < maxiter) && (tol < nFx) &&*tol < nΔx)
while (it <= maxiter) && (tol < nFx) &&*tol < nΔx)
it = it + 1
TMP, Jx = stackedtime_RJ(x, x, sd)
copyto!(Fx, TMP)
Expand Down
20 changes: 20 additions & 0 deletions test/sim_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ rng = Random.default_rng()
@test @compare res01[2] res01[3] quiet
end

@testset "warn_maxiter" begin
m = getE7A()
sssolve!(m)
@test issssolved(m) && (0 == check_sstate(m))

p01 = Plan(m, 1:100)
Random.seed!(rng, 0x1230ABCF)
data01 = steadystatedata(m, p01)
data01[begin:0U, m.variables] .+= randn(rng, m.maxlag, m.nvars)
data01[1U:10U, m.shocks] .+= randn(rng, 10, m.nshks)

@testset "warn_maxiter = false" begin
@test simulate(m, p01, data01; warn_maxiter=false, sim_solver=:sim_nr, verbose=false, fctype=fcnatural, maxiter=1) !== nothing
end

@testset "warn_maxiter = :error" begin
@test_throws ErrorException simulate(m, p01, data01; warn_maxiter=:error, sim_solver=:sim_nr, verbose=false, fctype=fcnatural, maxiter=1)
end
end

@testset "damping" begin

m = getE7A()
Expand Down

0 comments on commit 8446b04

Please sign in to comment.