From f55568425fe4ce574266a891f5a09b4857ec0b49 Mon Sep 17 00:00:00 2001 From: amitjamadagni Date: Mon, 13 Jul 2015 09:17:04 +0800 Subject: [PATCH] Tests added. --- src/arrays/arraymath.jl | 11 +++++++++-- test/multest.jl | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/arrays/arraymath.jl b/src/arrays/arraymath.jl index 743c777..6ca9aa8 100644 --- a/src/arrays/arraymath.jl +++ b/src/arrays/arraymath.jl @@ -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))) @@ -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 diff --git a/test/multest.jl b/test/multest.jl index fb93748..946d10f 100644 --- a/test/multest.jl +++ b/test/multest.jl @@ -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])