Skip to content

Commit 0cca30e

Browse files
committed
improve coverage
1 parent 25407c1 commit 0cca30e

1 file changed

Lines changed: 60 additions & 8 deletions

File tree

test/plans/test_stepsize.jl

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,43 @@ end
515515
α = hzls_u3(dmp, gs, 1, η)
516516
@test α > 0
517517
end
518+
@testset "U3 (b) trigger test" begin
519+
M = Euclidean(1)
520+
# Force U3 (b) in _hz_u3:
521+
# 1) At d=0.5 we need df < 0 and f(d) <= f(0) + ϵₖ with no termination,
522+
# so i_a_bar gets updated to i_d.
523+
# 2) On the next U3 iteration we return from the loop.
524+
function f_u3b(M, q)
525+
return 0.0
526+
end
527+
528+
function grad_f_u3b(M, q)
529+
v = q[1]
530+
if isapprox(v, 0.0; atol = 1.0e-12)
531+
return [-1.0]
532+
elseif isapprox(v, 1.0; atol = 1.0e-12)
533+
return [1.0]
534+
elseif isapprox(v, 0.5; atol = 1.0e-12)
535+
return [-1.0]
536+
elseif isapprox(v, 0.75; atol = 1.0e-12)
537+
return [1.0]
538+
end
539+
return [0.0]
540+
end
541+
542+
dmp = DefaultManoptProblem(M, ManifoldGradientObjective(f_u3b, grad_f_u3b))
543+
p = [0.0]
544+
η = [1.0]
545+
hzls_u3b = Manopt.HagerZhangLinesearchStepsize(M; max_function_evaluations = 4)
546+
Manopt.initialize_stepsize!(hzls_u3b)
547+
Manopt._hz_evaluate_next_step(hzls_u3b, M, dmp, p, η, 0.0)
548+
Manopt._hz_evaluate_next_step(hzls_u3b, M, dmp, p, η, 1.0)
549+
550+
(i_a, i_b, f_eval, f_wolfe) = Manopt._hz_u3(hzls_u3b, M, dmp, p, η, 1, 2)
551+
@test (i_a, i_b) == (3, 4)
552+
@test f_eval
553+
@test !f_wolfe
554+
end
518555
@testset "U3 (c) info trigger test" begin
519556
M = Euclidean(1)
520557
# Force U3 (c) inside _hz_u3 by making the mid-point have
@@ -575,6 +612,29 @@ end
575612
@test !f_eval
576613
@test !f_wolfe
577614
end
615+
@testset "U0 out-of-bracket early return" begin
616+
M = Euclidean(1)
617+
f(M, p) = sum(p .^ 2)
618+
grad_f(M, p) = 2 .* p
619+
dmp = DefaultManoptProblem(M, ManifoldGradientObjective(f, grad_f))
620+
p = [0.0]
621+
η = [1.0]
622+
623+
hzls_u0 = Manopt.HagerZhangLinesearchStepsize(M; max_function_evaluations = 5)
624+
Manopt.initialize_stepsize!(hzls_u0)
625+
Manopt._hz_evaluate_next_step(hzls_u0, M, dmp, p, η, 0.0)
626+
Manopt._hz_evaluate_next_step(hzls_u0, M, dmp, p, η, 1.0)
627+
628+
last_eval_before = hzls_u0.last_evaluation_index
629+
630+
# c is left of bracket [0, 1] -> U0 early return
631+
@test (1, 2, -1, false, false) == Manopt._hz_update(hzls_u0, M, dmp, p, η, 1, 2, -0.1)
632+
@test hzls_u0.last_evaluation_index == last_eval_before
633+
634+
# c is right of bracket [0, 1] -> U0 early return
635+
@test (1, 2, -1, false, false) == Manopt._hz_update(hzls_u0, M, dmp, p, η, 1, 2, 1.1)
636+
@test hzls_u0.last_evaluation_index == last_eval_before
637+
end
578638

579639
@testset "S2 trigger test" begin
580640
M = Euclidean(1)
@@ -633,14 +693,6 @@ end
633693
# 3. Secant gives c=0.2. At c, df=-0.1 and f=0 -> U2.
634694

635695
function f_s3(M, q)
636-
v = q[1]
637-
if isapprox(v, 0.0; atol = 1.0e-12)
638-
return 0.0
639-
elseif isapprox(v, 1.0; atol = 1.0e-12)
640-
return 0.0
641-
elseif isapprox(v, 0.2; atol = 1.0e-12)
642-
return 0.0
643-
end
644696
return 0.0
645697
end
646698

0 commit comments

Comments
 (0)