From 50406dca350844c678d42e28b42343083059c190 Mon Sep 17 00:00:00 2001 From: Amit Jamadagni Gangapuram Date: Tue, 22 Nov 2016 15:33:37 +0100 Subject: [PATCH] Warnings on version 0.5 --- src/arrays/arraymath.jl | 14 ++++++-------- src/arrays/ladderops.jl | 4 ++-- src/arrays/quarray.jl | 8 +++++--- test/labelbasistest.jl | 10 +++++----- test/multest.jl | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/arrays/arraymath.jl b/src/arrays/arraymath.jl index 4e7bdf9..6dd6766 100644 --- a/src/arrays/arraymath.jl +++ b/src/arrays/arraymath.jl @@ -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}) @@ -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 diff --git a/src/arrays/ladderops.jl b/src/arrays/ladderops.jl index 594fd6c..b7ef8da 100644 --- a/src/arrays/ladderops.jl +++ b/src/arrays/ladderops.jl @@ -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, diff --git a/src/arrays/quarray.jl b/src/arrays/quarray.jl index 90f0c15..fdc2fbf 100644 --- a/src/arrays/quarray.jl +++ b/src/arrays/quarray.jl @@ -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} @@ -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 ############## @@ -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) diff --git a/test/labelbasistest.jl b/test/labelbasistest.jl index b7e476a..efdbd2e 100644 --- a/test/labelbasistest.jl +++ b/test/labelbasistest.jl @@ -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] @@ -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] \ No newline at end of file +@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] diff --git a/test/multest.jl b/test/multest.jl index 00ac37e..e16f47c 100644 --- a/test/multest.jl +++ b/test/multest.jl @@ -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)