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

Add support for Julia v0.6 [Initial Build] #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.3 0.4-
julia 0.6
Compat
Iterators
Iterators
42 changes: 21 additions & 21 deletions src/QuDirac.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module QuDirac

using Compat
using Iterators.product

if !(v"0.3-" <= VERSION < v"0.4-")
warn("QuDirac v0.1 only officially supports the v0.3 release of Julia. Your version of Julia is $VERSION.")
if !(VERSION < v"0.6")
warn("QuDirac v0.1 only officially supports the v0.6 release of Julia. Your version of Julia is $VERSION.")
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole warning should probably go away, any version handling should just go into the REQUIRE anyway


####################
# String Constants #
####################
Expand All @@ -18,21 +18,21 @@ module QuDirac
##################
# Abstract Types #
##################
abstract AbstractInner
immutable UndefinedInner <: AbstractInner end
abstract type AbstractInner end

immutable UndefinedInner <: AbstractInner end
immutable KroneckerDelta <: AbstractInner end

abstract AbstractDirac{P<:AbstractInner,N}
abstract DiracOp{P,N} <: AbstractDirac{P,N}
abstract DiracState{P,N} <: AbstractDirac{P,N}

abstract DiracScalar <: Number
abstract type AbstractDirac{P<:AbstractInner,N} end
abstract type DiracOp{P,N} <: AbstractDirac{P,N} end
abstract type DiracState{P,N} <: AbstractDirac{P,N} end

abstract type DiracScalar <: Number end

#############
# Functions #
#############
# These functions will be in
# These functions will be in
# QuBase when it releases
tensor() = error("Cannot call tensor function without arguments")
tensor(s...) = reduce(tensor, s)
Expand All @@ -49,19 +49,19 @@ module QuDirac
include("dictfuncs.jl")
include("mapfuncs.jl")
include("str_macros.jl")

#################
# default_inner #
#################
# Julia doesn't recompile functions within other
# previously compiled functions, so we can't have a
# Julia doesn't recompile functions within other
# previously compiled functions, so we can't have a
# get_default_inner() or something like that.
#
# Also, global optimization is poor, so we don't want
# to use that either. Thus, we go for a function that
# straight-up redefines the default constructors for
# the relevant objects. This is hacky, but works for now,
# seeing as how only a few functions actually "use"
# straight-up redefines the default constructors for
# the relevant objects. This is hacky, but works for now,
# seeing as how only a few functions actually "use"
# the default ptype.
function default_inner(ptype::AbstractInner)
QuDirac.OpSum(dict::Dict) = OpSum(ptype, dict)
Expand All @@ -80,8 +80,8 @@ module QuDirac
AbstractDirac,
DiracState,
DiracOp,
# All functions that conflict
# with QuBase should be exported
# All functions that conflict
# with QuBase should be exported
# below:
tensor,
commute,
Expand Down
72 changes: 36 additions & 36 deletions src/innerexpr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ klabel(i::InnerProduct) = i.k
Base.repr(i::InnerProduct) = brstr(blabel(i))*ktstr(klabel(i))[2:end]
Base.show(io::IO, i::InnerProduct) = print(io, repr(i))

Base.(:(==))(a::InnerProduct, b::InnerProduct) = blabel(a) == blabel(b) && klabel(a) == klabel(b)
Base.(:(==))(::InnerProduct, ::Number) = false
Base.(:(==))(::Number, ::InnerProduct) = false
Base.:(==)(a::InnerProduct, b::InnerProduct) = blabel(a) == blabel(b) && klabel(a) == klabel(b)
Base.:(==)(::InnerProduct, ::Number) = false
Base.:(==)(::Number, ::InnerProduct) = false

Base.hash(i::InnerProduct) = hash(blabel(i), hash(klabel(i)))
Base.hash(i::InnerProduct, h::Uint64) = hash(hash(i), h)
Base.hash(i::InnerProduct, h::UInt64) = hash(hash(i), h)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be UInt instead of UInt64 (to accommodate 32-bit systems)


Base.conj(i::InnerProduct) = InnerProduct(klabel(i), blabel(i))

Expand All @@ -26,7 +26,7 @@ Base.conj(i::InnerProduct) = InnerProduct(klabel(i), blabel(i))
##############

