Skip to content

Commit 342a1b6

Browse files
committed
update tests
1 parent 9eaa4a2 commit 342a1b6

File tree

2 files changed

+61
-87
lines changed

2 files changed

+61
-87
lines changed

test/chainrules.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,18 +541,18 @@ end
541541
)
542542
test_rrule(
543543
config, left_orth, A;
544-
fkwargs = (; kind = :qr), atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
544+
fkwargs = (; alg = :qr), atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
545545
)
546546
m >= n &&
547547
test_rrule(
548548
config, left_orth, A;
549-
fkwargs = (; kind = :polar), atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
549+
fkwargs = (; alg = :polar), atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
550550
)
551551

552-
ΔN = left_orth(A; kind = :qr)[1] * randn(rng, T, min(m, n), m - min(m, n))
552+
ΔN = left_orth(A; alg = :qr)[1] * randn(rng, T, min(m, n), m - min(m, n))
553553
test_rrule(
554554
config, left_null, A;
555-
fkwargs = (; kind = :qr), output_tangent = ΔN, atol = atol, rtol = rtol,
555+
fkwargs = (; alg = :qr), output_tangent = ΔN, atol = atol, rtol = rtol,
556556
rrule_f = rrule_via_ad, check_inferred = false
557557
)
558558

@@ -561,19 +561,19 @@ end
561561
atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
562562
)
563563
test_rrule(
564-
config, right_orth, A; fkwargs = (; kind = :lq),
564+
config, right_orth, A; fkwargs = (; alg = :lq),
565565
atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
566566
)
567567
m <= n &&
568568
test_rrule(
569-
config, right_orth, A; fkwargs = (; kind = :polar),
569+
config, right_orth, A; fkwargs = (; alg = :polar),
570570
atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
571571
)
572572

573-
ΔNᴴ = randn(rng, T, n - min(m, n), min(m, n)) * right_orth(A; kind = :lq)[2]
573+
ΔNᴴ = randn(rng, T, n - min(m, n), min(m, n)) * right_orth(A; alg = :lq)[2]
574574
test_rrule(
575575
config, right_null, A;
576-
fkwargs = (; kind = :lq), output_tangent = ΔNᴴ,
576+
fkwargs = (; alg = :lq), output_tangent = ΔNᴴ,
577577
atol = atol, rtol = rtol, rrule_f = rrule_via_ad, check_inferred = false
578578
)
579579
end

test/orthnull.jl

Lines changed: 53 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ using LinearAlgebra: LinearAlgebra, I
88
include("linearmap.jl")
99

1010
eltypes = (Float32, Float64, ComplexF32, ComplexF64)
11-
1211
@testset "left_orth and left_null for T = $T" for T in eltypes
1312
rng = StableRNG(123)
1413
m = 54
@@ -27,7 +26,7 @@ eltypes = (Float32, Float64, ComplexF32, ComplexF64)
2726
@test V * V' + N * N' I
2827

2928
M = LinearMap(A)
30-
VM, CM = @constinferred left_orth(M; kind = :svd)
29+
VM, CM = @constinferred left_orth(M; alg = :svd)
3130
@test parent(VM) * parent(CM) A
3231

3332
if m > n
@@ -43,25 +42,33 @@ eltypes = (Float32, Float64, ComplexF32, ComplexF64)
4342
@test isisometric(N)
4443
end
4544

