Skip to content

Commit

Permalink
remove Compat dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubin committed Sep 27, 2015
1 parent acd0496 commit 36b5e7a
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 39 deletions.
1 change: 0 additions & 1 deletion REQUIRE
Expand Up @@ -2,5 +2,4 @@ julia 0.4-rc2
MathProgBase 0.3.8 0.4.0-
ReverseDiffSparse 0.2.2
ArrayViews 0.4.12
Compat 0.7.1
Calculus
10 changes: 4 additions & 6 deletions src/JuMP.jl
Expand Up @@ -20,8 +20,6 @@ using ReverseDiffSparse, Calculus
import ArrayViews
const subarr = ArrayViews.view

using Compat

export
# Objects
Model, Variable, Norm, AffExpr, QuadExpr, SOCExpr, AbstractJuMPScalar,
Expand Down Expand Up @@ -77,7 +75,7 @@ type Model
colCat::Vector{Symbol}

# Variable cones of the form, e.g. (:SDP, 1:9)
varCones::Vector{@compat Tuple{Symbol,Any}}
varCones::Vector{Tuple{Symbol,Any}}

# Solution data
objVal
Expand Down Expand Up @@ -144,7 +142,7 @@ function Model(;solver=UnsetSolver())
Float64[], # colLower
Float64[], # colUpper
Symbol[], # colCat
Vector{@compat Tuple{Symbol,Any}}[], # varCones
Vector{Tuple{Symbol,Any}}[], # varCones
0, # objVal
Float64[], # colVal
Float64[], # redCosts
Expand Down Expand Up @@ -631,12 +629,12 @@ operator_warn(lhs,rhs) = nothing
##########################################################################
# Behavior that's uniform across all JuMP "scalar" objects

