Skip to content

Commit e08bab3

Browse files
authored
Refactor tests for CUTEstModel with benchmarks
1 parent 321052a commit e08bab3

File tree

1 file changed

+0
-10
lines changed

1 file changed

+0
-10
lines changed

test/test_comprehensive.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ using BenchmarkTools
33
using LinearAlgebra
44
using NLPModels
55

6-
# Test with an unconstrained problem first
76
println("Testing with unconstrained problem (ROSENBR):")
87
nlp1 = CUTEstModel{Float64}("ROSENBR")
98
x0 = nlp1.meta.x0
109

11-
# Test hess_coord allocations
1210
println("✓ Problem loaded: $(nlp1.meta.name) ($(nlp1.meta.nvar) vars, $(nlp1.meta.ncon) cons)")
1311
vals_h = Vector{Float64}(undef, nlp1.meta.nnzh)
1412
hess_coord!(nlp1, x0, vals_h)
@@ -18,36 +16,30 @@ println("✓ hess_coord!: $(b_hess.allocs) allocations, $(BenchmarkTools.prettyt
1816

1917
finalize(nlp1)
2018

21-
# Test with a constrained problem
2219
println("\nTesting with constrained problem (HS6):")
2320
nlp2 = CUTEstModel{Float64}("HS6")
2421
x0 = nlp2.meta.x0
2522

2623
println("✓ Problem loaded: $(nlp2.meta.name) ($(nlp2.meta.nvar) vars, $(nlp2.meta.ncon) cons)")
2724
println(" nnzj: $(nlp2.meta.nnzj), nnzh: $(nlp2.meta.nnzh)")
2825

29-
# Test basic functionality
3026
f = obj(nlp2, x0)
3127
g = similar(x0)
3228
grad!(nlp2, x0, g)
3329
println("✓ obj/grad: f = $(round(f, digits=6)), ||g|| = $(round(norm(g), digits=6))")
3430

35-
# Test constraint functions
3631
c = Vector{Float64}(undef, nlp2.meta.ncon)
3732
cons!(nlp2, x0, c)
3833
println("✓ constraints: ||c|| = $(round(norm(c), digits=6))")
3934

40-
# Test cons_coord - this should show major allocation improvements
4135
println("\nTesting cons_coord allocation improvements:")
4236
c1, rows1, cols1, vals1 = cons_coord(nlp2, x0)
4337

44-
# Benchmark cons_coord
4538
b_cons = @benchmark cons_coord($nlp2, $x0) samples=100 evals=5
4639
println("✓ cons_coord: $(b_cons.allocs) allocations, $(BenchmarkTools.prettytime(median(b_cons).time))")
4740
println(" Memory: $(BenchmarkTools.prettymemory(median(b_cons).memory))")
4841
println(" Returned $(length(vals1)) Jacobian elements")
4942

50-
# Test cons_coord!
5143
rows = Vector{Cint}(undef, nlp2.meta.nnzj)
5244
cols = Vector{Cint}(undef, nlp2.meta.nnzj)
5345
vals = Vector{Float64}(undef, nlp2.meta.nnzj)
@@ -56,7 +48,6 @@ c_out = Vector{Float64}(undef, nlp2.meta.ncon)
5648
b_cons_inplace = @benchmark cons_coord!($nlp2, $x0, $c_out, $rows, $cols, $vals) samples=100 evals=5
5749
println("✓ cons_coord!: $(b_cons_inplace.allocs) allocations, $(BenchmarkTools.prettytime(median(b_cons_inplace).time))")
5850

59-
# Test type conversion
6051
println("\nTesting type conversion improvements:")
6152
x0_f32 = Float32.(x0)
6253
g_f32 = Vector{Float32}(undef, nlp2.meta.nvar)
@@ -65,7 +56,6 @@ b_grad_conv = @benchmark grad!($nlp2, $x0_f32, $g_f32) samples=100 evals=5
6556
println("✓ grad! with Float32->Float64 conversion: $(b_grad_conv.allocs) allocations")
6657
println(" Time: $(BenchmarkTools.prettytime(median(b_grad_conv).time))")
6758

68-
# Test hess_coord with constraints
6959
vals_h2 = Vector{Float64}(undef, nlp2.meta.nnzh)
7060
y = zeros(nlp2.meta.ncon)
7161
hess_coord!(nlp2, x0, y, vals_h2)

0 commit comments

Comments
 (0)