Skip to content

Commit

Permalink
scale! used, added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
amitjamadagni committed Apr 18, 2015
1 parent 8972edd commit c26e0b4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/arrays/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function *{B<:OrthonormalBasis}(qm1::QuMatrix{B}, qm2::QuMatrix{B})
bases(qm2,2))
end

*(dm1::DualMatrix, dm2::DualMatrix) = QuArray(coeffs(dm1)*coeffs(dm2),bases(dm1,1), bases(dm2,2))
*(dm1::DualMatrix, dm2::DualMatrix) = (dm2.qarr*dm1.qarr)'

function +{B<:OrthonormalBasis,N}(qarr1::AbstractQuArray{B,N}, qarr2::AbstractQuArray{B,N})
if bases(qarr1) == bases(qarr2)
Expand Down Expand Up @@ -94,7 +94,7 @@ Base.scale(qarr::Union(QuArray,CTranspose), num::Number) = scale(num, qarr)
Base.full(qarr::AbstractQuMatrix) = QuArray(full(coeffs(qarr)),bases(qarr))

# exponential of dense matrix
Base.expm(qarr::AbstractQuMatrix) = QuArray(expm(coeffs(full(qarr))),bases(qarr))
Base.expm(qarr::AbstractQuMatrix) = QuArray(expm(full(coeffs(qarr))),bases(qarr))

# normalization
Base.norm(qarr::Union(QuArray,CTranspose)) = vecnorm(rawcoeffs(qarr))
Expand Down
8 changes: 4 additions & 4 deletions src/arrays/ladderops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ function momentumop(n::Int)
return scale(im/sqrt(2.), cop-cop')
end

squeeze_construct(a::AbstractQuMatrix,b::AbstractQuMatrix, z::Union(Complex64, Float64)) = 0.5*(z'*(a*b)-z*(a'*b'))
squeezing(a::AbstractQuMatrix, b::AbstractQuMatrix, z::Union(Complex64, Float64)) = expm(squeeze_construct(a,b,z))
squeeze(n::Int,z::Union(Complex64, Float64)) = squeezing(lowerop(n),lowerop(n),z)
squeeze_construct(a::AbstractQuMatrix,b::AbstractQuMatrix, z::Number) = scale!(0.5,(scale!(z',a*b)-scale!(z,a'*b')))
squeezing(a::AbstractQuMatrix, b::AbstractQuMatrix, z::Number) = expm(squeeze_construct(a,b,z))
squeeze(n::Int,z::Number) = squeezing(lowerop(n),lowerop(n),z)

displaceop(n::Int,alpha::Union(Complex64, Float64)) = expm(alpha*lowerop(n)'-alpha'*lowerop(n))
displaceop(n::Int,alpha::Number) = expm(scale!(alpha,lowerop(n)')-scale!(alpha',lowerop(n)))

export raiseop,
lowerop,
Expand Down
2 changes: 1 addition & 1 deletion test/multest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ qv = QuArray(v)
@test_approx_eq rawcoeffs(normalize(qv)) rawcoeffs(qv)/norm(v)

# a simple test of the `==` operator
@assert qm*3im == scale!(3im, copy(qm))
@assert qm*3im == scale!(3im, copy(qm))
8 changes: 8 additions & 0 deletions test/operatortest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ p = positionop(2)
m = momentumop(2)
@assert coeffs(commutator(sigma_x, p)) == spzeros(2,2)
@assert coeffs(commutator(sigma_y, m)) == spzeros(2,2)

#####################################
# Squeeze, Squeezing Operators Test #
#####################################

@assert squeeze(2,1.0)== QuArray(eye(2))
@assert squeezing(lowerop(2), lowerop(2), 1.0) == squeeze(2,1)

0 comments on commit c26e0b4

Please sign in to comment.