@compat typealias JuMPTypes Union{AbstractJuMPScalar,
typealias JuMPTypes Union{AbstractJuMPScalar,
Norm,
GenericAffExpr,
QuadExpr,
SOCExpr}
@compat typealias JuMPScalars Union{Number,JuMPTypes}
typealias JuMPScalars Union{Number,JuMPTypes}

# would really want to do this on ::Type{T}, but doesn't work on v0.4
Base.eltype{T<:JuMPTypes}(::T) = T
Expand Down
4 changes: 2 additions & 2 deletions src/JuMPContainer.jl
Expand Up @@ -53,7 +53,7 @@ Base.getindex(d::JuMPDict, t...) = d.tupledict[t]
Base.setindex!(d::JuMPDict, value, t...) = (d.tupledict[t] = value)

function Base.map{T,N}(f::Function, d::JuMPDict{T,N})
ret = Base.return_types(f, @compat(Tuple{T}))
ret = Base.return_types(f, Tuple{T})
R = (length(ret) == 1 ? ret[1] : Any)
x = JuMPDict{R,N}()
for (k,v) in d.tupledict
Expand Down Expand Up @@ -176,7 +176,7 @@ getmeta(x::JuMPContainer, sym::Symbol) = x.meta[sym]

# duck typing approach -- if eltype(innerArray) doesn't support accessor, will fail
for accessor in (:getDual, :getLower, :getUpper)
@eval @compat $accessor(x::Union{JuMPContainer,Array}) = map($accessor,x)
@eval $accessor(x::Union{JuMPContainer,Array}) = map($accessor,x)
end

_similar(x::Array) = Array(Float64,size(x))
Expand Down
3 changes: 0 additions & 3 deletions src/affexpr.jl
Expand Up @@ -76,9 +76,6 @@ end
# Alias for (Float64, Variable), the specific GenericAffExpr used by JuMP
typealias AffExpr GenericAffExpr{Float64,Variable}
AffExpr() = zero(AffExpr)
# TODO: remove following two lines when no longer supporting Julia v0.3
@compat AffExpr(x::Union{Number,Variable}) = convert(AffExpr, x)
AffExpr(x::AffExpr) = x

Base.isempty(a::AffExpr) = (length(a.vars) == 0 && a.constant == 0.)
Base.convert(::Type{AffExpr}, v::Variable) = AffExpr([v], [1.], 0.)
Expand Down
2 changes: 1 addition & 1 deletion src/callbacks.jl
Expand Up @@ -157,7 +157,7 @@ end


# TODO: Should this be somewhere else?
const sensemap = @compat Dict(:(<=) => '<', :(==) => '=', :(>=) => '>')
const sensemap = Dict(:(<=) => '<', :(==) => '=', :(>=) => '>')


## Lazy constraints
Expand Down
4 changes: 2 additions & 2 deletions src/macros.jl
Expand Up @@ -56,7 +56,7 @@ function buildrefsets(expr::Expr)
end

buildrefsets(c::Symbol) = (esc(c), Any[], Any[], IndexPair[], :())
@compat buildrefsets(c::Void) = (gensym(), Any[], Any[], IndexPair[], :())
buildrefsets(c::Void) = (gensym(), Any[], Any[], IndexPair[], :())

###############################################################################
# getloopedcode
Expand Down Expand Up @@ -154,7 +154,7 @@ function _localvar(x::Expr)
end

getname(c::Symbol) = c
@compat getname(c::Void) = ()
getname(c::Void) = ()
getname(c::Expr) = c.args[1]

validmodel(m::Model, name) = nothing
Expand Down
2 changes: 1 addition & 1 deletion src/nlp.jl
Expand Up @@ -593,7 +593,7 @@ function solvenlp(m::Model, traits; suppress_warnings=false)
end

# getValue for nonlinear subexpressions
@compat function getValue(x::Union{ReverseDiffSparse.ParametricExpressionWithParams,ReverseDiffSparse.ParametricExpression{0}})
function getValue(x::Union{ReverseDiffSparse.ParametricExpressionWithParams,ReverseDiffSparse.ParametricExpression{0}})
# messy check to extract model object
found = false
m = nothing
Expand Down
22 changes: 11 additions & 11 deletions src/operators.jl
Expand Up @@ -112,11 +112,11 @@ end
(-)(lhs::GenericAffExpr, rhs::Number) = (+)(-rhs,lhs)
(*)(lhs::GenericAffExpr, rhs::Number) = (*)(rhs,lhs)
(/)(lhs::GenericAffExpr, rhs::Number) = (*)(1.0/rhs,lhs)
@compat function (^)(lhs::Union{Variable,AffExpr}, rhs::Integer)
function (^)(lhs::Union{Variable,AffExpr}, rhs::Integer)
rhs == 2 || error("Only exponents of 2 are currently supported. Are you trying to build a nonlinear problem? Make sure you use @addNLConstraint/@setNLObjective.")
return lhs*lhs
end
@compat (^)(lhs::Union{Variable,AffExpr}, rhs::Number) = error("Only exponents of 2 are currently supported. Are you trying to build a nonlinear problem? Make sure you use @addNLConstraint/@setNLObjective.")
(^)(lhs::Union{Variable,AffExpr}, rhs::Number) = error("Only exponents of 2 are currently supported. Are you trying to build a nonlinear problem? Make sure you use @addNLConstraint/@setNLObjective.")
# AffExpr--Variable
(+){C,V<:JuMPTypes}(lhs::GenericAffExpr{C,V}, rhs::V) = (+)(rhs,lhs)
(-){C,V<:JuMPTypes}(lhs::GenericAffExpr{C,V}, rhs::V) = GenericAffExpr{C,V}(vcat(lhs.vars,rhs),vcat(lhs.coeffs,-one(C)),lhs.constant)
Expand Down Expand Up @@ -401,7 +401,7 @@ function _multiply!{T<:JuMPTypes}(ret::Array{T}, lhs::Array, rhs::Array)
ret
end

@compat function _multiply!{T<:Union{GenericAffExpr,GenericQuadExpr}}(ret::Array{T}, lhs::SparseMatrixCSC, rhs::Array)
function _multiply!{T<:Union{GenericAffExpr,GenericQuadExpr}}(ret::Array{T}, lhs::SparseMatrixCSC, rhs::Array)
nzv = lhs.nzval
rv = lhs.rowval
for col in 1:lhs.n
Expand All @@ -414,7 +414,7 @@ end
ret
end

@compat function _multiply!{T<:Union{GenericAffExpr,GenericQuadExpr}}(ret::Array{T}, lhs::Matrix, rhs::SparseMatrixCSC)
function _multiply!{T<:Union{GenericAffExpr,GenericQuadExpr}}(ret::Array{T}, lhs::Matrix, rhs::SparseMatrixCSC)
rowval = rhs.rowval
nzval = rhs.nzval
for multivec_row in 1:size(lhs,1)
Expand All @@ -435,9 +435,9 @@ _multiply!{T<:JuMPTypes}(ret::AbstractArray{T}, lhs::SparseMatrixCSC, rhs::Spars

_multiply!(ret, lhs, rhs) = A_mul_B!(ret, lhs, ret)

@compat (*){T<:JuMPTypes}( A::Union{Matrix{T},SparseMatrixCSC{T}}, x::Union{Matrix, Vector, SparseMatrixCSC}) = _matmul(A, x)
@compat (*){T<:JuMPTypes,R<:JuMPTypes}(A::Union{Matrix{T},SparseMatrixCSC{T}}, x::Union{Matrix{R},Vector{R},SparseMatrixCSC{R}}) = _matmul(A, x)
@compat (*){T<:JuMPTypes}( A::Union{Matrix, SparseMatrixCSC}, x::Union{Matrix{T},Vector{T},SparseMatrixCSC{T}}) = _matmul(A, x)
(*){T<:JuMPTypes}( A::Union{Matrix{T},SparseMatrixCSC{T}}, x::Union{Matrix, Vector, SparseMatrixCSC}) = _matmul(A, x)
(*){T<:JuMPTypes,R<:JuMPTypes}(A::Union{Matrix{T},SparseMatrixCSC{T}}, x::Union{Matrix{R},Vector{R},SparseMatrixCSC{R}}) = _matmul(A, x)
(*){T<:JuMPTypes}( A::Union{Matrix, SparseMatrixCSC}, x::Union{Matrix{T},Vector{T},SparseMatrixCSC{T}}) = _matmul(A, x)

function _matmul(A, x)
m, n = size(A,1), size(A,2)
Expand All @@ -463,7 +463,7 @@ function _fillwithzeros{T}(arr::Array{T})
end

# Let's be conservative and only define arithmetic for the basic types
@compat typealias ArrayOrSparseMat{T} Union{Array{T}, SparseMatrixCSC{T}}
typealias ArrayOrSparseMat{T} Union{Array{T}, SparseMatrixCSC{T}}

for op in [:+, :-]; @eval begin
function $op{T<:JuMPTypes}(lhs::Number,rhs::ArrayOrSparseMat{T})
Expand Down Expand Up @@ -599,11 +599,11 @@ for (func,_) in Calculus.symbolic_derivatives_1arg(), typ in [:Variable,:AffExpr
@eval Base.($(quot(func)))(::$typ) = error($errstr)
end

@compat *{T<:QuadExpr,S<:Union{Variable,AffExpr,QuadExpr}}(::T,::S) =
*{T<:QuadExpr,S<:Union{Variable,AffExpr,QuadExpr}}(::T,::S) =
error( "*(::$T,::$S) is not defined. $op_hint")
(*)(lhs::QuadExpr, rhs::QuadExpr) =
error( "*(::QuadExpr,::QuadExpr) is not defined. $op_hint")
@compat *{T<:QuadExpr,S<:Union{Variable,AffExpr,QuadExpr}}(::S,::T) =
*{T<:QuadExpr,S<:Union{Variable,AffExpr,QuadExpr}}(::S,::T) =
error( "*(::$S,::$T) is not defined. $op_hint")
@compat /{S<:Union{Number,Variable,AffExpr,QuadExpr},T<:Union{Variable,AffExpr,QuadExpr}}(::S,::T) =
/{S<:Union{Number,Variable,AffExpr,QuadExpr},T<:Union{Variable,AffExpr,QuadExpr}}(::S,::T) =
error( "/(::$S,::$T) is not defined. $op_hint")
14 changes: 7 additions & 7 deletions src/print.jl
Expand Up @@ -48,7 +48,7 @@ _values(x) = Base.values(x)
# REPL-specific symbols
# Anything here: https://en.wikipedia.org/wiki/Windows-1252
# should probably work fine on Windows
const repl = @compat Dict{Symbol,UTF8String}(
const repl = Dict{Symbol,UTF8String}(
:leq => (OS_NAME == :Windows ? "<=" : ""),
:geq => (OS_NAME == :Windows ? ">=" : ""),
:eq => (OS_NAME == :Windows ? "==" : "="),
Expand All @@ -71,7 +71,7 @@ const repl = @compat Dict{Symbol,UTF8String}(
:sub2 => (OS_NAME == :Windows ? "_2" : ""))

# IJulia-specific symbols
const ijulia = @compat Dict{Symbol,UTF8String}(
const ijulia = Dict{Symbol,UTF8String}(
:leq => "\\leq",
:geq => "\\geq",
:eq => "=",
Expand Down Expand Up @@ -309,7 +309,7 @@ function fill_var_names{N}(mode, colNames, v::JuMPArray{Variable,N})
for (ind,var) in enumerate(v.innerArray)
idx_strs = [string( idxsets[1][mod1(ind,lengths[1])] )]
for i = 2:N
push!(idx_strs, string(idxsets[i][@compat Int(ceil(mod1(ind,cprod[i]) / cprod[i-1]))]))
push!(idx_strs, string(idxsets[i][Int(ceil(mod1(ind,cprod[i]) / cprod[i-1]))]))
end
if mode == IJuliaMode
colNames[var.col] = string(name, "_{", join(idx_strs,",") , "}")
Expand Down Expand Up @@ -379,9 +379,9 @@ exprToStr(n::Norm) = norm_str(REPLMode, n)
#------------------------------------------------------------------------
## JuMPContainer{Variable}
#------------------------------------------------------------------------
@compat Base.print(io::IO, j::Union{JuMPContainer{Variable}, Array{Variable}}) = print(io, cont_str(REPLMode,j))
@compat Base.show( io::IO, j::Union{JuMPContainer{Variable}, Array{Variable}}) = print(io, cont_str(REPLMode,j))
@compat Base.writemime(io::IO, ::MIME"text/latex", j::Union{JuMPContainer{Variable},Array{Variable}}) =
Base.print(io::IO, j::Union{JuMPContainer{Variable}, Array{Variable}}) = print(io, cont_str(REPLMode,j))
Base.show( io::IO, j::Union{JuMPContainer{Variable}, Array{Variable}}) = print(io, cont_str(REPLMode,j))
Base.writemime(io::IO, ::MIME"text/latex", j::Union{JuMPContainer{Variable},Array{Variable}}) =
print(io, cont_str(IJuliaMode,j,mathmode=false))
# Generic string converter, called by mode-specific handlers

Expand Down Expand Up @@ -492,7 +492,7 @@ function cont_str(mode, j, sym::PrintSymbols)
end

# UTILITY FUNCTIONS FOR cont_str
@compat function cont_str_set(idxset::Union{Range,Array}, dots) # 2:2:20 -> {2,4..18,20}
function cont_str_set(idxset::Union{Range,Array}, dots) # 2:2:20 -> {2,4..18,20}
length(idxset) == 1 && return string(idxset[1])
length(idxset) == 2 && return string(idxset[1],",",idxset[2])
length(idxset) == 3 && return string(idxset[1],",",idxset[2],",",idxset[3])
Expand Down
2 changes: 1 addition & 1 deletion src/quadexpr.jl
Expand Up @@ -63,7 +63,7 @@ end

# Alias for (Float64, Variable)
typealias QuadExpr GenericQuadExpr{Float64,Variable}
@compat Base.convert(::Type{QuadExpr}, v::Union{Real,Variable,AffExpr}) = QuadExpr(Variable[], Variable[], Float64[], AffExpr(v))
Base.convert(::Type{QuadExpr}, v::Union{Real,Variable,AffExpr}) = QuadExpr(Variable[], Variable[], Float64[], AffExpr(v))
QuadExpr() = zero(QuadExpr)

function setObjective(m::Model, sense::Symbol, q::QuadExpr)
Expand Down
8 changes: 4 additions & 4 deletions src/solvers.jl
Expand Up @@ -312,7 +312,7 @@ function addQuadratics(m::Model)
end

# Add quadratic constraint to solver
const sensemap = @compat Dict(:(<=) => '<', :(>=) => '>', :(==) => '=')
const sensemap = Dict(:(<=) => '<', :(>=) => '>', :(==) => '=')
for k in 1:length(m.quadconstr)
qconstr = m.quadconstr[k]::QuadConstraint
if !haskey(sensemap, qconstr.sense)
Expand Down Expand Up @@ -630,9 +630,9 @@ function conicconstraintdata(m::Model)
I = Int[]
J = Int[]
V = Float64[]
@compat sizehint!(I, nnz)
@compat sizehint!(J, nnz)
@compat sizehint!(V, nnz)
sizehint!(I, nnz)
sizehint!(J, nnz)
sizehint!(V, nnz)

# Fill it up
nnz = 0
Expand Down

0 comments on commit 36b5e7a

Please sign in to comment.