Skip to content

Commit c58ee3c

Browse files
committed
Expand testing with mixed scalartypes
1 parent 713a8aa commit c58ee3c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

test/operators.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,40 @@ vspaces = (ℙ^10, Rep[U₁]((0 => 20)), Rep[SU₂](1 // 2 => 10, 3 // 2 => 5, 5
2424
for V in (ℂ^2, U1Space(0 => 1, 1 => 1))
2525
O₁ = rand(T, V^L, V^L)
2626
O₂ = rand(T, space(O₁))
27+
O₃ = rand(real(T), space(O₁))
2728

2829
# create MPO and convert it back to see if it is the same
2930
mpo₁ = FiniteMPO(O₁) # type-unstable for now!
3031
mpo₂ = FiniteMPO(O₂)
32+
mpo₃ = FiniteMPO(O₃)
3133
@test convert(TensorMap, mpo₁) O₁
3234
@test convert(TensorMap, -mpo₂) -O₂
35+
@test convert(TensorMap, @constinferred complex(mpo₃)) complex(O₃)
3336

3437
# test scalar multiplication
3538
α = rand(T)
3639
@test convert(TensorMap, α * mpo₁) α * O₁
3740
@test convert(TensorMap, mpo₁ * α) O₁ * α
41+
@test α * mpo₃ α * complex(mpo₃)
3842

3943
# test addition and multiplication
4044
@test convert(TensorMap, mpo₁ + mpo₂) O₁ + O₂
45+
@test convert(TensorMap, mpo₁ + mpo₃) O₁ + O₃
4146
@test convert(TensorMap, mpo₁ * mpo₂) O₁ * O₂
47+
@test convert(TensorMap, mpo₁ * mpo₃) O₁ * O₃
4248

4349
# test application to a state
4450
ψ₁ = rand(T, domain(O₁))
51+
ψ₂ = rand(real(T), domain(O₂))
4552
mps₁ = FiniteMPS(ψ₁)
53+
mps₂ = FiniteMPS(ψ₂)
4654

4755
@test convert(TensorMap, mpo₁ * mps₁) O₁ * ψ₁
4856
@test mpo₁ * ψ₁ O₁ * ψ₁
57+
@test convert(TensorMap, mpo₃ * mps₁) O₃ * ψ₁
58+
@test mpo₃ * ψ₁ O₃ * ψ₁
59+
@test convert(TensorMap, mpo₁ * mps₂) O₁ * ψ₂
60+
@test mpo₁ * ψ₂ O₁ * ψ₂
4961

5062
@test dot(mps₁, mpo₁, mps₁) dot(ψ₁, O₁, ψ₁)
5163
@test dot(mps₁, mpo₁, mps₁) dot(mps₁, mpo₁ * mps₁)

test/states.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ end
4646
ψ_small2 = FiniteMPS(convert(TensorMap, ψ_small))
4747
@test dot(ψ_small, ψ_small2) dot(ψ_small, ψ_small)
4848

49-
ψ′ = @constinferred complex(ψ)
49+
ψ′ = @constinferred complex(ψ_small)
5050
@test scalartype(ψ′) <: Complex
5151
if elt <: Complex
52-
@test ψ === ψ′
52+
@test ψ_small === ψ′
5353
else
54-
@test norm(ψ) norm(ψ′)
55-
@test complex(convert(TensorMap, ψ)) convert(TensorMap, ψ′)
54+
@test norm(ψ_small) norm(ψ′)
55+
@test complex(convert(TensorMap, ψ_small)) convert(TensorMap, ψ′)
5656
end
5757
end
5858

0 commit comments

Comments
 (0)