# we can cheat here to avoid tempory StateLabel construction
# to evaluate KroneckerDelta inner products
# to evaluate KroneckerDelta inner products
eval_inner_rule(p::KroneckerDelta, b, k) = inner_rule(p, b, k)
eval_inner_rule(p::KroneckerDelta, b::StateLabel, k::StateLabel) = inner_rule(p, b, k)

Expand All @@ -48,10 +48,10 @@ inner_mul(v,c,prodtype,b,k) = v * c * eval_inner_rule(prodtype, b, k)
# InnerExpr #
##############
# A InnerExpr is a type that wraps arthimetic expressions
# performed with InnerExprs. The allows storage and
# delayed evaluation of expressions. For example, this
# performed with InnerExprs. The allows storage and
# delayed evaluation of expressions. For example, this
# expression:
#
#
# (< a | b >^2 + < c | d >^2 - 3.13+im) / 2
#
# is representable as a InnerExpr.
Expand All @@ -66,7 +66,7 @@ InnerExpr{N<:Number}(n::N) = convert(InnerExpr, n)
Base.convert(::Type{InnerExpr}, iex::InnerExpr) = iex
Base.convert{N<:Number}(::Type{InnerExpr}, n::N) = InnerExpr(Expr(:call, +, n))

Base.(:(==))(a::InnerExpr, b::InnerExpr) = a.ex == b.ex
Base.:(==)(a::InnerExpr, b::InnerExpr) = a.ex == b.ex
same_num(a::Number, b::Number) = a == b
same_num(a::InnerExpr, b::InnerExpr) = a == b
same_num(iex::InnerExpr, i::InnerProduct) = iex == InnerExpr(i)
Expand All @@ -75,15 +75,15 @@ same_num(iex::InnerExpr, n::Number) = iex == InnerExpr(n)
same_num(n::Number, iex::InnerExpr) = iex == n

Base.hash(iex::InnerExpr) = hash(iex.ex)
Base.hash(iex::InnerExpr, h::Uint64) = hash(hash(iex), h)
Base.hash(iex::InnerExpr, h::UInt64) = hash(hash(iex), h)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - UInt64 --> UInt


Base.one(::InnerExpr) = InnerExpr(1)
Base.zero(::InnerExpr) = InnerExpr(0)

Base.promote_rule{N<:Number}(::Type{InnerExpr}, ::Type{N}) = InnerExpr

Base.length(iex::InnerExpr) = length(iex.ex.args)
Base.getindex(iex::InnerExpr, i) = iex.ex.args[i]
Base.getindex(iex::InnerExpr, i::Integer) = iex.ex.args[i]

##############
# inner_eval #
Expand Down Expand Up @@ -123,20 +123,20 @@ function iexpr_exp(a, b)
end
end

Base.(:^)(a::InnerExpr, b::Integer) = iexpr_exp(a, b)
Base.(:^)(a::InnerExpr, b::Rational) = iexpr_exp(a, b)
Base.(:^)(a::InnerExpr, b::InnerExpr) = iexpr_exp(a, b)
Base.(:^)(a::InnerExpr, b::Number) = iexpr_exp(a, b)
Base.(:^)(a::MathConst{:e}, b::InnerExpr) = iexpr_exp(a, b)
Base.(:^)(a::Number, b::InnerExpr) = iexpr_exp(a, b)
Base.:^(a::InnerExpr, b::Integer) = iexpr_exp(a, b)
Base.:^(a::InnerExpr, b::Rational) = iexpr_exp(a, b)
Base.:^(a::InnerExpr, b::InnerExpr) = iexpr_exp(a, b)
Base.:^(a::InnerExpr, b::Number) = iexpr_exp(a, b)
#Base.:^(a::MathConst{:e}, b::InnerExpr) = iexpr_exp(a, b)
Base.:^(a::Number, b::InnerExpr) = iexpr_exp(a, b)

Base.exp(iex::InnerExpr) = InnerExpr(:(exp($(iex))))
Base.exp2(iex::InnerExpr) = InnerExpr(:(exp2($(iex))))

Base.sqrt(iex::InnerExpr) = InnerExpr(:(sqrt($(iex))))

