Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot committed Sep 30, 2020
1 parent c76432d commit 3a9ef15
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/State/GenericStatemod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function compress_state!(stateatx :: AbstractState;
if typeof(getfield(stateatx, k)) <: AbstractVector
katt = getfield(stateatx, k)
if (length(katt) > max_vector_size) setfield!(stateatx, k, [norm(katt, pnorm)]) end
elseif typeof(getfield(stateatx, k)) <: Union{AbstractArray, AbstractMatrix} && !save_matrix
elseif typeof(getfield(stateatx, k)) <: Union{AbstractArray, AbstractMatrix}
if save_matrix
katt = getfield(stateatx, k)
if maximum(size(katt)) > max_vector_size setfield!(stateatx, k, norm(getfield(stateatx, k))) end
Expand Down
2 changes: 1 addition & 1 deletion src/Stopping/LinearAlgebraStopping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,6 @@ function normal_equation_check(pb :: LLSModel,
state :: AbstractState;
pnorm :: Float64 = Inf,
kwargs...)
nres = jtprod_residual(pb, state.x, jprod_residual(pb, state.x, state.x))
nres = jtprod_residual(pb, state.x, residual(pb, state.x))
return norm(nres, pnorm)
end
4 changes: 4 additions & 0 deletions test/test-state/test-unitaire-ListOfStates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ df1 = print(stest, verbose = false)
df2 = print(stest2, verbose = false)

@test typeof(df2) <: DataFrame

stest3 = ListStates(-1, list = [s0, s1, s2], i = 3)

@test stest3[2] == s1
4 changes: 4 additions & 0 deletions test/test-state/test-unitaire-NLPAtXmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ c_uncons_nlp_at_x = copy_compress_state(uncons_nlp_at_x, max_vector_size = 5)
@test c_uncons_nlp_at_x.x == [0.0]
@test c_uncons_nlp_at_x.lambda == [1.0]

uncons_nlp_at_x.Hx = zeros(10,10)
zip_uncons_nlp_at_x = compress_state!(uncons_nlp_at_x, keep = true, save_matrix = true, max_vector_size = 5, Hx = 1)
zip_uncons_nlp_at_x.Hx == 0.0

nlp_64 = NLPAtX(ones(10))
nlp_64.x = ones(10)
nlp_64.fx = 1.0
Expand Down
9 changes: 9 additions & 0 deletions test/test-stopping/test-unitaire-generic-stopping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ stop0.meta.norm_unbounded_x = 2
stop!(stop0)
@test status(stop0, list = true) == [:Optimal, :Unbounded] #indeed ||x||_2 = sqrt(6) !!

#We now test that stop! verifies that:
#- there are no NaN in the score
#- if the listofstates != nothing, stop! increases the list of states with the current_state.
stop0.meta.optimality_check = (a,b) -> NaN
stop0.listofstates = ListStates(state0)
stop!(stop0)
@test :DomainError in status(stop0, list = true)
@test length(stop0.listofstates) == 2

#Initialize a GenericStopping by default
stop_def = GenericStopping(rosenbrock, x0, atol = 1.0)
@test stop_def.current_state.x == x0
Expand Down
22 changes: 16 additions & 6 deletions test/test-stopping/test-unitaire-linearalgebrastopping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,19 @@ la_stop = LAStopping(A, b, GenericState(x0), max_iter = 150000, rtol = 1e-6, max
sa_stop = LAStopping(sparse(A), b, GenericState(sparse(x0)), max_iter = 150000, rtol = 1e-6)
op_stop = LAStopping(LinearSystem(LinearOperator(A), b), GenericState(x0), max_iter = 150000, rtol = 1e-6, max_cntrs = Stopping._init_max_counters_linear_operators(nprod = 150000))

@time RandomizedBlockKaczmarz(la_stop)
@test status(la_stop) == :Optimal
@time RandomizedBlockKaczmarz(sa_stop)
@test status(sa_stop) == :Optimal
@time RandomizedBlockKaczmarz(op_stop)
@test status(op_stop) == :Optimal
try
@time RandomizedBlockKaczmarz(la_stop)
@test status(la_stop) == :Optimal
@time RandomizedBlockKaczmarz(sa_stop)
@test status(sa_stop) == :Optimal
@time RandomizedBlockKaczmarz(op_stop)
@test status(op_stop) == :Optimal
catch
@warn "If LSSModel.A does not exist consider [la_stop.pb.Avals[i,j] for (i) in la_stop.pb.Arows, j in la_stop.pb.Acols]"
#https://github.com/JuliaSmoothOptimizers/NLPModels.jl/blob/master/src/lls_model.jl
end

update!(la_stop.current_state, x = xref)
@test normal_equation_check(la_stop.pb, la_stop.current_state) <= 1e-10
update!(op_stop.current_state, x = xref)
@test normal_equation_check(op_stop.pb, op_stop.current_state) <= 1e-10

0 comments on commit 3a9ef15

Please sign in to comment.