|
1 | | -@everywhere function test_in_place_residual(prob::Symbol) |
2 | | - nlp = make_ad_nlp(prob; use_nls = false) |
3 | | - @test typeof(nlp) <: ADNLPModels.ADNLPModel |
4 | | - nls = make_ad_nlp(prob; use_nls = true) |
5 | | - @test typeof(nls) <: ADNLPModels.ADNLSModel |
6 | | - return test_in_place_residual(prob, nlp, nls) |
7 | | -end |
8 | | - |
9 | | -@everywhere function test_in_place_residual(prob::Symbol, nlp::AbstractNLPModel, nls::AbstractNLSModel) |
10 | | - @testset "Test in-place residual $prob" begin |
11 | | - x = nls.meta.x0 |
12 | | - Fx = similar(x, nls.nls_meta.nequ) |
13 | | - pb = String(prob) |
14 | | - if VERSION ≥ v"1.7" && !occursin("palmer", pb) && (pb != "watson") # palmer residual allocate |
15 | | - @allocated residual!(nls, x, Fx) |
16 | | - @test (@allocated residual!(nls, x, Fx)) == 0 |
17 | | - end |
18 | | - m = OptimizationProblems.eval(Meta.parse("get_$(prob)_nls_nequ"))() |
19 | | - @test nls.nls_meta.nequ == m |
20 | | - end |
21 | | - |
22 | | - @testset "Compare NLS with NLP $prob: x0 and obj are the same." begin |
23 | | - x0 = nlp.meta.x0 |
24 | | - @test x0 == nls.meta.x0 |
25 | | - nlp_fx = obj(nlp, x0) |
26 | | - nls_fx = obj(nls, x0) |
27 | | - are_almost_same = (nlp_fx ≈ nls_fx) | (nlp_fx ≈ 2 * nls_fx) |
28 | | - if !(are_almost_same) |
29 | | - @info "$prob : NLS $(nls_fx) ≈ NLP $(nlp_fx)" |
30 | | - end |
31 | | - @test are_almost_same |
32 | | - end |
33 | | -end |
34 | | - |
35 | | -nls_name_list = intersect(Symbol.(meta[meta.objtype .== :least_squares, :name]), list_problems_ADNLPProblems) |
36 | | -pmap(test_in_place_residual, nls_name_list) |
| 1 | +@everywhere function test_in_place_residual(prob::Symbol) |
| 2 | + nlp = make_ad_nlp(prob; use_nls = false) |
| 3 | + @test typeof(nlp) <: ADNLPModels.ADNLPModel |
| 4 | + nls = make_ad_nlp(prob; use_nls = true) |
| 5 | + @test typeof(nls) <: ADNLPModels.ADNLSModel |
| 6 | + return test_in_place_residual(prob, nlp, nls) |
| 7 | +end |
| 8 | + |
| 9 | +@everywhere function test_in_place_residual( |
| 10 | + prob::Symbol, |
| 11 | + nlp::AbstractNLPModel, |
| 12 | + nls::AbstractNLSModel, |
| 13 | +) |
| 14 | + @testset "Test in-place residual $prob" begin |
| 15 | + x = nls.meta.x0 |
| 16 | + Fx = similar(x, nls.nls_meta.nequ) |
| 17 | + pb = String(prob) |
| 18 | + if VERSION ≥ v"1.7" && !occursin("palmer", pb) && (pb != "watson") # palmer residual allocate |
| 19 | + @allocated residual!(nls, x, Fx) |
| 20 | + @test (@allocated residual!(nls, x, Fx)) == 0 |
| 21 | + end |
| 22 | + m = OptimizationProblems.eval(Meta.parse("get_$(prob)_nls_nequ"))() |
| 23 | + @test nls.nls_meta.nequ == m |
| 24 | + end |
| 25 | + |
| 26 | + @testset "Compare NLS with NLP $prob: x0 and obj are the same." begin |
| 27 | + x0 = nlp.meta.x0 |
| 28 | + @test x0 == nls.meta.x0 |
| 29 | + nlp_fx = obj(nlp, x0) |
| 30 | + nls_fx = obj(nls, x0) |
| 31 | + are_almost_same = (nlp_fx ≈ nls_fx) | (nlp_fx ≈ 2 * nls_fx) |
| 32 | + if !(are_almost_same) |
| 33 | + @info "$prob : NLS $(nls_fx) ≈ NLP $(nlp_fx)" |
| 34 | + end |
| 35 | + @test are_almost_same |
| 36 | + end |
| 37 | +end |
| 38 | + |
| 39 | +nls_name_list = |
| 40 | + intersect(Symbol.(meta[meta.objtype .== :least_squares, :name]), list_problems_ADNLPProblems) |
| 41 | +pmap(test_in_place_residual, nls_name_list) |
0 commit comments