46-
for alg_qr in ((; positive = true), (; positive = false), LAPACK_HouseholderQR())
47-
V, C = @constinferred left_orth(A; alg_qr)
48-
N = @constinferred left_null(A; alg_qr)
49-
@test V isa Matrix{T} && size(V) == (m, minmn)
50-
@test C isa Matrix{T} && size(C) == (minmn, n)
51-
@test N isa Matrix{T} && size(N) == (m, m - minmn)
52-
@test V * C A
53-
@test isisometric(V)
54-
@test LinearAlgebra.norm(A' * N) 0 atol = MatrixAlgebraKit.defaulttol(T)
55-
@test isisometric(N)
56-
@test V * V' + N * N' I
57-
end
45+
# passing a kind and some kwargs
46+
V, C = @constinferred left_orth(A; alg = :qr, alg_qr = (; positive = true))
47+
N = @constinferred left_null(A; alg = :qr, alg_qr = (; positive = true))
48+
@test V isa Matrix{T} && size(V) == (m, minmn)
49+
@test C isa Matrix{T} && size(C) == (minmn, n)
50+
@test N isa Matrix{T} && size(N) == (m, m - minmn)
51+
@test V * C A
52+
@test isisometric(V)
53+
@test LinearAlgebra.norm(A' * N) 0 atol = MatrixAlgebraKit.defaulttol(T)
54+
@test isisometric(N)
55+
@test V * V' + N * N' I
56+
57+
# passing an algorithm
58+
V, C = @constinferred left_orth(A; alg = LAPACK_HouseholderQR())
59+
N = @constinferred left_null(A; alg = :qr, alg_qr = (; positive = true))
60+
@test V isa Matrix{T} && size(V) == (m, minmn)
61+
@test C isa Matrix{T} && size(C) == (minmn, n)
62+
@test N isa Matrix{T} && size(N) == (m, m - minmn)
63+
@test V * C A
64+
@test isisometric(V)
65+
@test LinearAlgebra.norm(A' * N) 0 atol = MatrixAlgebraKit.defaulttol(T)
66+
@test isisometric(N)
67+
@test V * V' + N * N' I
5868

5969
Ac = similar(A)
6070
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C))
6171
N2 = @constinferred left_null!(copy!(Ac, A), N)
62-
@test V2 === V
63-
@test C2 === C
64-
@test N2 === N
6572
@test V2 * C2 A
6673
@test isisometric(V2)
6774
@test LinearAlgebra.norm(A' * N2) 0 atol = MatrixAlgebraKit.defaulttol(T)
@@ -71,9 +78,6 @@ eltypes = (Float32, Float64, ComplexF32, ComplexF64)
7178
atol = eps(real(T))
7279
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C); trunc = (; atol = atol))
7380
N2 = @constinferred left_null!(copy!(Ac, A), N; trunc = (; atol = atol))
74-
@test V2 !== V
75-
@test C2 !== C
76-
@test N2 !== C
7781
@test V2 * C2 A
7882
@test isisometric(V2)
7983
@test LinearAlgebra.norm(A' * N2) 0 atol = MatrixAlgebraKit.defaulttol(T)
@@ -87,59 +91,47 @@ eltypes = (Float32, Float64, ComplexF32, ComplexF64)
8791
)
8892
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C); trunc = trunc_orth)
8993
N2 = @constinferred left_null!(copy!(Ac, A), N; trunc = trunc_null)
90-
@test V2 !== V
91-
@test C2 !== C
92-
@test N2 !== C
9394
@test V2 * C2 A
9495
@test isisometric(V2)
9596
@test LinearAlgebra.norm(A' * N2) 0 atol = MatrixAlgebraKit.defaulttol(T)
9697
@test isisometric(N2)
9798
@test V2 * V2' + N2 * N2' I
9899
end
99100

100-
for kind in (:qr, :polar, :svd) # explicit kind kwarg
101-
m < n && kind == :polar && continue
102-
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C); kind = kind)
103-
@test V2 === V
104-
@test C2 === C
101+
for alg in (:qr, :polar, :svd) # explicit kind kwarg
102+
m < n && alg === :polar && continue
103+
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C); alg)
105104
@test V2 * C2 A
106105
@test isisometric(V2)
107-
if kind != :polar
108-
N2 = @constinferred left_null!(copy!(Ac, A), N; kind = kind)
109-
@test N2 === N
106+
if alg != :polar
107+
N2 = @constinferred left_null!(copy!(Ac, A), N; alg)
110108
@test LinearAlgebra.norm(A' * N2) 0 atol = MatrixAlgebraKit.defaulttol(T)
111109
@test isisometric(N2)
112110
@test V2 * V2' + N2 * N2' I
113111
end
114112

115113
# with kind and tol kwargs
116-
if kind == :svd
117-
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C); kind, trunc = (; atol))
118-
N2 = @constinferred left_null!(copy!(Ac, A), N; kind, trunc = (; atol))
119-
@test V2 !== V
120-
@test C2 !== C
121-
@test N2 !== C
114+
if alg == :svd
115+
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C); alg, trunc = (; atol))
116+
N2 = @constinferred left_null!(copy!(Ac, A), N; alg, trunc = (; atol))
122117
@test V2 * C2 A
123118
@test V2' * V2 I
124119
@test LinearAlgebra.norm(A' * N2) 0 atol = MatrixAlgebraKit.defaulttol(T)
125120
@test N2' * N2 I
126121
@test V2 * V2' + N2 * N2' I
127122

128-
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C); kind, trunc = (; rtol))
129-
N2 = @constinferred left_null!(copy!(Ac, A), N; kind, trunc = (; rtol))
130-
@test V2 !== V
131-
@test C2 !== C
132-
@test N2 !== C
123+
V2, C2 = @constinferred left_orth!(copy!(Ac, A), (V, C); alg, trunc = (; rtol))
124+
N2 = @constinferred left_null!(copy!(Ac, A), N; alg, trunc = (; rtol))
133125
@test V2 * C2 A
134126
@test isisometric(V2)
135127
@test LinearAlgebra.norm(A' * N2) 0 atol = MatrixAlgebraKit.defaulttol(T)
136128
@test isisometric(N2)
137129
@test V2 * V2' + N2 * N2' I
138130
else
139-
@test_throws ArgumentError left_orth!(copy!(Ac, A), (V, C); kind, trunc = (; atol))
140-
@test_throws ArgumentError left_orth!(copy!(Ac, A), (V, C); kind, trunc = (; rtol))
141-
@test_throws ArgumentError left_null!(copy!(Ac, A), N; kind, trunc = (; atol))
142-
@test_throws ArgumentError left_null!(copy!(Ac, A), N; kind, trunc = (; rtol))
131+
@test_throws ArgumentError left_orth!(copy!(Ac, A), (V, C); alg, trunc = (; atol))
132+
@test_throws ArgumentError left_orth!(copy!(Ac, A), (V, C); alg, trunc = (; rtol))
133+
@test_throws ArgumentError left_null!(copy!(Ac, A), N; alg, trunc = (; atol))
134+
@test_throws ArgumentError left_null!(copy!(Ac, A), N; alg, trunc = (; rtol))
143135
end
144136
end
145137
end
@@ -163,15 +155,12 @@ end
163155
@test Vᴴ' * Vᴴ + Nᴴ' * Nᴴ I
164156

165157
M = LinearMap(A)
166-
CM, VMᴴ = @constinferred right_orth(M; kind = :svd)
158+
CM, VMᴴ = @constinferred right_orth(M; alg = :svd)
167159
@test parent(CM) * parent(VMᴴ) A
168160

169161
Ac = similar(A)
170162
C2, Vᴴ2 = @constinferred right_orth!(copy!(Ac, A), (C, Vᴴ))
171163
Nᴴ2 = @constinferred right_null!(copy!(Ac, A), Nᴴ)
172-
@test C2 === C
173-
@test Vᴴ2 === Vᴴ
174-
@test Nᴴ2 === Nᴴ
175164
@test C2 * Vᴴ2 A
176165
@test isisometric(Vᴴ2; side = :right)
177166
@test LinearAlgebra.norm(A * adjoint(Nᴴ2)) 0 atol = MatrixAlgebraKit.defaulttol(T)
@@ -181,9 +170,6 @@ end
181170
atol = eps(real(T))
182171
C2, Vᴴ2 = @constinferred right_orth!(copy!(Ac, A), (C, Vᴴ); trunc = (; atol))
183172
Nᴴ2 = @constinferred right_null!(copy!(Ac, A), Nᴴ; trunc = (; atol))
184-
@test C2 !== C
185-
@test Vᴴ2 !== Vᴴ
186-
@test Nᴴ2 !== Nᴴ
187173
@test C2 * Vᴴ2 A
188174
@test isisometric(Vᴴ2; side = :right)
189175
@test LinearAlgebra.norm(A * adjoint(Nᴴ2)) 0 atol = MatrixAlgebraKit.defaulttol(T)
@@ -193,57 +179,45 @@ end
193179
rtol = eps(real(T))
194180
C2, Vᴴ2 = @constinferred right_orth!(copy!(Ac, A), (C, Vᴴ); trunc = (; rtol))
195181
Nᴴ2 = @constinferred right_null!(copy!(Ac, A), Nᴴ; trunc = (; rtol))
196-
@test C2 !== C
197-
@test Vᴴ2 !== Vᴴ
198-
@test Nᴴ2 !== Nᴴ
199182
@test C2 * Vᴴ2 A
200183
@test isisometric(Vᴴ2; side = :right)
201184
@test LinearAlgebra.norm(A * adjoint(Nᴴ2)) 0 atol = MatrixAlgebraKit.defaulttol(T)
202185
@test isisometric(Nᴴ2; side = :right)
203186
@test Vᴴ2' * Vᴴ2 + Nᴴ2' * Nᴴ2 I
204187

205-
for kind in (:lq, :polar, :svd)
206-
n < m && kind == :polar && continue
207-
C2, Vᴴ2 = @constinferred right_orth!(copy!(Ac, A), (C, Vᴴ); kind)
208-
@test C2 === C
209-
@test Vᴴ2 === Vᴴ
188+
for alg in (:lq, :polar, :svd)
189+
n < m && alg == :polar && continue
190+
C2, Vᴴ2 = @constinferred right_orth!(copy!(Ac, A), (C, Vᴴ); alg)
210191
@test C2 * Vᴴ2 A
211192
@test isisometric(Vᴴ2; side = :right)
212-
if kind != :polar
213-
Nᴴ2 = @constinferred right_null!(copy!(Ac, A), Nᴴ; kind)
214-
@test Nᴴ2 === Nᴴ
193+
if alg != :polar
194+
Nᴴ2 = @constinferred right_null!(copy!(Ac, A), Nᴴ; alg)
215195
@test LinearAlgebra.norm(A * adjoint(Nᴴ2)) 0 atol = MatrixAlgebraKit.defaulttol(T)
216196
@test isisometric(Nᴴ2; side = :right)
217197
@test Vᴴ2' * Vᴴ2 + Nᴴ2' * Nᴴ2 I
218198
end
219199

220-
if kind == :svd
221-
C2, Vᴴ2 = @constinferred right_orth!(copy!(Ac, A), (C, Vᴴ); kind, trunc = (; atol))
222-
Nᴴ2 = @constinferred right_null!(copy!(Ac, A), Nᴴ; kind, trunc = (; atol))
223-
@test C2 !== C
224-
@test Vᴴ2 !== Vᴴ
225-
@test Nᴴ2 !== Nᴴ
200+
if alg == :svd
201+
C2, Vᴴ2 = @constinferred right_orth!(copy!(Ac, A), (C, Vᴴ); alg, trunc = (; atol))
202+
Nᴴ2 = @constinferred right_null!(copy!(Ac, A), Nᴴ; alg, trunc = (; atol))
226203
@test C2 * Vᴴ2 A
227204
@test isisometric(Vᴴ2; side = :right)
228205
@test LinearAlgebra.norm(A * adjoint(Nᴴ2)) 0 atol = MatrixAlgebraKit.defaulttol(T)
229206
@test isisometric(Nᴴ2; side = :right)
230207
@test Vᴴ2' * Vᴴ2 + Nᴴ2' * Nᴴ2 I
231208

232-
C2, Vᴴ2 = @constinferred right_orth!(copy!(Ac, A), (C, Vᴴ); kind, trunc = (; rtol))
233-
Nᴴ2 = @constinferred right_null!(copy!(Ac, A), Nᴴ; kind, trunc = (; rtol))
234-
@test C2 !== C
235-
@test Vᴴ2 !== Vᴴ
236-
@test Nᴴ2 !== Nᴴ
209+
C2, Vᴴ2 = @constinferred right_orth!(copy!(Ac, A), (C, Vᴴ); alg, trunc = (; rtol))
210+
Nᴴ2 = @constinferred right_null!(copy!(Ac, A), Nᴴ; alg, trunc = (; rtol))
237211
@test C2 * Vᴴ2 A
238212
@test isisometric(Vᴴ2; side = :right)
239213
@test LinearAlgebra.norm(A * adjoint(Nᴴ2)) 0 atol = MatrixAlgebraKit.defaulttol(T)
240214
@test isisometric(Nᴴ2; side = :right)
241215
@test Vᴴ2' * Vᴴ2 + Nᴴ2' * Nᴴ2 I
242216
else
243-
@test_throws ArgumentError right_orth!(copy!(Ac, A), (C, Vᴴ); kind, trunc = (; atol))
244-
@test_throws ArgumentError right_orth!(copy!(Ac, A), (C, Vᴴ); kind, trunc = (; rtol))
245-
@test_throws ArgumentError right_null!(copy!(Ac, A), Nᴴ; kind, trunc = (; atol))
246-
@test_throws ArgumentError right_null!(copy!(Ac, A), Nᴴ; kind, trunc = (; rtol))
217+
@test_throws ArgumentError right_orth!(copy!(Ac, A), (C, Vᴴ); alg, trunc = (; atol))
218+
@test_throws ArgumentError right_orth!(copy!(Ac, A), (C, Vᴴ); alg, trunc = (; rtol))
219+
@test_throws ArgumentError right_null!(copy!(Ac, A), Nᴴ; alg, trunc = (; atol))
220+
@test_throws ArgumentError right_null!(copy!(Ac, A), Nᴴ; alg, trunc = (; rtol))
247221
end
248222
end
249223
end

0 commit comments

Comments
 (0)