Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings on version 0.5 #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/arrays/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,15 @@ Base.scale!(num::Number, qarr::AbstractQuArray) = (scale!(num, rawcoeffs(qarr));
Base.scale!(num::Number, ct::CTranspose) = CTranspose(scale!(num', ct.qarr))
Base.scale!(qarr::AbstractQuArray, num::Number) = scale!(num, qarr)

function Base.scale(num::Number, qarr::AbstractQuArray)
fc = scale(num, rawcoeffs(qarr))
function *(num::Number, qarr::AbstractQuArray)
fc = num*rawcoeffs(qarr)
QAT = similar_type(qarr)
return QAT(fc, bases(qarr))
end
Base.scale(num::Number, ct::CTranspose) = CTranspose(scale(num', ct.qarr))
Base.scale(qarr::AbstractQuArray, num::Number) = scale(num, qarr)

*(num::Number, qarr::AbstractQuArray) = scale(num, qarr)
*(qarr::AbstractQuArray, num::Number) = scale(qarr, num)
/(qarr::AbstractQuArray, num::Number) = scale(1/num, qarr)
*(num::Number, ct::CTranspose) = CTranspose(num'*ct.qarr)
*(qarr::AbstractQuArray, num::Number) = num*qarr
/(qarr::AbstractQuArray, num::Number) = 1/num*qarr

# Matrix Division, A*X=B, X = \(A,B), where A and B are of type AbstractQuMatrix
function \{B<:OrthonormalBasis}(qm1::AbstractQuMatrix{B}, qm2::AbstractQuMatrix{B})
Expand Down Expand Up @@ -148,7 +146,7 @@ function Compat.normalize!(qarr::AbstractQuArray)
return qarr
end

Compat.normalize(qarr::AbstractQuArray) = normalize!(copy(qarr))
Compat.normalize(qarr::AbstractQuArray) = normalize!(identity(qarr))

# matrix operations returning an array
# sparse to dense
Expand Down
4 changes: 2 additions & 2 deletions src/arrays/ladderops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ end

function momentumop(n::Int)
cop = raiseop(n)
return scale(im/sqrt(2.), cop-cop')
return (im/sqrt(2.))*(cop-cop')
end

squeeze_construct(a::AbstractQuMatrix,b::AbstractQuMatrix, z::Number) = scale!(0.5,(scale!(z',a*b)-scale!(z,a'*b')))
squeezingop(a::AbstractQuMatrix, b::AbstractQuMatrix, z::Number) = expm(squeeze_construct(a,b,z))
squeezingop(n::Int,z::Number) = squeezingop(lowerop(n),lowerop(n),z)

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

export raiseop,
lowerop,
Expand Down
8 changes: 5 additions & 3 deletions src/arrays/quarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

Base.in(c, qarr::AbstractQuArray) = in(c, rawcoeffs(qarr))

Base.(:(==))(a::AbstractQuArray, b::AbstractQuArray) = coeffs(a)==coeffs(b) && bases(a)==bases(b)
Base.:(==)(a::AbstractQuArray, b::AbstractQuArray) = coeffs(a)==coeffs(b) && bases(a)==bases(b)

typealias AbstractQuVector{B<:AbstractBasis,T} AbstractQuArray{B,T,1}
typealias AbstractQuMatrix{B<:AbstractBasis,T} AbstractQuArray{B,T,2}
Expand Down Expand Up @@ -80,7 +80,8 @@
########################
# Array-like functions #
########################
Base.copy(qa::QuArray) = QuArray(copy(qa.coeffs), copy(qa.bases))
Base.copy(qa::QuArray) = QuArray(identity(qa.coeffs), identity(qa.bases))
Base.identity(qa::QuArray) = QuArray(identity(qa.coeffs), identity(qa.bases))
Base.eltype{B,T,N,A}(::Type{QuArray{B,T,N,A}}) = T

##############
Expand Down Expand Up @@ -125,7 +126,8 @@
########################
Base.eltype{B,T,N,Q}(::Type{CTranspose{B,T,N,Q}}) = T

Base.copy(ct::CTranspose) = CTranspose(copy(ct.qarr))
Base.copy(ct::CTranspose) = CTranspose(identity(ct.qarr))
Base.identity(ct::CTranspose) = CTranspose(identity(ct.qarr))

Base.ndims(ct::CTranspose) = ndims(ct.qarr)
Base.length(ct::CTranspose) = length(ct.qarr)
Expand Down
10 changes: 5 additions & 5 deletions test/labelbasistest.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
m = [1+1im 2+2im 3+3im 4+4im;
5+5im 6+6im 7+7im 8+8im;
m = [1+1im 2+2im 3+3im 4+4im;
5+5im 6+6im 7+7im 8+8im;
9+9im 10+10im 11+11im 12+12im;
13+13im 14+14im 15+15im 16+16im]

Expand All @@ -17,6 +17,6 @@ qm_qm[(2,0,1,0),(1,1,0,1)] = 123
x2subspace = [filter((x...)->sum(x...)==2, QuBase.bases(qm_qm,2))...]
@assert x2subspace == [(1,1,0,0),(1,0,1,0),(0,1,1,0),(1,0,0,1),(0,1,0,1),(0,0,1,1)]

@assert qm_qm[(3,0,3,0), x2subspace] == [0+416im 0+392im 0+420im 0+420im 0+450im 0+416im]
qm_qm[(3,0,3,0), x2subspace] = [1 2 3 4 5 6]
@assert qm_qm[(3,0,3,0), x2subspace] == [1 2 3 4 5 6]
@assert qm_qm[(3,0,3,0), x2subspace] == [0+416im, 0+392im, 0+420im, 0+420im, 0+450im, 0+416im]
qm_qm[(3,0,3,0), x2subspace] = [1, 2, 3, 4, 5, 6]
@assert qm_qm[(3,0,3,0), x2subspace] == [1, 2, 3, 4, 5, 6]
2 changes: 1 addition & 1 deletion test/multest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ qv = QuArray(v)

@assert coeffs(2*im*qv) == 2*im*v
@assert coeffs(qv/2) == v/2
@assert coeffs(scale(2,qv)) == 2*v
@assert coeffs(2*qv) == 2*v
@assert coeffs(qm' * -im) == -im * m'
@assert norm(qv) == norm(v)
@test_approx_eq coeffs(normalize(qv)) coeffs(qv)/norm(v)
Expand Down