Skip to content

Commit 87e2e47

Browse files
committed
improve real(::MPOHamiltonian) coverage
1 parent 5558e49 commit 87e2e47

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

test/operators.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ module TestOperators
124124
@testset "Finite MPOHamiltonian" begin
125125
L = 3
126126
T = ComplexF64
127-
for V in (ℂ^2, U1Space(-1 => 1, 0 => 1, 1 => 1))
127+
for T in (Float64, ComplexF64), V in (ℂ^2, U1Space(-1 => 1, 0 => 1, 1 => 1))
128128
lattice = fill(V, L)
129129
O₁ = randn(T, V, V)
130130
O₁ += O₁'
@@ -136,6 +136,20 @@ module TestOperators
136136
H2 = FiniteMPOHamiltonian(lattice, (i, i + 1) => O₂ for i in 1:(L - 1))
137137
H3 = FiniteMPOHamiltonian(lattice, 1 => O₁, (2, 3) => O₂, (1, 3) => O₂)
138138

139+
@test scalartype(H1) == scalartype(H2) == scalartype(H3) == T
140+
if !(T <: Complex)
141+
for H in (H1, H2, H3)
142+
Hc = @constinferred complex(H)
143+
@test scalartype(Hc) == complex(T)
144+
# cannot define `real(H)`, so only test elementwise
145+
for (Wc, W) in zip(parent(Hc), parent(H))
146+
Wr = @constinferred real(Wc)
147+
@test scalartype(Wr) == T
148+
@test Wr W atol = 1.0e-6
149+
end
150+
end
151+
end
152+
139153
# check if constructor works by converting back to tensormap
140154
H1_tm = convert(TensorMap, H1)
141155
operators = vcat(fill(E, L - 1), O₁)

0 commit comments

Comments
 (0)