Skip to content

Commit d3d01b8

Browse files
committed
Comments
1 parent 04f6925 commit d3d01b8

File tree

5 files changed

+110
-7
lines changed

5 files changed

+110
-7
lines changed

src/implementations/lq.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ function _lapack_lq!(
153153
computeL = length(L) > 0
154154
inplaceQ = Q === A
155155

156-
if pivoted
157-
throw(ArgumentError("LAPACK does not provide an implementation for a pivoted LQ decomposition"))
156+
if pivoted && (blocksize > 1)
157+
throw(ArgumentError("LAPACK does not provide a blocked implementation for a pivoted LQ decomposition"))
158158
end
159159
if inplaceQ && (computeL || positive || blocksize > 1 || n < m)
160160
throw(ArgumentError("inplace Q only supported if matrix is wide (`m <= n`), L is not required, and using the unblocked algorithm (`blocksize=1`) with `positive=false`"))

test/lq.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ for T in BLASFloats, n in (37, m, 63)
2626
n == m && TestSuite.test_lq(Diagonal{T, ROCVector{T}}, m; test_pivoted = false, test_blocksize = false)
2727
end
2828
else
29-
TestSuite.test_lq(T, (m, n); test_pivoted = false)
29+
TestSuite.test_lq(T, (m, n))
3030
end
3131
end
3232
if !is_buildkite

test/qr.jl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,41 @@ for T in BLASFloats, n in (37, m, 63)
1717
TestSuite.seed_rng!(123)
1818
if is_buildkite
1919
if CUDA.functional()
20+
CUDA_QR_ALGS = (CUSOLVER_HouseholderQR(; positive=false), CUSOLVER_HouseholderQR(; positive=true))
2021
TestSuite.test_qr(CuMatrix{T}, (m, n); test_pivoted = false, test_blocksize = false)
21-
n == m && TestSuite.test_qr(Diagonal{T, CuVector{T}}, m; test_pivoted = false, test_blocksize = false)
22+
TestSuite.test_qr_algs(CuMatrix{T}, (m, n), CUDA_QR_ALGS; test_blocksize = false)
23+
if n == m
24+
TestSuite.test_qr(Diagonal{T, CuVector{T}}, m; test_pivoted = false, test_blocksize = false)
25+
TestSuite.test_qr_algs(Diagonal{T, CuVector{T}}, m, (DiagonalAlgorithm(),); test_blocksize = false)
26+
end
2227
end
2328
if AMDGPU.functional()
29+
ROC_QR_ALGS = (ROCSOLVER_HouseholderQR(; positive=false), ROCSOLVER_HouseholderQR(; positive=true))
2430
TestSuite.test_qr(ROCMatrix{T}, (m, n); test_pivoted = false, test_blocksize = false)
25-
n == m && TestSuite.test_qr(Diagonal{T, ROCVector{T}}, m; test_pivoted = false, test_blocksize = false)
31+
TestSuite.test_qr_algs(ROCMatrix{T}, (m, n), ROC_QR_ALGS; test_blocksize = false)
32+
if n == m
33+
TestSuite.test_qr(Diagonal{T, ROCVector{T}}, m; test_pivoted = false, test_blocksize = false)
34+
TestSuite.test_qr_algs(Diagonal{T, ROCVector{T}}, m, (DiagonalAlgorithm(),); test_blocksize = false)
35+
end
2636
end
2737
else
2838
TestSuite.test_qr(T, (m, n))
39+
LAPACK_QR_ALGS = (LAPACK_HouseholderQR(; positive=false, pivoted=false, blocksize=1),
40+
LAPACK_HouseholderQR(; positive=false, pivoted=false, blocksize=2),
41+
LAPACK_HouseholderQR(; positive=false, pivoted=true, blocksize=1),
42+
#LAPACK_HouseholderQR(; positive=false, pivoted=true, blocksize=2), # not supported
43+
LAPACK_HouseholderQR(; positive=true, pivoted=false, blocksize=1),
44+
LAPACK_HouseholderQR(; positive=true, pivoted=false, blocksize=2),
45+
LAPACK_HouseholderQR(; positive=true, pivoted=true, blocksize=1),
46+
#LAPACK_HouseholderQR(; positive=true, pivoted=true, blocksize=2), # not supported
47+
)
48+
TestSuite.test_qr_algs(T, (m, n), LAPACK_QR_ALGS)
2949
end
3050
end
3151
if !is_buildkite
3252
for T in (BLASFloats..., GenericFloats...)
3353
AT = Diagonal{T, Vector{T}}
3454
TestSuite.test_qr(AT, m; test_pivoted = false, test_blocksize = false)
55+
TestSuite.test_qr_algs(AT, m, (DiagonalAlgorithm(),); test_blocksize = false)
3556
end
3657
end

test/testsuite/lq.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ function test_lq_null(
146146
Nᴴpiv = @testinferred lq_null(A; pivoted = true)
147147
@test isrightnull(Nᴴpiv, A; atol, rtol)
148148
@test isisometric(Nᴴpiv; side = :right, atol, rtol)
149-
#else # DISABLE for now as lq_null does support pivoting...
150-
# @test_throws Exception lq_null(A; pivoted = true)
149+
else
150+
@test_throws Exception lq_null(A; pivoted = true)
151151
end
152152

153153
# do we support `blocksize = Int`?

test/testsuite/qr.jl

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ function test_qr(T::Type, sz; kwargs...)
99
end
1010
end
1111

12+
function test_qr_algs(T::Type, sz, algs; kwargs...)
13+
summary_str = testargs_summary(T, sz)
14+
return @testset "qr algorithms $summary_str" begin
15+
test_qr_compact_algs(T, sz, algs; kwargs...)
16+
test_qr_full_algs(T, sz, algs; kwargs...)
17+
test_qr_null_algs(T, sz, algs; kwargs...)
18+
end
19+
end
20+
21+
# test correctness and interface for QR regardless of algorithm
1222
function test_qr_compact(
1323
T::Type, sz;
1424
test_positive = true, test_pivoted = true, test_blocksize = true,
@@ -64,6 +74,31 @@ function test_qr_compact(
6474
end
6575
end
6676

77+
# test various algorithms
78+
function test_qr_compact_algs(
79+
T::Type, sz, algs;
80+
test_blocksize = true,
81+
atol::Real = 0, rtol::Real = precision(T),
82+
kwargs...
83+
)
84+
summary_str = testargs_summary(T, sz)
85+
return @testset "qr_compact! algorithm $alg $summary_str" for alg in algs
86+
A = instantiate_matrix(T, sz)
87+
Ac = deepcopy(A)
88+
89+
# does the elementary functionality work
90+
Q, R = @testinferred qr_compact(A; alg)
91+
@test Q * R A
92+
@test isisometric(Q; atol, rtol)
93+
@test A == Ac
94+
95+
# can I pass in outputs?
96+
Q2, R2 = @testinferred qr_compact!(Ac, (Q, R); alg)
97+
@test Q2 * R2 A
98+
@test isisometric(Q2; atol, rtol)
99+
end
100+
end
101+
67102
function test_qr_full(
68103
T::Type, sz;
69104
test_positive = true, test_pivoted = true, test_blocksize = true,
@@ -119,6 +154,30 @@ function test_qr_full(
119154
end
120155
end
121156

157+
function test_qr_full_algs(
158+
T::Type, sz, algs;
159+
test_blocksize = true,
160+
atol::Real = 0, rtol::Real = precision(T),
161+
kwargs...
162+
)
163+
summary_str = testargs_summary(T, sz)
164+
return @testset "qr_full! algorithm $alg $summary_str" for alg in algs
165+
A = instantiate_matrix(T, sz)
166+
Ac = deepcopy(A)
167+
168+
# does the elementary functionality work
169+
Q, R = @testinferred qr_full(A; alg)
170+
@test Q * R A
171+
@test isunitary(Q; atol, rtol)
172+
@test A == Ac
173+
174+
# can I pass in outputs?
175+
Q2, R2 = @testinferred qr_full!(Ac, (Q, R); alg)
176+
@test Q2 * R2 A
177+
@test isunitary(Q2; atol, rtol)
178+
end
179+
end
180+
122181
function test_qr_null(
123182
T::Type, sz;
124183
test_pivoted = true, test_blocksize = true,
@@ -160,3 +219,26 @@ function test_qr_null(
160219
end
161220
end
162221
end
222+
223+
function test_qr_null_algs(
224+
T::Type, sz, algs;
225+
atol::Real = 0, rtol::Real = precision(T),
226+
kwargs...
227+
)
228+
summary_str = testargs_summary(T, sz)
229+
return @testset "qr_null! algorithm $alg $summary_str" for alg in algs
230+
A = instantiate_matrix(T, sz)
231+
Ac = deepcopy(A)
232+
233+
# does the elementary functionality work
234+
N = @testinferred qr_null(A; alg)
235+
@test isleftnull(N, A; atol, rtol)
236+
@test isisometric(N; atol, rtol)
237+
@test A == Ac
238+
239+
# can I pass in outputs?
240+
N2 = @testinferred qr_null!(Ac, N; alg)
241+
@test isleftnull(N2, A; atol, rtol)
242+
@test isisometric(N2; atol, rtol)
243+
end
244+
end

0 commit comments

Comments
 (0)