Base.log(iex::InnerExpr) = length(iex)==2 && iex[1]==:exp ? iex[2] : InnerExpr(:(log($(iex))))
Base.log(a::MathConst{:e}, b::InnerExpr) = InnerExpr(:(log($(a),$(b))))
#Base.log(a::MathConst{:e}, b::InnerExpr) = InnerExpr(:(log($(a),$(b))))
Base.log(a::InnerExpr, b::InnerExpr) = InnerExpr(:(log($(a),$(b))))
Base.log(a::InnerExpr, b::Number) = InnerExpr(:(log($(a),$(b))))
Base.log(a::Number, b::InnerExpr) = InnerExpr(:(log($(a),$(b))))
Expand All @@ -157,11 +157,11 @@ function iexpr_mul(a,b)
end
end

Base.(:*)(a::InnerExpr, b::InnerExpr) =iexpr_mul(a,b)
Base.(:*)(a::Bool, b::InnerExpr) = iexpr_mul(a,b)
Base.(:*)(a::InnerExpr, b::Bool) = iexpr_mul(a,b)
Base.(:*)(a::InnerExpr, b::Number) = iexpr_mul(a,b)
Base.(:*)(a::Number, b::InnerExpr) = iexpr_mul(a,b)
Base.:*(a::InnerExpr, b::InnerExpr) =iexpr_mul(a,b)
Base.:*(a::Bool, b::InnerExpr) = iexpr_mul(a,b)
Base.:*(a::InnerExpr, b::Bool) = iexpr_mul(a,b)
Base.:*(a::InnerExpr, b::Number) = iexpr_mul(a,b)
Base.:*(a::Number, b::InnerExpr) = iexpr_mul(a,b)

############
# Division #
Expand All @@ -180,16 +180,16 @@ function iexpr_div(a, b)
end
end

Base.(:/)(a::InnerExpr, b::InnerExpr) = iexpr_div(a, b)
Base.(:/)(a::InnerExpr, b::Complex) = iexpr_div(a, b)
Base.(:/)(a::InnerExpr, b::Number) = iexpr_div(a, b)
Base.(:/)(a::Number, b::InnerExpr) = iexpr_div(a, b)
Base.:/(a::InnerExpr, b::InnerExpr) = iexpr_div(a, b)
Base.:/(a::InnerExpr, b::Complex) = iexpr_div(a, b)
Base.:/(a::InnerExpr, b::Number) = iexpr_div(a, b)
Base.:/(a::Number, b::InnerExpr) = iexpr_div(a, b)

############
# Addition #
############
function iexpr_add(a, b)
if same_num(a, 0)
if same_num(a, 0)
return InnerExpr(b)
elseif same_num(b, 0)
return InnerExpr(a)
Expand All @@ -198,14 +198,14 @@ function iexpr_add(a, b)
end
end

Base.(:+)(a::InnerExpr, b::InnerExpr) = iexpr_add(a, b)
Base.(:+)(a::InnerExpr, b::Number) = iexpr_add(a, b)
Base.(:+)(a::Number, b::InnerExpr) = iexpr_add(a, b)
Base.:+(a::InnerExpr, b::InnerExpr) = iexpr_add(a, b)
Base.:+(a::InnerExpr, b::Number) = iexpr_add(a, b)
Base.:+(a::Number, b::InnerExpr) = iexpr_add(a, b)

###############
# Subtraction #
###############
Base.(:-)(iex::InnerExpr) = length(iex)==2 && iex[1]==:- ? InnerExpr(iex[2]) : InnerExpr(:(-$(iex)))
Base.:-(iex::InnerExpr) = length(iex)==2 && iex[1]==:- ? InnerExpr(iex[2]) : InnerExpr(:(-$(iex)))

function iexpr_subtract(a, b)
if same_num(a, b)
Expand All @@ -219,9 +219,9 @@ function iexpr_subtract(a, b)
end
end

Base.(:-)(a::InnerExpr, b::InnerExpr) = iexpr_subtract(a, b)
Base.(:-)(a::InnerExpr, b::Number) = iexpr_subtract(a, b)
Base.(:-)(a::Number, b::InnerExpr) = iexpr_subtract(a, b)
Base.:-(a::InnerExpr, b::InnerExpr) = iexpr_subtract(a, b)
Base.:-(a::InnerExpr, b::Number) = iexpr_subtract(a, b)
Base.:-(a::Number, b::InnerExpr) = iexpr_subtract(a, b)

