Skip to content

Commit cf7839a

Browse files
committed
LQ for TestSuite
1 parent 61b2efa commit cf7839a

File tree

4 files changed

+189
-10
lines changed

4 files changed

+189
-10
lines changed

test/lq.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,30 @@ using TestExtras
44
using StableRNGs
55
using LinearAlgebra: diag, I, Diagonal
66
using MatrixAlgebraKit: LQViaTransposedQR, LAPACK_HouseholderQR
7+
using CUDA, AMDGPU
78

89
BLASFloats = (Float32, Float64, ComplexF32, ComplexF64)
910
GenericFloats = (Float16, BigFloat, Complex{BigFloat})
1011

12+
m = 54
13+
for T in BLASFloats, n in (37, m, 63)
14+
TestSuite.seed_rng!(123)
15+
TestSuite.test_lq(T, (m, n); test_pivoted = false)
16+
if CUDA.functional()
17+
TestSuite.test_lq(CuMatrix{T}, (m, n); test_pivoted = false, test_blocksize = false)
18+
TestSuite.test_lq(Diagonal{T, CuVector{T}}, m; test_pivoted = false, test_blocksize = false)
19+
end
20+
if AMDGPU.functional()
21+
TestSuite.test_lq(ROCMatrix{T}, (m, n); test_pivoted = false, test_blocksize = false)
22+
TestSuite.test_lq(Diagonal{T, ROCVector{T}}, m; test_pivoted = false, test_blocksize = false)
23+
end
24+
end
25+
for T in (BLASFloats..., GenericFloats...)
26+
AT = Diagonal{T, Vector{T}}
27+
TestSuite.test_lq(AT, m; test_pivoted = false, test_blocksize = false)
28+
end
29+
30+
#=
1131
@testset "lq_compact! for T = $T" for T in BLASFloats
1232
rng = StableRNG(123)
1333
m = 54
@@ -253,3 +273,4 @@ end
253273
@test N isa AbstractMatrix{T} && size(N) == (0, m)
254274
end
255275
end
276+
=#

test/testsuite/TestSuite.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module TestSuite
1111
using Test, TestExtras
1212
using MatrixAlgebraKit
1313
using MatrixAlgebraKit: diagview
14-
using LinearAlgebra: Diagonal, norm, istriu
14+
using LinearAlgebra: Diagonal, norm, istriu, istril
1515
using Random, StableRNGs
1616
using AMDGPU, CUDA
1717

