|
1 |
| -export test_allocs_nlpmodels, test_allocs_nlsmodels, print_nlp_allocations |
| 1 | +export test_allocs_nlpmodels, test_allocs_nlsmodels, test_zero_allocations, print_nlp_allocations |
2 | 2 |
|
3 | 3 | """
|
4 | 4 | test_allocs_nlpmodels(nlp::AbstractNLPModel; linear_api = false, exclude = [])
|
@@ -388,3 +388,29 @@ function print_nlp_allocations(io, nlp::AbstractNLPModel, table::Dict; only_nonz
|
388 | 388 | println(io, join(lines, "\n") * "\n")
|
389 | 389 | return table
|
390 | 390 | end
|
| 391 | + |
| 392 | +""" |
| 393 | + test_zero_allocations(table::Dict, name::String = "Generic") |
| 394 | + test_zero_allocations(nlp::AbstractNLPModel; kwargs...) |
| 395 | +
|
| 396 | +Test wether the result of `test_allocs_nlpmodels(nlp)` and `test_allocs_nlsmodels(nlp)` is 0. |
| 397 | +""" |
| 398 | +function test_zero_allocations(nlp::AbstractNLPModel; kwargs...) |
| 399 | + table = test_allocs_nlpmodels(nlp; kwargs...) |
| 400 | + return test_zero_allocations(table, get_name(nlp)) |
| 401 | +end |
| 402 | + |
| 403 | +function test_zero_allocations(nlp::AbstractNLSModel; linear_api = linear_api, kwargs...) |
| 404 | + table_nlp = test_allocs_nlpmodels(nlp; linear_api = linear_api, kwargs...) |
| 405 | + table_nls = test_allocs_nlsmodels(nlp; kwargs...) |
| 406 | + table = merge(table_nlp, table_nls) |
| 407 | + return test_zero_allocations(table, get_name(nlp)) |
| 408 | +end |
| 409 | + |
| 410 | +function test_zero_allocations(table::Dict, name::String = "Generic") |
| 411 | + @testset "Test 0-allocations of NLPModel API for $name" begin |
| 412 | + for k in keys(table) |
| 413 | + isnan(table[k]) || @test table[k] == 0 |
| 414 | + end |
| 415 | + end |
| 416 | +end |
0 commit comments