Skip to content

Commit

Permalink
Tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjamadagni committed Aug 5, 2015
1 parent 25862bd commit f555684
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/arrays/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function \{B<:OrthonormalBasis}(op::AbstractQuMatrix{B}, vec::AbstractQuVector{B
end

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

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

###############
# Expectaion #
###############
expectation(qarr::AbstractQuVector, op::AbstractQuMatrix) = vec(qarr)'*op*vec(qarr)
expectation(qarr::AbstractQuMatrix, op::AbstractQuMatrix) = trace(qarr*op)

export normalize,
normalize!,
tensor,
commute,
anticommute
anticommute,
expectation
3 changes: 3 additions & 0 deletions test/multest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ qv1 = normalize!(QuArray(v1))

# Vectorize
@assert vec(qv) == vec(qv')

# Complex coeffs
@assert complex(statevec(1, FiniteBasis(2))) == QuArray([1.+0.*im, 0.+0.*im])

0 comments on commit f555684

Please sign in to comment.