Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaibhavdixit02 committed Sep 16, 2023
1 parent 09d7cf9 commit 4e54703
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/ADtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,27 @@ H3 = [Array{Float64}(undef, 2, 2), Array{Float64}(undef, 2, 2)]
optprob.cons_h(H3, x0)
H3 == [[2.0 0.0; 0.0 2.0], [-0.0 1.0; 1.0 0.0]]


G2 = Array{Float64}(undef, 2)
H2 = Array{Float64}(undef, 2, 2)

optf = OptimizationFunction(rosenbrock, Optimization.AutoReverseDiff(), cons = con2_c)
optprob = Optimization.instantiate_function(optf, x0, Optimization.AutoReverseDiff(compile=true),
nothing, 2)
optprob.grad(G2, x0)
@test G1 == G2
optprob.hess(H2, x0)
@test H1 == H2
res = Array{Float64}(undef, 2)
optprob.cons(res, x0)
@test res == [0.0, 0.0]
J = Array{Float64}(undef, 2, 2)
optprob.cons_j(J, [5.0, 3.0])
@test all(isapprox(J, [10.0 6.0; -0.149013 -0.958924]; rtol = 1e-3))
H3 = [Array{Float64}(undef, 2, 2), Array{Float64}(undef, 2, 2)]
optprob.cons_h(H3, x0)
H3 == [[2.0 0.0; 0.0 2.0], [-0.0 1.0; 1.0 0.0]]

G2 = Array{Float64}(undef, 2)
H2 = Array{Float64}(undef, 2, 2)

Expand Down

0 comments on commit 4e54703

Please sign in to comment.