|
| 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 |
0 commit comments