@@ -35,8 +35,8 @@ elts = (Float64, ComplexF64)
3535 Acopy = deepcopy (A)
3636 Q, R = @constinferred qr (A, labels_A, labels_Q, labels_R; full= true )
3737 @test A == Acopy # should not have altered initial array
38- A′ = contract (labels_A, Q, (labels_Q... , :q ), R, (:q , labels_R... ))
39- @test A ≈ A′
38+ A′, legs = contract (Q, (labels_Q... , :q ), R, (:q , labels_R... ))
39+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
4040 @test size (Q, 1 ) * size (Q, 2 ) == size (Q, 3 ) # Q is unitary
4141end
4242
4949 Acopy = deepcopy (A)
5050 Q, R = @constinferred qr (A, labels_A, labels_Q, labels_R; full= false )
5151 @test A == Acopy # should not have altered initial array
52- A′ = contract (labels_A, Q, (labels_Q... , :q ), R, (:q , labels_R... ))
53- @test A ≈ A′
52+ A′, legs = contract (Q, (labels_Q... , :q ), R, (:q , labels_R... ))
53+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
5454 @test size (Q, 3 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
5555end
5656
6565 Acopy = deepcopy (A)
6666 L, Q = @constinferred lq (A, labels_A, labels_L, labels_Q; full= true )
6767 @test A == Acopy # should not have altered initial array
68- A′ = contract (labels_A, L, (labels_L... , :q ), Q, (:q , labels_Q... ))
69- @test A ≈ A′
68+ A′, legs = contract (L, (labels_L... , :q ), Q, (:q , labels_Q... ))
69+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
7070 @test size (Q, 1 ) == size (Q, 2 ) * size (Q, 3 ) # Q is unitary
7171end
7272
7979 Acopy = deepcopy (A)
8080 L, Q = @constinferred lq (A, labels_A, labels_L, labels_Q; full= false )
8181 @test A == Acopy # should not have altered initial array
82- A′ = contract (labels_A, L, (labels_L... , :q ), Q, (:q , labels_Q... ))
83- @test A ≈ A′
82+ A′, legs = contract (L, (labels_L... , :q ), Q, (:q , labels_Q... ))
83+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
8484 @test size (Q, 1 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 )) # Q is unitary
8585end
8686
9898 @test A == Acopy # should not have altered initial array
9999 @test eltype (D) == eltype (V) && eltype (D) <: Complex
100100
101- AV = contract (( :a , :b , :D ), A, labels_A, V, (labels_V′... , :D ))
102- VD = contract (( :a , :b , :D ), V, (labels_V... , :D′ ), D, (:D′ , :D ))
103- @test AV ≈ VD
101+ AV, _ = contract (A, labels_A, V, (labels_V′... , :D ))
102+ VD, _ = contract (V, (labels_V... , :D′ ), D, (:D′ , :D ))
103+ @test AV ≈ permutedims (VD, ( 2 , 1 , 3 ))
104104
105105 # type-unstable because of `ishermitian` difference
106106 Dvals = eigvals (A, labels_A, labels_V, labels_V′; ishermitian= false )
122122 @test eltype (D) <: Real
123123 @test eltype (V) == eltype (A)
124124
125- AV = contract (( :a , :b , :D ), A, labels_A, V, (labels_V′... , :D ))
126- VD = contract (( :a , :b , :D ), V, (labels_V... , :D′ ), D, (:D′ , :D ))
127- @test AV ≈ VD
125+ AV, _ = contract (A, labels_A, V, (labels_V′... , :D ))
126+ VD, _ = contract (V, (labels_V... , :D′ ), D, (:D′ , :D ))
127+ @test AV ≈ permutedims (VD, ( 2 , 1 , 3 ))
128128
129129 # type-unstable because of `ishermitian` difference
130130 Dvals = eigvals (A, labels_A, labels_V, labels_V′; ishermitian= true )
@@ -144,22 +144,22 @@ end
144144 U, S, Vᴴ = @constinferred svd (A, labels_A, labels_U, labels_Vᴴ; full= true )
145145 @test A == Acopy # should not have altered initial array
146146 US, labels_US = contract (U, (labels_U... , :u ), S, (:u , :v ))
147- A′ = contract (labels_A, US, labels_US, Vᴴ, (:v , labels_Vᴴ... ))
148- @test A ≈ A′
147+ A′, _ = contract (US, labels_US, Vᴴ, (:v , labels_Vᴴ... ))
148+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
149149 @test size (U, 1 ) * size (U, 2 ) == size (U, 3 ) # U is unitary
150150 @test size (Vᴴ, 1 ) == size (Vᴴ, 2 ) * size (Vᴴ, 3 ) # V is unitary
151151
152152 U, S, Vᴴ = @constinferred svd (A, labels_A, labels_A, (); full= true )
153153 @test A == Acopy # should not have altered initial array
154154 US, labels_US = contract (U, (labels_A... , :u ), S, (:u , :v ))
155- A′ = contract (labels_A, US, labels_US, Vᴴ, (:v ,))
155+ A′, _ = contract (US, labels_US, Vᴴ, (:v ,))
156156 @test A ≈ A′
157157 @test size (Vᴴ, 1 ) == 1
158158
159159 U, S, Vᴴ = @constinferred svd (A, labels_A, (), labels_A; full= true )
160160 @test A == Acopy # should not have altered initial array
161161 US, labels_US = contract (U, (:u ,), S, (:u , :v ))
162- A′ = contract (labels_A, US, labels_US, Vᴴ, (:v , labels_A... ))
162+ A′, _ = contract (US, labels_US, Vᴴ, (:v , labels_A... ))
163163 @test A ≈ A′
164164 @test size (U, 2 ) == 1
165165end
174174 U, S, Vᴴ = @constinferred svd (A, labels_A, labels_U, labels_Vᴴ; full= false )
175175 @test A == Acopy # should not have altered initial array
176176 US, labels_US = contract (U, (labels_U... , :u ), S, (:u , :v ))
177- A′ = contract (labels_A, US, labels_US, Vᴴ, (:v , labels_Vᴴ... ))
178- @test A ≈ A′
177+ A′, _ = contract (US, labels_US, Vᴴ, (:v , labels_Vᴴ... ))
178+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
179179 k = min (size (S)... )
180180 @test size (U, 3 ) == k == size (Vᴴ, 1 )
181181
@@ -185,14 +185,14 @@ end
185185 U, S, Vᴴ = @constinferred svd (A, labels_A, labels_A, (); full= false )
186186 @test A == Acopy # should not have altered initial array
187187 US, labels_US = contract (U, (labels_A... , :u ), S, (:u , :v ))
188- A′ = contract (labels_A, US, labels_US, Vᴴ, (:v ,))
188+ A′, _ = contract (US, labels_US, Vᴴ, (:v ,))
189189 @test A ≈ A′
190190 @test size (U, ndims (U)) == 1 == size (Vᴴ, 1 )
191191
192192 U, S, Vᴴ = @constinferred svd (A, labels_A, (), labels_A; full= false )
193193 @test A == Acopy # should not have altered initial array
194194 US, labels_US = contract (U, (:u ,), S, (:u , :v ))
195- A′ = contract (labels_A, US, labels_US, Vᴴ, (:v , labels_A... ))
195+ A′, _ = contract (US, labels_US, Vᴴ, (:v , labels_A... ))
196196 @test A ≈ A′
197197 @test size (U, 1 ) == 1 == size (Vᴴ, 1 )
198198end
212212
213213 @test A == Acopy # should not have altered initial array
214214 US, labels_US = contract (U, (labels_U... , :u ), S, (:u , :v ))
215- A′ = contract (labels_A, US, labels_US, Vᴴ, (:v , labels_Vᴴ... ))
216- @test norm (A - A′ ) ≈ S_untrunc[end ]
215+ A′, _ = contract (US, labels_US, Vᴴ, (:v , labels_Vᴴ... ))
216+ @test norm (A - permutedims (A′, ( 2 , 1 , 4 , 3 )) ) ≈ S_untrunc[end ]
217217 @test size (S, 1 ) == size (S_untrunc, 1 ) - 1
218218end
219219
@@ -227,17 +227,17 @@ end
227227 N = @constinferred left_null (A, labels_A, labels_codomain, labels_domain)
228228 @test A == Acopy # should not have altered initial array
229229 # N^ba_n' * A^ba_dc = 0
230- NA = contract (( :n , labels_domain ... ), conj (N), (labels_codomain... , :n ), A, labels_A)
230+ NA, _ = contract (conj (N), (labels_codomain... , :n ), A, labels_A)
231231 @test norm (NA) ≈ 0 atol = 1e-14
232- NN = contract (( :n , :n′ ), conj (N), (labels_codomain... , :n ), N, (labels_codomain... , :n′ ))
232+ NN, _ = contract (conj (N), (labels_codomain... , :n ), N, (labels_codomain... , :n′ ))
233233 @test NN ≈ LinearAlgebra. I
234234
235235 Nᴴ = @constinferred right_null (A, labels_A, labels_codomain, labels_domain)
236236 @test A == Acopy # should not have altered initial array
237237 # A^ba_dc * N^dc_n' = 0
238- AN = contract ((labels_codomain ... , :n ), A, labels_A, conj (Nᴴ), (:n , labels_domain... ))
238+ AN, _ = contract (A, labels_A, conj (Nᴴ), (:n , labels_domain... ))
239239 @test norm (AN) ≈ 0 atol = 1e-14
240- NN = contract (( :n , :n′ ), Nᴴ, (:n , labels_domain... ), Nᴴ, (:n′ , labels_domain... ))
240+ NN, _ = contract (Nᴴ, (:n , labels_domain... ), Nᴴ, (:n′ , labels_domain... ))
241241end
242242
243243@testset " Left polar ($T )" for T in elts
253253 polar (A, labels_A, labels_W, labels_P),
254254 )
255255 @test A == Acopy # should not have altered initial array
256- A′ = contract (labels_A, W, (labels_W... , :w ), P, (:w , labels_P... ))
257- @test A ≈ A′
256+ A′, _ = contract (W, (labels_W... , :w ), P, (:w , labels_P... ))
257+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
258258 @test size (W, 3 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
259259 end
260260end
271271 polar (A, labels_A, labels_P, labels_W; side= :right ),
272272 )
273273 @test A == Acopy # should not have altered initial array
274- A′ = contract (labels_A, P, (labels_P... , :w ), W, (:w , labels_W... ))
275- @test A ≈ A′
274+ A′, _ = contract (P, (labels_P... , :w ), W, (:w , labels_W... ))
275+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
276276 @test size (W, 1 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
277277 end
278278end
290290 orth (A, labels_A, labels_W, labels_P),
291291 )
292292 @test A == Acopy # should not have altered initial array
293- A′ = contract (labels_A, W, (labels_W... , :w ), P, (:w , labels_P... ))
294- @test A ≈ A′
293+ A′, _ = contract (W, (labels_W... , :w ), P, (:w , labels_P... ))
294+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
295295 @test size (W, 3 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
296296 end
297297end
308308 orth (A, labels_A, labels_P, labels_W; side= :right ),
309309 )
310310 @test A == Acopy # should not have altered initial array
311- A′ = contract (labels_A, P, (labels_P... , :w ), W, (:w , labels_W... ))
312- @test A ≈ A′
311+ A′, _ = contract (P, (labels_P... , :w ), W, (:w , labels_W... ))
312+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
313313 @test size (W, 1 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
314314 end
315315end
324324 for orth in (:left , :right )
325325 X, Y = factorize (A, labels_A, labels_X, labels_Y; orth)
326326 @test A == Acopy # should not have altered initial array
327- A′ = contract (labels_A, X, (labels_X... , :x ), Y, (:x , labels_Y... ))
328- @test A ≈ A′
327+ A′, _ = contract (X, (labels_X... , :x ), Y, (:x , labels_Y... ))
328+ @test A ≈ permutedims (A′, ( 2 , 1 , 4 , 3 ))
329329 @test size (X, 3 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
330330 end
331331end
0 commit comments