1
1
using Test
2
2
import RecursiveFactorization
3
3
import LinearAlgebra
4
- using LinearAlgebra: norm, Adjoint, Transpose
4
+ using LinearAlgebra: norm, Adjoint, Transpose, ldiv!
5
5
using Random
6
6
7
7
Random. seed! (12 )
8
8
9
9
const baselu = LinearAlgebra. lu
10
10
const mylu = RecursiveFactorization. lu
11
11
12
- function testlu (A, MF, BF)
12
+ function testlu (A, MF, BF, p )
13
13
@test MF. info == BF. info
14
- @test norm (MF. L * MF. U - A[MF. p, :], Inf ) < 200 sqrt (eps (real (one (float (first (A))))))
14
+ if ! iszero (MF. info)
15
+ return nothing
16
+ end
17
+ E = 20 size (A, 1 ) * eps (real (one (float (first (A)))))
18
+ @test norm (MF. L * MF. U - A[MF. p, :], Inf ) < (p ? E : 10 sqrt (E))
19
+ if == (size (A)... )
20
+ b = ldiv! (MF, A[:, end ])
21
+ if all (isfinite, b)
22
+ n = size (A, 2 )
23
+ rhs = [i == n for i in 1 : n]
24
+ @test b≈ rhs atol= p ? 100 E : 100 sqrt (E)
25
+ end
26
+ end
15
27
nothing
16
28
end
17
- testlu (A:: Union{Transpose, Adjoint} , MF, BF) = testlu (parent (A), parent (MF), BF)
29
+ testlu (A:: Union{Transpose, Adjoint} , MF, BF, p ) = testlu (parent (A), parent (MF), BF, p )
18
30
19
31
@testset " Test LU factorization" begin
20
32
for _p in (true , false ),
@@ -24,29 +36,31 @@ testlu(A::Union{Transpose, Adjoint}, MF, BF) = testlu(parent(A), parent(MF), BF)
24
36
p = Val (_p)
25
37
for (i, s) in enumerate ([1 : 10 ; 50 : 80 : 200 ; 300 ])
26
38
iseven (i) && (p = RecursiveFactorization. to_stdlib_pivot (p))
27
- siz = (s, s + 2 )
28
- @info (" size: $(siz[1 ]) × $(siz[2 ]) , T = $T , p = $_p " )
29
- if isconcretetype (T)
30
- A = rand (T, siz... )
31
- else
32
- _A = rand (siz... )
33
- A = Matrix {T} (undef, siz... )
34
- copyto! (A, _A)
39
+ for m in (s, s + 2 )
40
+ siz = (s, m)
41
+ @info (" size: $(siz[1 ]) × $(siz[2 ]) , T = $T , p = $_p " )
42
+ if isconcretetype (T)
43
+ A = rand (T, siz... )
44
+ else
45
+ _A = rand (siz... )
46
+ A = Matrix {T} (undef, siz... )
47
+ copyto! (A, _A)
48
+ end
49
+ MF = mylu (A, p)
50
+ BF = baselu (A, p)
51
+ testlu (A, MF, BF, _p)
52
+ testlu (A, mylu (A, p, Val (false )), BF, false )
53
+ A′ = permutedims (A)
54
+ MF′ = mylu (A′' , p)
55
+ testlu (A′' , MF′, BF, _p)
56
+ testlu (A′' , mylu (A′' , p, Val (false )), BF, false )
57
+ i = rand (1 : s) # test `MF.info`
58
+ A[:, i] .= 0
59
+ MF = mylu (A, p, check = false )
60
+ BF = baselu (A, p, check = false )
61
+ testlu (A, MF, BF, _p)
62
+ testlu (A, mylu (A, p, Val (false ), check = false ), BF, false )
35
63
end
36
- MF = mylu (A, p)
37
- BF = baselu (A, p)
38
- testlu (A, MF, BF)
39
- testlu (A, mylu (A, p, Val (false )), BF)
40
- A′ = permutedims (A)
41
- MF′ = mylu (A′' , p)
42
- testlu (A′' , MF′, BF)
43
- testlu (A′' , mylu (A′' , p, Val (false )), BF)
44
- i = rand (1 : s) # test `MF.info`
45
- A[:, i] .= 0
46
- MF = mylu (A, p, check = false )
47
- BF = baselu (A, p, check = false )
48
- testlu (A, MF, BF)
49
- testlu (A, mylu (A, p, Val (false ), check = false ), BF)
50
64
end
51
65
end
52
66
end
0 commit comments