|
147 | 147 | @test A ≈ A′ |
148 | 148 | @test size(U, 1) * size(U, 2) == size(U, 3) # U is unitary |
149 | 149 | @test size(Vᴴ, 1) == size(Vᴴ, 2) * size(Vᴴ, 3) # V is unitary |
| 150 | + |
| 151 | + U, S, Vᴴ = @constinferred svd(A, labels_A, labels_A, (); full=true) |
| 152 | + @test A == Acopy # should not have altered initial array |
| 153 | + US, labels_US = contract(U, (labels_A..., :u), S, (:u, :v)) |
| 154 | + A′ = contract(labels_A, US, labels_US, Vᴴ, (:v,)) |
| 155 | + @test A ≈ A′ |
| 156 | + @test size(Vᴴ, 1) == 1 |
| 157 | + |
| 158 | + U, S, Vᴴ = @constinferred svd(A, labels_A, (), labels_A; full=true) |
| 159 | + @test A == Acopy # should not have altered initial array |
| 160 | + US, labels_US = contract(U, (:u,), S, (:u, :v)) |
| 161 | + A′ = contract(labels_A, US, labels_US, Vᴴ, (:v, labels_A...)) |
| 162 | + @test A ≈ A′ |
| 163 | + @test size(U, 2) == 1 |
150 | 164 | end |
151 | 165 |
|
152 | 166 | @testset "Compact SVD ($T)" for T in elts |
|
166 | 180 |
|
167 | 181 | Svals = @constinferred svdvals(A, labels_A, labels_U, labels_Vᴴ) |
168 | 182 | @test Svals ≈ diag(S) |
| 183 | + |
| 184 | + U, S, Vᴴ = @constinferred svd(A, labels_A, labels_A, (); full=false) |
| 185 | + @test A == Acopy # should not have altered initial array |
| 186 | + US, labels_US = contract(U, (labels_A..., :u), S, (:u, :v)) |
| 187 | + A′ = contract(labels_A, US, labels_US, Vᴴ, (:v,)) |
| 188 | + @test A ≈ A′ |
| 189 | + @test size(U, ndims(U)) == 1 == size(Vᴴ, 1) |
| 190 | + |
| 191 | + U, S, Vᴴ = @constinferred svd(A, labels_A, (), labels_A; full=false) |
| 192 | + @test A == Acopy # should not have altered initial array |
| 193 | + US, labels_US = contract(U, (:u,), S, (:u, :v)) |
| 194 | + A′ = contract(labels_A, US, labels_US, Vᴴ, (:v, labels_A...)) |
| 195 | + @test A ≈ A′ |
| 196 | + @test size(U, 1) == 1 == size(Vᴴ, 1) |
169 | 197 | end |
170 | 198 |
|
171 | 199 | @testset "Truncated SVD ($T)" for T in elts |
|
0 commit comments