@@ -55,11 +55,15 @@ end
5555
isleftnull(N, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
5656
isapprox(norm(A' * N), 0; atol = max(atol, norm(A) * rtol))
5757

58+
isrightnull(Nᴴ, A; atol::Real = 0, rtol::Real = precision(eltype(A))) =
59+
isapprox(norm(A * Nᴴ'), 0; atol = max(atol, norm(A) * rtol))
60+
5861
# TODO: actually make this a test
5962
macro testinferred(ex)
6063
return esc(:(@inferred $ex))
6164
end
6265

6366
include("qr.jl")
67+
include("lq.jl")
6468

6569
end

test/testsuite/lq.jl

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
function test_lq(T::Type, sz; kwargs...)
2+
summary_str = testargs_summary(T, sz)
3+
return @testset "lq $summary_str" begin
4+
test_lq_compact(T, sz; kwargs...)
5+
test_lq_full(T, sz; kwargs...)
6+
test_lq_null(T, sz; kwargs...)
7+
end
8+
end
9+
10+
function test_lq_compact(
11+
T::Type, sz;
12+
test_positive = true, test_pivoted = true, test_blocksize = true,
13+
atol::Real = 0, rtol::Real = precision(T),
14+
kwargs...
15+
)
16+
summary_str = testargs_summary(T, sz)
17+
return @testset "lq_compact! $summary_str" begin
18+
A = instantiate_matrix(T, sz)
19+
Ac = deepcopy(A)
20+
21+
# does the elementary functionality work
22+
L, Q = @testinferred lq_compact(A)
23+
@test L * Q A
24+
@test isisometric(Q; side = :right, atol, rtol)
25+
@test istril(L)
26+
@test A == Ac
27+
28+
# can I pass in outputs?
29+
L2, Q2 = @testinferred lq_compact!(deepcopy(A), (L, Q))
30+
@test L2 * Q2 A
31+
@test isisometric(Q2; side = :right, atol, rtol)
32+
@test istril(L2)
33+
34+
# do we support `positive = true`?
35+
if test_positive
36+
Lpos, Qpos = @testinferred lq_compact(A; positive = true)
37+
@test Lpos * Qpos A
38+
@test isisometric(Qpos; side = :right, atol, rtol)
39+
@test istril(Lpos)
40+
@test has_positive_diagonal(Lpos)
41+
else
42+
@test_throws Exception lq_compact(A; positive = true)
43+
end
44+
45+
# do we support `pivoted = true`?
46+
if test_pivoted
47+
Lpiv, Qpiv = @testinferred lq_compact(A; pivoted = true)
48+
@test Lpiv * Qpiv A
49+
@test isisometric(Qpos; side = :right, atol, rtol)
50+
else
51+
@test_throws Exception lq_compact(A; pivoted = true)
52+
end
53+
54+
# do we support `blocksize = Int`?
55+
if test_blocksize
56+
Lblocked, Qblocked = @testinferred lq_compact(A; blocksize = 2)
57+
@test Lblocked * Qblocked A
58+
@test isisometric(Qblocked; side = :right, atol, rtol)
59+
else
60+
@test_throws Exception lq_compact(A; blocksize = 2)
61+
end
62+
end
63+
end
64+
65+
function test_lq_full(
66+
T::Type, sz;
67+
test_positive = true, test_pivoted = true, test_blocksize = true,
68+
atol::Real = 0, rtol::Real = precision(T),
69+
kwargs...
70+
)
71+
summary_str = testargs_summary(T, sz)
72+
return @testset "lq_full! $summary_str" begin
73+
A = instantiate_matrix(T, sz)
74+
Ac = deepcopy(A)
75+
76+
# does the elementary functionality work
77+
L, Q = @testinferred lq_full(A)
78+
@test L * Q A
79+
@test isunitary(Q; atol, rtol)
80+
@test istril(L)
81+
@test A == Ac
82+
83+
# can I pass in outputs?
84+
L2, Q2 = @testinferred lq_full!(deepcopy(A), (L, Q))
85+
@test L2 * Q2 A
86+
@test isunitary(Q2; atol, rtol)
87+
@test istril(L2)
88+
89+
# do we support `positive = true`?
90+
if test_positive
91+
Lpos, Qpos = @testinferred lq_full(A; positive = true)
92+
@test Lpos * Qpos A
93+
@test isunitary(Qpos; atol, rtol)
94+
@test istril(Lpos)
95+
@test has_positive_diagonal(Lpos)
96+
else
97+
@test_throws Exception lq_full(A; positive = true)
98+
end
99+
100+
# do we support `pivoted = true`?
101+
if test_pivoted
102+
Lpiv, Qpiv = @testinferred lq_full(A; pivoted = true)
103+
@test Lpiv * Qpiv A
104+
@test isunitary(Qpos; atol, rtol)
105+
else
106+
@test_throws Exception lq_full(A; pivoted = true)
107+
end
108+
109+
# do we support `blocksize = Int`?
110+
if test_blocksize
111+
Lblocked, Qblocked = @testinferred lq_full(A; blocksize = 2)
112+
@test Lblocked * Qblocked A
113+
@test isunitary(Qblocked; atol, rtol)
114+
else
115+
@test_throws Exception lq_full(A; blocksize = 2)
116+
end
117+
end
118+
end
119+
120+
function test_lq_null(
121+
T::Type, sz;
122+
test_pivoted = true, test_blocksize = true,
123+
atol::Real = 0, rtol::Real = precision(T),
124+
kwargs...
125+
)
126+
summary_str = testargs_summary(T, sz)
127+
return @testset "lq_null! $summary_str" begin
128+
A = instantiate_matrix(T, sz)
129+
Ac = deepcopy(A)
130+
131+
# does the elementary functionality work
132+
Nᴴ = @testinferred lq_null(A)
133+
@test isrightnull(Nᴴ, A; atol, rtol)
134+
@test isisometric(Nᴴ; side = :right, atol, rtol)
135+
@test A == Ac
136+
137+
# can I pass in outputs?
138+
Nᴴ2 = @testinferred lq_null!(deepcopy(A), Nᴴ)
139+
@test isrightnull(Nᴴ2, A; atol, rtol)
140+
@test isisometric(Nᴴ2; side = :right, atol, rtol)
141+
142+
# do we support `pivoted = true`?
143+
if test_pivoted
144+
Nᴴpiv = @testinferred lq_null(A; pivoted = true)
145+
@test isrightnull(Nᴴpiv, A; atol, rtol)
146+
@test isisometric(Nᴴpiv; side = :right, atol, rtol)
147+
#else # DISABLE for now as lq_null does support pivoting...
148+
# @test_throws Exception lq_null(A; pivoted = true)
149+
end
150+
151+
# do we support `blocksize = Int`?
152+
if test_blocksize
153+
Nᴴblocked = @testinferred lq_null(A; blocksize = 2)
154+
@test isrightnull(Nᴴblocked, A; atol, rtol)
155+
@test isisometric(Nᴴblocked; side = :right, atol, rtol)
156+
else
157+
@test_throws Exception lq_null(A; blocksize = 2)
158+
end
159+
end
160+
end

test/testsuite/qr.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
function test_qr(T::Type, sz; kwargs...)
22
summary_str = testargs_summary(T, sz)
33
return @testset "qr $summary_str" begin
4-
if T <: Union{CuArray, ROCArray}
5-
test_qr_compact(T, sz; pivoted = false, kwargs...)
6-
test_qr_full(T, sz; pivoted = false, kwargs...)
7-
test_qr_null(T, sz; pivoted = false, kwargs...)
8-
else
9-
test_qr_compact(T, sz; kwargs...)
10-
test_qr_full(T, sz; kwargs...)
11-
test_qr_null(T, sz; kwargs...)
12-
end
4+
test_qr_compact(T, sz; kwargs...)
5+
test_qr_full(T, sz; kwargs...)
6+
test_qr_null(T, sz; kwargs...)
137
end
148
end
159

0 commit comments

Comments
 (0)