@@ -5,8 +5,16 @@ diagspacelist = ((ℂ^4)', ℂ[Z2Irrep](0 => 2, 1 => 3),
5
5
@testset " DiagonalTensor with domain $V " for V in diagspacelist
6
6
@timedtestset " Basic properties and algebra" begin
7
7
for T in (Float32, Float64, ComplexF32, ComplexF64, BigFloat)
8
+ # constructors
8
9
t = @constinferred DiagonalTensorMap {T} (undef, V)
9
10
t = @constinferred DiagonalTensorMap (rand (T, reduceddim (V)), V)
11
+ t2 = @constinferred DiagonalTensorMap {T} (undef, space (t))
12
+ @test space (t2) == space (t)
13
+ @test_throws ArgumentError DiagonalTensorMap {T} (undef, V^ 2 ← V)
14
+ t2 = @constinferred DiagonalTensorMap {T} (undef, domain (t))
15
+ @test space (t2) == space (t)
16
+ @test_throws ArgumentError DiagonalTensorMap {T} (undef, V^ 2 )
17
+ # properties
10
18
@test @constinferred (hash (t)) == hash (deepcopy (t))
11
19
@test scalartype (t) == T
12
20
@test codomain (t) == ProductSpace (V)
@@ -135,6 +143,16 @@ diagspacelist = ((ℂ^4)', ℂ[Z2Irrep](0 => 2, 1 => 3),
135
143
@test u / t1 ≈ u / TensorMap (t1)
136
144
@test t1 * u' ≈ TensorMap (t1) * u'
137
145
@test t1 \ u' ≈ TensorMap (t1) \ u'
146
+
147
+ t3 = rand (Float64, V ← V^ 2 )
148
+ t4 = rand (ComplexF64, V ← V^ 2 )
149
+ @test t1 * t3 ≈ lmul! (t1, copy (t3))
150
+ @test t2 * t4 ≈ lmul! (t2, copy (t4))
151
+
152
+ t3 = rand (Float64, V^ 2 ← V)
153
+ t4 = rand (ComplexF64, V^ 2 ← V)
154
+ @test t3 * t1 ≈ rmul! (copy (t3), t1)
155
+ @test t4 * t2 ≈ rmul! (copy (t4), t2)
138
156
end
139
157
@timedtestset " Tensor contraction" begin
140
158
d = DiagonalTensorMap (rand (ComplexF64, reduceddim (V)), V)
@@ -175,6 +193,12 @@ diagspacelist = ((ℂ^4)', ℂ[Z2Irrep](0 => 2, 1 => 3),
175
193
VdV2 = V2' * V2
176
194
@test VdV2 ≈ one (VdV2)
177
195
@test t2 * V2 ≈ V2 * D2
196
+
197
+ @test rank (D) ≈ rank (t)
198
+ @test cond (D) ≈ cond (t)
199
+ @test all (((s, t),) -> isapprox (s, t),
200
+ zip (values (LinearAlgebra. eigvals (D)),
201
+ values (LinearAlgebra. eigvals (t))))
178
202
end
179
203
@testset " leftorth with $alg " for alg in (TensorKit. QR (), TensorKit. QL ())
180
204
Q, R = @constinferred leftorth (t; alg= alg)
@@ -201,6 +225,12 @@ diagspacelist = ((ℂ^4)', ℂ[Z2Irrep](0 => 2, 1 => 3),
201
225
VdV = Vᴴ * Vᴴ'
202
226
@test VdV ≈ one (VdV)
203
227
@test U * S * Vᴴ ≈ t
228
+
229
+ @test rank (S) ≈ rank (t)
230
+ @test cond (S) ≈ cond (t)
231
+ @test all (((s, t),) -> isapprox (s, t),
232
+ zip (values (LinearAlgebra. svdvals (S)),
233
+ values (LinearAlgebra. svdvals (t))))
204
234
end
205
235
end
206
236
end
0 commit comments