Skip to content

Commit f555684

Browse files
committed
Tests added.
1 parent 25862bd commit f555684

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/arrays/arraymath.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function \{B<:OrthonormalBasis}(op::AbstractQuMatrix{B}, vec::AbstractQuVector{B
122122
end
123123

124124
# convert coeffs to complex
125-
Base.complex{B<:OrthonormalBasis}(qarr::AbstractQuArray{B}) = similar_type(qarr)(complex(coeffs(vec(qarr))), bases(qarr))
125+
Base.complex{B<:OrthonormalBasis}(qarr::AbstractQuArray{B}) = similar_type(qarr)(complex(coeffs(qarr)), bases(qarr))
126126

127127
# Vectorize QuArray
128128
Base.vec{B<:OrthonormalBasis}(vec1::AbstractQuArray{B}) = QuArray(vec(coeffs(vec1)))
@@ -201,8 +201,15 @@ tensor(bra::DualVector, ket::AbstractQuVector) = tensor(ket, bra)
201201
commute(a::AbstractQuMatrix, b::AbstractQuMatrix) = (a*b) - (b*a)
202202
anticommute(a::AbstractQuMatrix, b::AbstractQuMatrix) = (a*b) + (b*a)
203203

204+
###############
205+
# Expectaion #
206+
###############
207+
expectation(qarr::AbstractQuVector, op::AbstractQuMatrix) = vec(qarr)'*op*vec(qarr)
208+
expectation(qarr::AbstractQuMatrix, op::AbstractQuMatrix) = trace(qarr*op)
209+
204210
export normalize,
205211
normalize!,
206212
tensor,
207213
commute,
208-
anticommute
214+
anticommute,
215+
expectation

test/multest.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ qv1 = normalize!(QuArray(v1))
5555

5656
# Vectorize
5757
@assert vec(qv) == vec(qv')
58+
59+
# Complex coeffs
60+
@assert complex(statevec(1, FiniteBasis(2))) == QuArray([1.+0.*im, 0.+0.*im])

0 commit comments

Comments
 (0)