Skip to content

Commit ab2c00b

Browse files
committed
Make Rayleigh tests more robust to eigenvectors switching sign.
1 parent 74e99bd commit ab2c00b

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

test/solvers/test_trust_regions.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ include("../utils/example_tasks.jl")
183183

184184
@testset "Allocating Variant" begin
185185
q = trust_regions(M, f, grad_f, Hess_f, p)
186-
@test isapprox(M, q, p_star)
186+
@test isapprox(M, q, p_star) || isapprox(M, q, -p_star)
187187
q2 = copy(M, p)
188188
trust_regions!(M, f, grad_f, Hess_f, q2)
189-
@test isapprox(M, q2, p_star)
189+
@test isapprox(M, q2, p_star) || isapprox(M, q2, -p_star)
190190
# random start point
191191
q3 = trust_regions(M, f, grad_f, Hess_f)
192192
# remove ambiguity
193193
q3 = (sign(q3[1]) == sign(p_star[1])) ? q3 : -q3
194-
@test isapprox(M, q3, p_star)
194+
@test isapprox(M, q3, p_star) || isapprox(M, q3, -p_star)
195195

196196
# a Default
197197
qaAoor = trust_regions(M, f, grad_f)
@@ -211,7 +211,7 @@ include("../utils/example_tasks.jl")
211211
retraction_method=ProjectionRetraction(),
212212
evaluation=InplaceEvaluation(),
213213
)
214-
@test isapprox(M, qaHSR1, p_star)
214+
@test isapprox(M, qaHSR1, p_star) || isapprox(M, qaHSR1, -p_star)
215215

216216
qaHSR1_2 = copy(M, p)
217217
trust_regions!(
@@ -227,7 +227,7 @@ include("../utils/example_tasks.jl")
227227
κ=0.9,
228228
retraction_method=ProjectionRetraction(),
229229
)
230-
@test isapprox(M, qaHSR1_2, p_star)
230+
@test isapprox(M, qaHSR1_2, p_star) || isapprox(M, qaHSR1_2, -p_star)
231231

232232
qaHBFGS = trust_regions(
233233
M,
@@ -242,7 +242,7 @@ include("../utils/example_tasks.jl")
242242
κ=0.9,
243243
retraction_method=ProjectionRetraction(),
244244
)
245-
@test isapprox(M, qaHBFGS, p_star)
245+
@test isapprox(M, qaHBFGS, p_star) || isapprox(M, qaHBFGS, -p_star)
246246

247247
qaHBFGS_2 = copy(M, p)
248248
trust_regions!(
@@ -258,7 +258,7 @@ include("../utils/example_tasks.jl")
258258
κ=0.9,
259259
retraction_method=ProjectionRetraction(),
260260
)
261-
@test isapprox(M, qaHBFGS_2, p_star)
261+
@test isapprox(M, qaHBFGS_2, p_star) || isapprox(M, qaHBFGS_2, -p_star)
262262
end
263263
@testset "Mutating" begin
264264
q3 = copy(M, p)
@@ -271,7 +271,7 @@ include("../utils/example_tasks.jl")
271271
trust_region_radius=1.0,
272272
evaluation=InplaceEvaluation(),
273273
)
274-
@test isapprox(M, q3, p_star)
274+
@test isapprox(M, q3, p_star) || isapprox(M, q3, -p_star)
275275

276276
q4 = copy(M, p)
277277
trust_regions!(
@@ -283,7 +283,7 @@ include("../utils/example_tasks.jl")
283283
trust_region_radius=1.0,
284284
evaluation=InplaceEvaluation(),
285285
)
286-
@test isapprox(M, q4, p_star)
286+
@test isapprox(M, q4, p_star) || isapprox(M, q4, -p_star)
287287

288288
qaHSR1_3 = copy(M, p)
289289

@@ -303,7 +303,7 @@ include("../utils/example_tasks.jl")
303303
retraction_method=ProjectionRetraction(),
304304
evaluation=InplaceEvaluation(),
305305
)
306-
@test isapprox(M, qaHSR1_3, p_star)
306+
@test isapprox(M, qaHSR1_3, p_star) || isapprox(M, qaHSR1_3, -p_star)
307307

308308
qaHBFGS_3 = copy(M, p)
309309
trust_regions!(
@@ -320,7 +320,7 @@ include("../utils/example_tasks.jl")
320320
retraction_method=ProjectionRetraction(),
321321
evaluation=InplaceEvaluation(),
322322
)
323-
@test isapprox(M, qaHBFGS_3, p_star)
323+
@test isapprox(M, qaHBFGS_3, p_star) || isapprox(M, qaHBFGS_3, -p_star)
324324
end
325325
end
326326
@testset "on the Circle" begin

0 commit comments

Comments
 (0)