##################
# Absolute Value #
Expand All @@ -239,7 +239,7 @@ Base.ctranspose(iex::InnerExpr) = conj(iex)
# Elementwise Operations #
##########################
for op=(:*,:-,:+,:/,:^)
elop = symbol(string(:.) * string(op))
elop = Symbol(string(:.) * string(op))
@eval begin
($elop)(a::InnerExpr, b::InnerExpr) = ($op)(a,b)
($elop)(a::InnerExpr, b::Number) = ($op)(a,b)
Expand Down
22 changes: 11 additions & 11 deletions src/labels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
##############
immutable StateLabel{N}
label::NTuple{N}
hash::Uint64
StateLabel(label::NTuple{N}) = new(label, hash(label))
StateLabel(label::NTuple{N}, h::Uint64) = new(label, h)
hash::UInt64
StateLabel{N}(label::NTuple{N}) where N = new(label, hash(label))
StateLabel{N}(label::NTuple{N}, h::UInt64) where N = new(label, h)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more UInt64 --> UInt situations. It seems there are a bunch of these - they should all get fixed, but I'll just stop commenting on them.

end

StateLabel(s::StateLabel) = s
Expand All @@ -18,9 +18,9 @@ Base.getindex(s::StateLabel, arr::AbstractArray) = s.label[arr]

Base.copy{N}(s::StateLabel{N}) = StateLabel{N}(s.label, s.hash)
Base.hash(s::StateLabel) = s.hash
Base.hash(s::StateLabel, h::Uint64) = hash(hash(s), h)
Base.hash(s::StateLabel, h::UInt64) = hash(hash(s), h)

Base.(:(==)){N}(a::StateLabel{N},b::StateLabel{N}) = hash(a) == hash(b)
Base.:(==){N}(a::StateLabel{N},b::StateLabel{N}) = hash(a) == hash(b)

Base.start(s::StateLabel) = start(s.label)
Base.next(s::StateLabel, i) = next(s.label, i)
Expand All @@ -32,7 +32,7 @@ Base.endof(s::StateLabel) = endof(s.label)

Base.length{N}(::StateLabel{N}) = N

Base.map(f::Union(Function,DataType), s::StateLabel) = StateLabel(map(f, s.label))
#Base.map(f::Union(Function,DataType), s::StateLabel) = StateLabel(map(f, s.label))

tensor(a::StateLabel, b::StateLabel) = StateLabel(tuple(a.label..., b.label...))

Expand All @@ -46,9 +46,9 @@ Base.show(io::IO, s::StateLabel) = print(io, repr(s))
immutable OpLabel{N}
k::StateLabel{N}
b::StateLabel{N}
hash::Uint64
OpLabel(k::StateLabel{N}, b::StateLabel{N}) = new(k, b, hash(k, hash(b)))
OpLabel(k::StateLabel{N}, b::StateLabel{N}, h::Uint64) = new(k, b, h)
hash::UInt64
OpLabel{N}(k::StateLabel{N}, b::StateLabel{N}) where N = new(k, b, hash(k, hash(b)))
OpLabel{N}(k::StateLabel{N}, b::StateLabel{N}, h::UInt64) where N = new(k, b, h)
end

OpLabel(op::OpLabel) = op
Expand All @@ -61,9 +61,9 @@ blabel(o::OpLabel) = o.b

Base.copy{N}(o::OpLabel{N}) = OpLabel{N}(o.k, o.b, o.hash)
Base.hash(o::OpLabel) = o.hash
Base.hash(o::OpLabel, h::Uint64) = hash(hash(o), h)
Base.hash(o::OpLabel, h::UInt64) = hash(hash(o), h)

Base.(:(==)){N}(a::OpLabel{N}, b::OpLabel{N}) = hash(a) == hash(b)
Base.:(==){N}(a::OpLabel{N}, b::OpLabel{N}) = hash(a) == hash(b)

Base.length{N}(::OpLabel{N}) = N

