Skip to content

Commit ce143db

Browse files
timholyamontoison
authored andcommitted
Add failing tests for warmstart
This also includes two `@test_broken` cases that should be fixed separately someday.
1 parent a9610e6 commit ce143db

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

test/test_tricg.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@
160160
M⁻¹ = inv(M)
161161
N⁻¹ = inv(N)
162162
(x, y, stats) = tricg(A, b, c, M=M⁻¹, N=N⁻¹)
163+
K = [M A; A' -N]
164+
r = [b; c] - K * [x; y]
165+
H = [M zeros(size(M, 1), size(N, 2)); zeros(size(N, 1), size(M, 2)) N]
166+
@test sqrt(dot(r, inv(H) * r)) / sqrt(dot([b; c], inv(H) * [b; c])) tricg_tol
163167
end
164168

165169
for transpose (false, true)

test/test_trimr.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@
200200
M⁻¹ = inv(M)
201201
N⁻¹ = inv(N)
202202
(x, y, stats) = trimr(A, b, c, M=M⁻¹, N=N⁻¹)
203+
K = [M A; A' -N]
204+
r = [b; c] - K * [x; y]
205+
H = [M zeros(size(M, 1), size(N, 2)); zeros(size(N, 1), size(M, 2)) N]
206+
@test sqrt(dot(r, inv(H) * r)) / sqrt(dot([b; c], inv(H) * [b; c])) trimr_tol
203207
end
204208

205209
for transpose (false, true)

test/test_warm_start.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ function test_warm_start(FC)
1313
z0 = -2 * ones(FC, n)
1414
d = -10 * ones(FC, n)
1515

16+
# For relevant bipartite methods, it's also important to test asymmetric sizes
17+
A3x2, b3, c2, M3x3, N2x2 = small_sqd(false; FC)
18+
1619
# BILQR
1720
@testset "bilqr" begin
1821
x, y, stats = bilqr(A, b, c, x0, y0)
@@ -51,6 +54,14 @@ function test_warm_start(FC)
5154
resid = norm(s) / norm(c)
5255
@test(resid tol)
5356

57+
x30, y20, _ = trilqr(A3x2, b3, c2)
58+
x3, y2, stats = trilqr(A3x2, b3, c2, x30, y20)
59+
@test_broken x3 x30 atol=1e-12
60+
@test y2 y20 atol=1e-12
61+
@test_broken stats.niter <= 1
62+
@test_throws "x0 should have size $(length(x30))" trilqr(A3x2, b3, c2, [1.0], y20)
63+
@test_throws "y0 should have size $(length(y20))" trilqr(A3x2, b3, c2, x30, [1.0])
64+
5465
workspace = TrilqrWorkspace(A, b)
5566
krylov_solve!(workspace, A, b, c, x0, y0)
5667
r = b - A * workspace.x
@@ -76,6 +87,13 @@ function test_warm_start(FC)
7687
resid = norm(r) / norm([b; b])
7788
@test(resid tol)
7889

90+
x30, y20, _ = tricg(A3x2, b3, c2)
91+
x3, y2, stats = tricg(A3x2, b3, c2, x30, y20)
92+
@test x3 x30 atol=1e-12
93+
@test y2 y20 atol=1e-12
94+
@test stats.niter <= 1
95+
@test_throws "x0 should have size $(length(x30))" tricg(A3x2, b3, c2, [1.0], y20)
96+
@test_throws "y0 should have size $(length(y20))" tricg(A3x2, b3, c2, x30, [1.0])
7997
workspace = TricgWorkspace(A, b)
8098
krylov_solve!(workspace, A, b, b, x0, y0)
8199
r = [b - workspace.x - A * workspace.y; b - A' * workspace.x + workspace.y]
@@ -97,6 +115,13 @@ function test_warm_start(FC)
97115
resid = norm(r) / norm([b; b])
98116
@test(resid tol)
99117

118+
x30, y20, _ = trimr(A3x2, b3, c2)
119+
x3, y2, stats = trimr(A3x2, b3, c2, x30, y20)
120+
@test x3 x30 atol=1e-12
121+
@test y2 y20 atol=1e-12
122+
@test stats.niter <= 1
123+
@test_throws "x0 should have size $(length(x30))" trimr(A3x2, b3, c2, [1.0], y20)
124+
@test_throws "y0 should have size $(length(y20))" trimr(A3x2, b3, c2, x30, [1.0])
100125
workspace = TrimrWorkspace(A, b)
101126
krylov_solve!(workspace, A, b, b, x0, y0)
102127
r = [b - workspace.x - A * workspace.y; b - A' * workspace.x + workspace.y]
@@ -118,6 +143,11 @@ function test_warm_start(FC)
118143
resid = norm(r) / norm([b; b])
119144
@test(resid tol)
120145

146+
x30, y20, _ = gpmr(A3x2, A3x2', b3, c2)
147+
x3, y2, stats = gpmr(A3x2, A3x2', b3, c2, x30, y20)
148+
@test stats.niter <= 1
149+
@test_throws "x0 should have size $(length(x30))" gpmr(A3x2, A3x2', b3, c2, [1.0], y20)
150+
@test_throws "y0 should have size $(length(y20))" gpmr(A3x2, A3x2', b3, c2, x30, [1.0])
121151
workspace = GpmrWorkspace(A, b)
122152
krylov_solve!(workspace, A, A', b, b, x0, y0)
123153
r = [b - workspace.x - A * workspace.y; b - A' * workspace.x - workspace.y]

0 commit comments

Comments
 (0)