@@ -35,8 +35,8 @@ elts = (Float64, ComplexF64)
35
35
Acopy = deepcopy (A)
36
36
Q, R = @constinferred qr (A, labels_A, labels_Q, labels_R; full= true )
37
37
@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 ))
40
40
@test size (Q, 1 ) * size (Q, 2 ) == size (Q, 3 ) # Q is unitary
41
41
end
42
42
49
49
Acopy = deepcopy (A)
50
50
Q, R = @constinferred qr (A, labels_A, labels_Q, labels_R; full= false )
51
51
@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 ))
54
54
@test size (Q, 3 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
55
55
end
56
56
65
65
Acopy = deepcopy (A)
66
66
L, Q = @constinferred lq (A, labels_A, labels_L, labels_Q; full= true )
67
67
@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 ))
70
70
@test size (Q, 1 ) == size (Q, 2 ) * size (Q, 3 ) # Q is unitary
71
71
end
72
72
79
79
Acopy = deepcopy (A)
80
80
L, Q = @constinferred lq (A, labels_A, labels_L, labels_Q; full= false )
81
81
@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 ))
84
84
@test size (Q, 1 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 )) # Q is unitary
85
85
end
86
86
98
98
@test A == Acopy # should not have altered initial array
99
99
@test eltype (D) == eltype (V) && eltype (D) <: Complex
100
100
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 ))
104
104
105
105
# type-unstable because of `ishermitian` difference
106
106
Dvals = eigvals (A, labels_A, labels_V, labels_V′; ishermitian= false )
122
122
@test eltype (D) <: Real
123
123
@test eltype (V) == eltype (A)
124
124
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 ))
128
128
129
129
# type-unstable because of `ishermitian` difference
130
130
Dvals = eigvals (A, labels_A, labels_V, labels_V′; ishermitian= true )
@@ -144,22 +144,22 @@ end
144
144
U, S, Vᴴ = @constinferred svd (A, labels_A, labels_U, labels_Vᴴ; full= true )
145
145
@test A == Acopy # should not have altered initial array
146
146
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 ))
149
149
@test size (U, 1 ) * size (U, 2 ) == size (U, 3 ) # U is unitary
150
150
@test size (Vᴴ, 1 ) == size (Vᴴ, 2 ) * size (Vᴴ, 3 ) # V is unitary
151
151
152
152
U, S, Vᴴ = @constinferred svd (A, labels_A, labels_A, (); full= true )
153
153
@test A == Acopy # should not have altered initial array
154
154
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 ,))
156
156
@test A ≈ A′
157
157
@test size (Vᴴ, 1 ) == 1
158
158
159
159
U, S, Vᴴ = @constinferred svd (A, labels_A, (), labels_A; full= true )
160
160
@test A == Acopy # should not have altered initial array
161
161
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... ))
163
163
@test A ≈ A′
164
164
@test size (U, 2 ) == 1
165
165
end
174
174
U, S, Vᴴ = @constinferred svd (A, labels_A, labels_U, labels_Vᴴ; full= false )
175
175
@test A == Acopy # should not have altered initial array
176
176
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 ))
179
179
k = min (size (S)... )
180
180
@test size (U, 3 ) == k == size (Vᴴ, 1 )
181
181
@@ -185,14 +185,14 @@ end
185
185
U, S, Vᴴ = @constinferred svd (A, labels_A, labels_A, (); full= false )
186
186
@test A == Acopy # should not have altered initial array
187
187
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 ,))
189
189
@test A ≈ A′
190
190
@test size (U, ndims (U)) == 1 == size (Vᴴ, 1 )
191
191
192
192
U, S, Vᴴ = @constinferred svd (A, labels_A, (), labels_A; full= false )
193
193
@test A == Acopy # should not have altered initial array
194
194
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... ))
196
196
@test A ≈ A′
197
197
@test size (U, 1 ) == 1 == size (Vᴴ, 1 )
198
198
end
212
212
213
213
@test A == Acopy # should not have altered initial array
214
214
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 ]
217
217
@test size (S, 1 ) == size (S_untrunc, 1 ) - 1
218
218
end
219
219
@@ -227,17 +227,17 @@ end
227
227
N = @constinferred left_null (A, labels_A, labels_codomain, labels_domain)
228
228
@test A == Acopy # should not have altered initial array
229
229
# 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)
231
231
@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′ ))
233
233
@test NN ≈ LinearAlgebra. I
234
234
235
235
Nᴴ = @constinferred right_null (A, labels_A, labels_codomain, labels_domain)
236
236
@test A == Acopy # should not have altered initial array
237
237
# 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... ))
239
239
@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... ))
241
241
end
242
242
243
243
@testset " Left polar ($T )" for T in elts
253
253
polar (A, labels_A, labels_W, labels_P),
254
254
)
255
255
@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 ))
258
258
@test size (W, 3 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
259
259
end
260
260
end
271
271
polar (A, labels_A, labels_P, labels_W; side= :right ),
272
272
)
273
273
@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 ))
276
276
@test size (W, 1 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
277
277
end
278
278
end
290
290
orth (A, labels_A, labels_W, labels_P),
291
291
)
292
292
@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 ))
295
295
@test size (W, 3 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
296
296
end
297
297
end
308
308
orth (A, labels_A, labels_P, labels_W; side= :right ),
309
309
)
310
310
@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 ))
313
313
@test size (W, 1 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
314
314
end
315
315
end
324
324
for orth in (:left , :right )
325
325
X, Y = factorize (A, labels_A, labels_X, labels_Y; orth)
326
326
@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 ))
329
329
@test size (X, 3 ) == min (size (A, 1 ) * size (A, 2 ), size (A, 3 ) * size (A, 4 ))
330
330
end
331
331
end
0 commit comments