Skip to content

Commit 5a65804

Browse files
authored
Counter-attack TNRKit with increased coverage (#190)
* Comment out unused LAPACK wrappers for coverage * Restore gesvj and test it * No Jacobi for svd_full * Test algorithms for Schur too * Restore ungql * And ungqr * Kwargs for SVD * Formatter * Don't run Jacobi on 1.10
1 parent 6d52436 commit 5a65804

5 files changed

Lines changed: 90 additions & 24 deletions

File tree

src/yalapack.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ for (geqr, gelq, geqrf, gelqf, geqlf, gerqf, geqrt, gelqt, latsqr, laswlq, geqp3
9999
#! format: on
100100
@eval begin
101101
# Flexible QR / LQ
102-
function geqr!(A::AbstractMatrix{$elty})
102+
#=function geqr!(A::AbstractMatrix{$elty})
103103
require_one_based_indexing(A)
104104
chkstride1(A)
105105
m, n = size(A)
@@ -162,7 +162,7 @@ for (geqr, gelq, geqrf, gelqf, geqlf, gerqf, geqrt, gelqt, latsqr, laswlq, geqp3
162162
end
163163
end
164164
return A, t
165-
end
165+
end=#
166166

167167
# Classic QR / LQ / QL / RQ
168168
function geqrf!(
@@ -231,7 +231,7 @@ for (geqr, gelq, geqrf, gelqf, geqlf, gerqf, geqrt, gelqt, latsqr, laswlq, geqp3
231231
end
232232
return A, tau
233233
end
234-
function geqlf!(
234+
#=function geqlf!(
235235
A::AbstractMatrix{$elty},
236236
tau::AbstractVector{$elty} = similar(A, $elty, min(size(A)...))
237237
)
@@ -296,7 +296,7 @@ for (geqr, gelq, geqrf, gelqf, geqlf, gerqf, geqrt, gelqt, latsqr, laswlq, geqp3
296296
end
297297
end
298298
return A, tau
299-
end
299+
end=#
300300

301301
# QR and LQ with block reflectors
302302
#! format: off
@@ -441,7 +441,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
441441
#! format: on
442442
@eval begin
443443
# multiply with Q factor of flexible QR / LQ
444-
function gemqr!(
444+
#=function gemqr!(
445445
side::AbstractChar, trans::AbstractChar, A::AbstractMatrix{$elty},
446446
T::AbstractVector{$elty}, C::AbstractVecOrMat{$elty}
447447
)
@@ -544,7 +544,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
544544
end
545545
end
546546
return C
547-
end
547+
end=#
548548

549549
# Build Q factor of classic QR / LQ / QL / RQ in the space of `A`
550550
function ungqr!(A::AbstractMatrix{$elty}, tau::AbstractVector{$elty})
@@ -615,7 +615,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
615615
end
616616
return A
617617
end
618-
function ungql!(A::AbstractMatrix{$elty}, tau::AbstractVector{$elty})
618+
#=function ungql!(A::AbstractMatrix{$elty}, tau::AbstractVector{$elty})
619619
require_one_based_indexing(A, tau)
620620
chkstride1(A, tau)
621621
m, n = size(A)
@@ -682,7 +682,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
682682
end
683683
end
684684
return A
685-
end
685+
end=#
686686

687687
# multiply with Q factor of classic QR / LQ / QL / RQ
688688
function unmqr!(
@@ -781,7 +781,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
781781
end
782782
return C
783783
end
784-
function unmql!(
784+
#=function unmql!(
785785
side::AbstractChar, trans::AbstractChar,
786786
A::AbstractMatrix{$elty}, tau::AbstractVector{$elty},
787787
C::AbstractVecOrMat{$elty}
@@ -876,7 +876,7 @@ for (gemqr, gemlq, ungqr, unglq, ungql, ungrq, unmqr, unmlq, unmql, unmrq, gemqr
876876
end
877877
end
878878
return C
879-
end
879+
end=#
880880

881881
# Multiply with blocked Q factor from QR / LQ
882882
function gemqrt!(

test/schur.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ for T in (BLASFloats..., GenericFloats...)
2727
end
2828
if !is_buildkite
2929
TestSuite.test_schur(T, (m, m))
30+
if T BLASFloats
31+
LAPACK_SCHUR_ALGS = (LAPACK_Simple(), LAPACK_Expert())
32+
TestSuite.test_schur_algs(T, (m, m), LAPACK_SCHUR_ALGS)
33+
end
3034
#AT = Diagonal{T, Vector{T}}
3135
#TestSuite.test_schur(AT, m) # not supported yet
3236
end

test/svd.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ for T in (BLASFloats..., GenericFloats...), m in (0, 54), n in (0, 37, m, 63)
5555
)
5656
TestSuite.test_svd(T, (m, n))
5757
TestSuite.test_svd_algs(T, (m, n), LAPACK_SVD_ALGS)
58+
@static if VERSION > v"1.11-" # Jacobi broken on 1.10
59+
m n && TestSuite.test_svd_algs(T, (m, n), (LAPACK_Jacobi(),); test_full = false, test_vals = false)
60+
end
5861
elseif T GenericFloats
5962
TestSuite.test_svd(T, (m, n))
6063
TestSuite.test_svd_algs(T, (m, n), (GLA_QRIteration(),))

test/testsuite/decompositions/schur.jl

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

12+
function test_schur_algs(T::Type, sz, algs; kwargs...)
13+
summary_str = testargs_summary(T, sz)
14+
return @testset "schur algorithms $summary_str" begin
15+
test_schur_full_algs(T, sz, algs; kwargs...)
16+
test_schur_vals_algs(T, sz, algs; kwargs...)
17+
end
18+
end
19+
1220
function test_schur_full(
1321
T::Type, sz;
1422
atol::Real = 0, rtol::Real = precision(T),
@@ -34,6 +42,31 @@ function test_schur_full(
3442
end
3543
end
3644

45+
function test_schur_full_algs(
46+
T::Type, sz, algs;
47+
atol::Real = 0, rtol::Real = precision(T),
48+
kwargs...
49+
)
50+
summary_str = testargs_summary(T, sz)
51+
return @testset "schur_full! algorithm $alg $summary_str" for alg in algs
52+
A = instantiate_matrix(T, sz)
53+
Ac = deepcopy(A)
54+
Tc = isa(A, Diagonal) ? eltype(T) : complex(eltype(T))
55+
56+
TA, Z, vals = @testinferred schur_full(A; alg)
57+
@test eltype(TA) == eltype(Z) == eltype(T)
58+
@test eltype(vals) == Tc
59+
@test isisometric(Z)
60+
@test A * Z Z * TA
61+
62+
TA2, Z2, vals2 = @testinferred schur_full!(Ac, (TA, Z, vals); alg)
63+
@test TA2 === TA
64+
@test Z2 === Z
65+
@test vals2 === vals
66+
@test A * Z Z * TA
67+
end
68+
end
69+
3770
function test_schur_vals(
3871
T::Type, sz;
3972
atol::Real = 0, rtol::Real = precision(T),
@@ -55,3 +88,25 @@ function test_schur_vals(
5588
@test valsc eig_vals(A)
5689
end
5790
end
91+
92+
function test_schur_vals_algs(
93+
T::Type, sz, algs;
94+
atol::Real = 0, rtol::Real = precision(T),
95+
kwargs...
96+
)
97+
summary_str = testargs_summary(T, sz)
98+
return @testset "schur_vals! algorithm $alg $summary_str" for alg in algs
99+
A = instantiate_matrix(T, sz)
100+
Ac = deepcopy(A)
101+
Tc = isa(A, Diagonal) ? eltype(T) : complex(eltype(T))
102+
103+
valsc = @testinferred schur_vals(A; alg)
104+
@test eltype(valsc) == Tc
105+
@test valsc eig_vals(A)
106+
107+
valsc = similar(A, Tc, size(A, 1))
108+
valsc = @testinferred schur_vals!(Ac, valsc; alg)
109+
@test eltype(valsc) == Tc
110+
@test valsc eig_vals(A)
111+
end
112+
end

test/testsuite/decompositions/svd.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ using TestExtras
22
using GenericLinearAlgebra
33
using LinearAlgebra: opnorm
44

5-
function test_svd(T::Type, sz; kwargs...)
5+
function test_svd(T::Type, sz; test_compact::Bool = true, test_full::Bool = true, test_trunc::Bool = true, kwargs...)
66
summary_str = testargs_summary(T, sz)
77
return @testset "svd $summary_str" begin
8-
test_svd_compact(T, sz; kwargs...)
9-
test_svd_full(T, sz; kwargs...)
10-
test_svd_trunc(T, sz; kwargs...)
8+
test_compact && test_svd_compact(T, sz; kwargs...)
9+
test_full && test_svd_full(T, sz; kwargs...)
10+
test_trunc && test_svd_trunc(T, sz; kwargs...)
1111
end
1212
end
1313

14-
function test_svd_algs(T::Type, sz, algs; kwargs...)
14+
function test_svd_algs(T::Type, sz, algs; test_compact::Bool = true, test_full::Bool = true, test_trunc::Bool = true, kwargs...)
1515
summary_str = testargs_summary(T, sz)
1616
return @testset "svd algorithms $summary_str" begin
17-
test_svd_compact_algs(T, sz, algs; kwargs...)
18-
test_svd_full_algs(T, sz, algs; kwargs...)
19-
test_svd_trunc_algs(T, sz, algs; kwargs...)
17+
test_compact && test_svd_compact_algs(T, sz, algs; kwargs...)
18+
test_full && test_svd_full_algs(T, sz, algs; kwargs...)
19+
test_trunc && test_svd_trunc_algs(T, sz, algs; kwargs...)
2020
end
2121
end
2222

2323
function test_svd_compact(
2424
T::Type, sz;
2525
atol::Real = 0, rtol::Real = precision(eltype(T)),
26-
kwargs...
26+
test_vals::Bool = true, kwargs...
2727
)
2828
summary_str = testargs_summary(T, sz)
2929
return @testset "svd_compact! $summary_str" begin
@@ -47,15 +47,17 @@ function test_svd_compact(
4747
@test isisometric(V2ᴴ; side = :right)
4848
@test isposdef(S2)
4949

50-
Sd = @testinferred svd_vals(A)
51-
@test S Diagonal(Sd)
50+
if test_vals
51+
Sd = @testinferred svd_vals(A)
52+
@test S Diagonal(Sd)
53+
end
5254
end
5355
end
5456

5557
function test_svd_compact_algs(
5658
T::Type, sz, algs;
5759
atol::Real = 0, rtol::Real = precision(eltype(T)),
58-
kwargs...
60+
test_vals::Bool = true, kwargs...
5961
)
6062
summary_str = testargs_summary(T, sz)
6163
return @testset "svd_compact! algorithm $alg $summary_str" for alg in algs
@@ -78,8 +80,10 @@ function test_svd_compact_algs(
7880
@test isisometric(V2ᴴ; side = :right)
7981
@test isposdef(S2)
8082

81-
Sd = @testinferred svd_vals(A; alg)
82-
@test S Diagonal(Sd)
83+
if test_vals
84+
Sd = @testinferred svd_vals(A; alg)
85+
@test S Diagonal(Sd)
86+
end
8387
end
8488
end
8589

0 commit comments

Comments
 (0)