Skip to content

Commit 576bb88

Browse files
update tests
1 parent 144f9a4 commit 576bb88

File tree

3 files changed

+23
-36
lines changed

3 files changed

+23
-36
lines changed

test/runtests.jl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,9 @@ for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1"), (IndBallL0(10 * com
9191
x0[p[1:nz]] = sign.(randn(nz)) # initial guess with nz nonzeros (necessary for h = B0)
9292
args = solver_sym == :LM ? () : (NormLinf(1.0),)
9393
out = solver(bpdn_nls, h, args..., options, x0 = x0)
94-
@test typeof(out.solution) == typeof(bpdn_nls.meta.x0)
95-
@test length(out.solution) == bpdn_nls.meta.nvar
96-
@test typeof(out.solver_specific[:Fhist]) == typeof(out.solution)
97-
@test typeof(out.solver_specific[:Hhist]) == typeof(out.solution)
98-
@test typeof(out.solver_specific[:SubsolverCounter]) == Array{Int, 1}
94+
@test typeof(out.solution) == typeof(bpdn.meta.x0)
95+
@test length(out.solution) == bpdn.meta.nvar
9996
@test typeof(out.dual_feas) == eltype(out.solution)
100-
@test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:Hhist])
101-
@test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:SubsolverCounter])
102-
@test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:NLSGradHist])
103-
@test out.solver_specific[:NLSGradHist][end] ==
104-
bpdn_nls.counters.neval_jprod_residual + bpdn_nls.counters.neval_jtprod_residual - 1
105-
@test obj(bpdn_nls, out.solution) == out.solver_specific[:Fhist][end]
106-
@test h(out.solution) == out.solver_specific[:Hhist][end]
10797
@test out.status == :first_order
10898
end
10999
end

test/test_allocs.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ macro wrappedallocs(expr)
4040
end
4141

4242
# Test non allocating solve!
43-
@testset "allocs" begin
43+
@testset "NLP allocs" begin
4444
for (h, h_name) ((NormL0(λ), "l0"),)
4545
for (solver, solver_name) ((:R2Solver, "R2"), (:R2DHSolver, "R2DH"), (:R2NSolver, "R2N"))
4646
@testset "$(solver_name)" begin
@@ -59,3 +59,18 @@ end
5959
end
6060
end
6161
end
62+
63+
@testset "NLS allocs" begin
64+
for (h, h_name) ((NormL0(λ), "l0"),)
65+
for (solver, solver_name) ((:LMSolver, "LM"), )
66+
@testset "$(solver_name)" begin
67+
solver_name == "LM" && continue #FIXME
68+
reg_nlp = RegularizedNLPModel(bpdn_nls, h)
69+
solver = eval(solver)(reg_nlp)
70+
stats = RegularizedExecutionStats(reg_nlp)
71+
@test @wrappedallocs(solve!(solver, reg_nlp, stats, σk = 1.0, atol = 1e-6, rtol = 1e-6)) == 0
72+
@test stats.status == :first_order
73+
end
74+
end
75+
end
76+
end

test/test_bounds.jl

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,9 @@ for (h, h_name) ∈ ((NormL0(λ), "l0"), (NormL1(λ), "l1"))
5454
args = solver_sym == :LM ? () : (NormLinf(1.0),)
5555
@test has_bounds(bpdn_nls2)
5656
out = solver(bpdn_nls2, h, args..., options, x0 = x0)
57-
@test typeof(out.solution) == typeof(bpdn_nls2.meta.x0)
58-
@test length(out.solution) == bpdn_nls2.meta.nvar
59-
@test typeof(out.solver_specific[:Fhist]) == typeof(out.solution)
60-
@test typeof(out.solver_specific[:Hhist]) == typeof(out.solution)
61-
@test typeof(out.solver_specific[:SubsolverCounter]) == Array{Int, 1}
57+
@test typeof(out.solution) == typeof(bpdn.meta.x0)
58+
@test length(out.solution) == bpdn.meta.nvar
6259
@test typeof(out.dual_feas) == eltype(out.solution)
63-
@test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:Hhist])
64-
@test length(out.solver_specific[:Fhist]) == length(out.solver_specific[:SubsolverCounter])
65-
@test obj(bpdn_nls2, out.solution) == out.solver_specific[:Fhist][end]
66-
@test h(out.solution) == out.solver_specific[:Hhist][end]
6760
@test out.status == :first_order
6861
end
6962
end
@@ -108,20 +101,9 @@ for (h, h_name) ∈ ((NormL0(λ), "l0"),)
108101
@test has_bounds(bpdn_nls2)
109102
LM_out =
110103
LM(bpdn_nls2, h, options, x0 = x0, subsolver = R2DH, subsolver_options = subsolver_options)
111-
@test typeof(LM_out.solution) == typeof(bpdn_nls2.meta.x0)
112-
@test length(LM_out.solution) == bpdn_nls2.meta.nvar
113-
@test typeof(LM_out.solver_specific[:Fhist]) == typeof(LM_out.solution)
114-
@test typeof(LM_out.solver_specific[:Hhist]) == typeof(LM_out.solution)
115-
@test typeof(LM_out.solver_specific[:SubsolverCounter]) == Array{Int, 1}
116-
@test typeof(LM_out.dual_feas) == eltype(LM_out.solution)
117-
@test length(LM_out.solver_specific[:Fhist]) == length(LM_out.solver_specific[:Hhist])
118-
@test length(LM_out.solver_specific[:Fhist]) ==
119-
length(LM_out.solver_specific[:SubsolverCounter])
120-
@test length(LM_out.solver_specific[:Fhist]) == length(LM_out.solver_specific[:NLSGradHist])
121-
@test LM_out.solver_specific[:NLSGradHist][end] ==
122-
bpdn_nls2.counters.neval_jprod_residual + bpdn_nls2.counters.neval_jtprod_residual - 1
123-
@test obj(bpdn_nls2, LM_out.solution) == LM_out.solver_specific[:Fhist][end]
124-
@test h(LM_out.solution) == LM_out.solver_specific[:Hhist][end]
104+
@test typeof(LM_out.solution) == typeof(bpdn.meta.x0)
105+
@test length(LM_out.solution) == bpdn.meta.nvar
106+
@test typeof(LM_out.dual_feas) == eltype(out.solution)
125107
@test LM_out.status == :first_order
126108
end
127109
end

0 commit comments

Comments
 (0)