Skip to content

Commit 9b47a36

Browse files
lkdvoskshyatt
authored andcommitted
add QR test suite
1 parent 6dc2081 commit 9b47a36

2 files changed

Lines changed: 156 additions & 0 deletions

File tree

test/testsuite/TestSuite.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ macro testinferred(ex)
4646
return esc(:(@inferred $ex))
4747
end
4848

49+
include("qr.jl")
50+
4951
end

test/testsuite/qr.jl

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
function test_qr(::Type{T}, sz; kwargs...) where {T}
2+
summary_str = testargs_summary(T, sz)
3+
return @testset "qr $summary_str" begin
4+
test_qr_compact(T, sz; kwargs...)
5+
test_qr_full(T, sz; kwargs...)
6+
test_qr_null(T, sz; kwargs...)
7+
end
8+
end
9+
10+
function test_qr_compact(
11+
::Type{T}, sz;
12+
test_positive = true, test_pivoted = true, test_blocksize = true, kwargs...
13+
) where {T <: Number}
14+
summary_str = testargs_summary(T, sz)
15+
return @testset "qr_compact! $summary_str" begin
16+
A = instantiate_matrix(T, sz)
17+
Ac = deepcopy(A)
18+
19+
# does the elementary functionality work
20+
Q, R = @testinferred qr_compact(A)
21+
@test Q * R A
22+
@test isisometric(Q)
23+
@test istriu(R)
24+
@test A == Ac
25+
26+
# can I pass in outputs?
27+
Q2, R2 = @testinferred qr_compact!(deepcopy(A), (Q, R))
28+
@test Q2 * R2 A
29+
@test isisometric(Q2)
30+
@test istriu(R2)
31+
32+
# do we support `positive = true`?
33+
if test_positive
34+
Qpos, Rpos = @testinferred qr_compact(A; positive = true)
35+
@test Qpos * Rpos A
36+
@test isisometric(Qpos)
37+
@test istriu(Rpos)
38+
@test has_positive_diagonal(Rpos)
39+
else
40+
@test_throws ArgumentError qr_compact(A; positive = true)
41+
end
42+
43+
# do we support `pivoted = true`?
44+
if test_pivoted
45+
Qpiv, Rpiv = @testinferred qr_compact(A; pivoted = true)
46+
@test Qpiv * Rpiv A
47+
@test isisometric(Qpos)
48+
else
49+
@test_throws ArgumentError qr_compact(A; pivoted = true)
50+
end
51+
52+
# do we support `blocksize = Int`?
53+
if test_blocksize
54+
Qblocked, Rblocked = @testinferred qr_compact(A; blocksize = 2)
55+
@test Qblocked * Rblocked A
56+
@test isisometric(Qblocked)
57+
else
58+
@test_throws ArgumentError qr_compact(A; blocksize = 2)
59+
end
60+
end
61+
end
62+
63+
function test_qr_full(
64+
::Type{T}, sz;
65+
test_positive = true, test_pivoted = true, test_blocksize = true, kwargs...
66+
) where {T <: Number}
67+
summary_str = testargs_summary(T, sz)
68+
return @testset "qr_full! $summary_str" begin
69+
A = instantiate_matrix(T, sz)
70+
Ac = deepcopy(A)
71+
72+
# does the elementary functionality work
73+
Q, R = @testinferred qr_full(A)
74+
@test Q * R A
75+
@test isunitary(Q)
76+
@test istriu(R)
77+
@test A == Ac
78+
79+
# can I pass in outputs?
80+
Q2, R2 = @testinferred qr_full!(deepcopy(A), (Q, R))
81+
@test Q2 * R2 A
82+
@test isunitary(Q2)
83+
@test istriu(R2)
84+
85+
# do we support `positive = true`?
86+
if test_positive
87+
Qpos, Rpos = @testinferred qr_full(A; positive = true)
88+
@test Qpos * Rpos A
89+
@test isunitary(Qpos)
90+
@test istriu(Rpos)
91+
@test has_positive_diagonal(Rpos)
92+
else
93+
@test_throws ArgumentError qr_full(A; positive = true)
94+
end
95+
96+
# do we support `pivoted = true`?
97+
if test_pivoted
98+
Qpiv, Rpiv = @testinferred qr_full(A; pivoted = true)
99+
@test Qpiv * Rpiv A
100+
@test isunitary(Qpos)
101+
else
102+
@test_throws ArgumentError qr_full(A; pivoted = true)
103+
end
104+
105+
# do we support `blocksize = Int`?
106+
if test_blocksize
107+
Qblocked, Rblocked = @testinferred qr_full(A; blocksize = 2)
108+
@test Qblocked * Rblocked A
109+
@test isunitary(Qblocked)
110+
else
111+
@test_throws ArgumentError qr_full(A; blocksize = 2)
112+
end
113+
end
114+
end
115+
116+
function test_qr_null(
117+
::Type{T}, sz;
118+
test_pivoted = true, test_blocksize = true, kwargs...
119+
) where {T <: Number}
120+
summary_str = testargs_summary(T, sz)
121+
return @testset "qr_null! $summary_str" begin
122+
A = instantiate_matrix(T, sz)
123+
Ac = deepcopy(A)
124+
125+
# does the elementary functionality work
126+
N = @testinferred qr_null(A)
127+
@test isleftnull(N, A)
128+
@test isisometric(N)
129+
@test A == Ac
130+
131+
# can I pass in outputs?
132+
N2 = @testinferred qr_null!(deepcopy(A), N)
133+
@test isleftnull(N2, A)
134+
@test isisometric(N2)
135+
136+
# do we support `pivoted = true`?
137+
if test_pivoted
138+
Npiv = @testinferred qr_null(A; pivoted = true)
139+
@test isleftnull(Npiv, A)
140+
@test isisometric(Npiv)
141+
else
142+
@test_throws ArgumentError qr_null(A; pivoted = true)
143+
end
144+
145+
# do we support `blocksize = Int`?
146+
if test_blocksize
147+
Nblocked = @testinferred qr_null(A; blocksize = 2)
148+
@test isleftnull(Nblocked, A)
149+
@test isisometric(Nblocked)
150+
else
151+
@test_throws ArgumentError qr_null(A; blocksize = 2)
152+
end
153+
end
154+
end

0 commit comments

Comments
 (0)