@@ -490,3 +490,45 @@ sol = solve(prob, Optim.KrylovTrustRegion())
490
490
491
491
sol = solve (prob, Optimisers. ADAM (0.1 ), maxiters = 1000 )
492
492
@test 10 * sol. objective < l1
493
+
494
+ optf = OptimizationFunction (rosenbrock, Optimization. AutoSparseReverseDiff (), cons = con2_c)
495
+ optprob = Optimization. instantiate_function (optf, x0, Optimization. AutoSparseReverseDiff (),
496
+ nothing , 2 )
497
+ G2 = Array {Float64} (undef, 2 )
498
+ optprob. grad (G2, x0)
499
+ @test G1≈ G2 rtol= 1e-4
500
+ H2 = Array {Float64} (undef, 2 , 2 )
501
+ optprob. hess (H2, x0)
502
+ @test H1≈ H2 rtol= 1e-4
503
+ res = Array {Float64} (undef, 2 )
504
+ optprob. cons (res, x0)
505
+ @test res≈ [0.0 , 0.0 ] atol= 1e-4
506
+ optprob. cons (res, [1.0 , 2.0 ])
507
+ @test res ≈ [5.0 , 0.682941969615793 ]
508
+ J = Array {Float64} (undef, 2 , 2 )
509
+ optprob. cons_j (J, [5.0 , 3.0 ])
510
+ @test all (isapprox (J, [10.0 6.0 ; - 0.149013 - 0.958924 ]; rtol = 1e-3 ))
511
+ H3 = [Array {Float64} (undef, 2 , 2 ), Array {Float64} (undef, 2 , 2 )]
512
+ optprob. cons_h (H3, x0)
513
+ @test H3 ≈ [[2.0 0.0 ; 0.0 2.0 ], [- 0.0 1.0 ; 1.0 0.0 ]]
514
+
515
+ optf = OptimizationFunction (rosenbrock, Optimization. AutoSparseReverseDiff ())
516
+ optprob = Optimization. instantiate_function (optf, x0, Optimization. AutoSparseReverseDiff (),
517
+ nothing )
518
+ optprob. grad (G2, x0)
519
+ @test G1≈ G2 rtol= 1e-6
520
+ optprob. hess (H2, x0)
521
+ @test H1≈ H2 rtol= 1e-6
522
+
523
+ prob = OptimizationProblem (optf, x0)
524
+ sol = solve (prob, Optim. BFGS ())
525
+ @test 10 * sol. objective < l1
526
+
527
+ sol = solve (prob, Optim. Newton ())
528
+ @test 10 * sol. objective < l1
529
+
530
+ sol = solve (prob, Optim. KrylovTrustRegion ())
531
+ @test sol. objective < l1
532
+
533
+ sol = solve (prob, Optimisers. ADAM (0.1 ), maxiters = 1000 )
534
+ @test 10 * sol. objective < l1
0 commit comments