Expand Down
36 changes: 18 additions & 18 deletions src/mapfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,36 @@ Base.filter(f::Function, op::OuterProduct) = filter(f, convert(OpSum, op))
########################
# mapcoeffs!/mapcoeffs #
########################
mapcoeffs!(f::Union(Function,DataType), k::Ket) = (mapvals!(f, dict(k)); return k)
mapcoeffs!(f::Union(Function,DataType), b::Bra) = (mapvals!(v->f(v')', dict(b)); return b)
mapcoeffs!(f::Union(Function,DataType), op::OpSum) = (mapvals!(f, dict(op)); return op)
mapcoeffs!(f::Union(Function,DataType), opc::DualOpSum) = (mapvals!(v->f(v')', dict(opc)); return opc)
mapcoeffs!(f::Function, k::Ket) = (mapvals!(f, dict(k)); return k)
mapcoeffs!(f::Function, b::Bra) = (mapvals!(v->f(v')', dict(b)); return b)
mapcoeffs!(f::Function, op::OpSum) = (mapvals!(f, dict(op)); return op)
mapcoeffs!(f::Function, opc::DualOpSum) = (mapvals!(v->f(v')', dict(opc)); return opc)

mapcoeffs(f::Union(Function,DataType), kt::Ket) = similar(kt, mapvals(f, dict(kt)))
mapcoeffs(f::Union(Function,DataType), br::Bra) = similar(br, mapvals(v->f(v')', dict(br)))
mapcoeffs(f::Union(Function,DataType), op::OpSum) = similar(op, mapvals(f, dict(op)))
mapcoeffs(f::Union(Function,DataType), opc::DualOpSum) = similar(opc, mapvals(v->f(v')', dict(opc)))
mapcoeffs(f::Union(Function,DataType), op::OuterProduct) = mapcoeffs(f, convert(OpSum, op))
mapcoeffs(f::Function, kt::Ket) = similar(kt, mapvals(f, dict(kt)))
mapcoeffs(f::Function, br::Bra) = similar(br, mapvals(v->f(v')', dict(br)))
mapcoeffs(f::Function, op::OpSum) = similar(op, mapvals(f, dict(op)))
mapcoeffs(f::Function, opc::DualOpSum) = similar(opc, mapvals(v->f(v')', dict(opc)))
mapcoeffs(f::Function, op::OuterProduct) = mapcoeffs(f, convert(OpSum, op))

########################
# maplabels!/maplabels #
########################
maplabels(f::Union(Function,DataType), s::DiracState) = similar(s, mapkeys(f, dict(s)))
maplabels(f::Union(Function,DataType), op::OpSum) = similar(op, mapkeys(f, dict(op)))
maplabels(f::Union(Function,DataType), opc::DualOpSum) = OpSum(ptype(opc), mapkeys(label->f(label'), dict(op)))
maplabels(f::Union(Function,DataType), op::OuterProduct) = maplabels(f, convert(OpSum, op))
maplabels(f::Function, s::DiracState) = similar(s, mapkeys(f, dict(s)))
maplabels(f::Function, op::OpSum) = similar(op, mapkeys(f, dict(op)))
maplabels(f::Function, opc::DualOpSum) = OpSum(ptype(opc), mapkeys(label->f(label'), dict(op)))
maplabels(f::Function, op::OuterProduct) = maplabels(f, convert(OpSum, op))

#######
# map #
#######
Base.map(f::Union(Function,DataType), obj::AbstractDirac) = similar(obj, mapkv(kv->f(kv[1], kv[2]), dict(obj)))
Base.map(f::Union(Function,DataType), br::Bra) = similar(br, mapkv(kv->br_tup(f(kv[1], kv[2]')), dict(d)))
Base.map(f::Union(Function,DataType), opc::DualOpSum) = OpSum(ptype(opc), mapkv(kv->f(kv[1]', kv[2]'), dict(d)))
Base.map(f::Union(Function,DataType), op::OuterProduct) = map(f, convert(OpSum, op))
Base.map(f::Function, obj::AbstractDirac) = similar(obj, mapkv(kv->f(kv[1], kv[2]), dict(obj)))
Base.map(f::Function, br::Bra) = similar(br, mapkv(kv->br_tup(f(kv[1], kv[2]')), dict(d)))
Base.map(f::Function, opc::DualOpSum) = OpSum(ptype(opc), mapkv(kv->f(kv[1]', kv[2]'), dict(d)))
Base.map(f::Function, op::OuterProduct) = map(f, convert(OpSum, op))

br_tup(tup) = (tup[1], tup[2]')

export maplabels!,
mapcoeffs!,
maplabels,
mapcoeffs
mapcoeffs
Loading