Skip to content

Commit

Permalink
Merge pull request #65 from ZKSI/pg/fixbases
Browse files Browse the repository at this point in the history
hermitainbasisiterator obeeys its matrix type
  • Loading branch information
pgawron authored Aug 19, 2019
2 parents 56c8053 + 46c2d1d commit dcb33a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/matrixbases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ function iterate(itr::HermitianBasisIterator{T}, state=(1,1)) where T<:AbstractM
(a, b) = state
a > dim && return nothing

Tn = eltype(T)
if a > b
x = 1 / sqrt(2) * (1im * ketbra(a, b, dim) - 1im * ketbra(b, a, dim))
x = (im * ketbra(T, a, b, dim) - im * ketbra(T, b, a, dim)) / sqrt(Tn(2))
elseif a < b
x = 1 / sqrt(2) * (ketbra(a, b, dim) + ketbra(b, a, dim))
x = (ketbra(T, a, b, dim) + ketbra(T, b, a, dim)) / sqrt(Tn(2))
else
x = ketbra(a, b, dim)
x = ketbra(T, a, b, dim)
end
return x, b==dim ? (a+1, 1) : (a, b+1)
end
Expand Down
5 changes: 4 additions & 1 deletion test/matrixbases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ end

@testset "represent, combine" begin
d = 4
A = reshape(collect(1:16), 4, 4)
A = reshape(collect(1:16), d, d)
vA = represent(HermitianBasis{Matrix{ComplexF64}}(d), A)
Ap = combine(HermitianBasis{Matrix{ComplexF64}}(d), vA)
@test A Ap
B = A*A'
vB = represent(HermitianBasis{Matrix{ComplexF64}}(d), B)
Bp = combine(HermitianBasis{Matrix{ComplexF64}}(d), vB)
@test B Bp

vB = represent(HermitianBasis{Matrix{ComplexF32}}(d), B)
@test eltype(vB) == ComplexF32
end

end

0 comments on commit dcb33a1

Please sign in to comment.