Skip to content

Commit

Permalink
Merge fda156b into d2040b6
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Aug 24, 2018
2 parents d2040b6 + fda156b commit eeb2d6e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 20 deletions.
8 changes: 1 addition & 7 deletions .travis.yml
Expand Up @@ -5,6 +5,7 @@ os:
julia:
- 0.6
- 0.7
- 1.0
# This is left as an example for the next big version switch.
# matrix:
# allow_failures:
Expand All @@ -17,13 +18,6 @@ addons:
- gfortran
- liblapack-dev
- libblas-dev
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd())'
- julia -e 'Pkg.test("JuMP", coverage=true)'
# - julia test/hygiene.jl
# - julia -e 'Pkg.add("Ipopt")' # needed for below tests
# - julia test/hockschittkowski/runhs.jl
after_success:
- echo $TRAVIS_JULIA_VERSION
- julia -e 'Pkg.add("Coverage"); cd(Pkg.dir("JuMP")); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())'
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Expand Up @@ -2,6 +2,7 @@ environment:
matrix:
- julia_version: 0.6
- julia_version: 0.7
- julia_version: 1.0

platform:
- x86 # 32-bit
Expand Down
9 changes: 9 additions & 0 deletions src/JuMP.jl
Expand Up @@ -245,6 +245,11 @@ function direct_model(backend::MOI.ModelLike)
Dict{Symbol, Any}())
end

if VERSION >= v"0.7-"
Base.broadcastable(model::Model) = Ref(model)
end


# In Automatic and Manual mode, `model.moibackend` is either directly the
# `CachingOptimizer` if `bridge_constraints=false` was passed in the constructor
# or it is a `LazyBridgeOptimizer` and the `CachingOptimizer` is stored in the
Expand Down Expand Up @@ -466,6 +471,10 @@ struct ConstraintRef{M <: AbstractModel, C, Shape <: AbstractShape}
shape::Shape
end

if VERSION >= v"0.7-"
Base.broadcastable(cref::ConstraintRef) = Ref(cref)
end

# TODO: should model be a parameter here?
function MOI.delete!(m::Model, cr::ConstraintRef{Model})
@assert m === cr.m
Expand Down
3 changes: 3 additions & 0 deletions src/affexpr.jl
Expand Up @@ -76,6 +76,9 @@ Base.one(::Type{GenericAffExpr{C,V}}) where {C,V} = GenericAffExpr{C,V}(one(C),
Base.zero(a::GenericAffExpr) = zero(typeof(a))
Base.one( a::GenericAffExpr) = one(typeof(a))
Base.copy(a::GenericAffExpr) = GenericAffExpr(copy(a.constant), copy(a.terms))
if VERSION >= v"0.7-"
Base.broadcastable(a::GenericAffExpr) = Ref(a)
end

GenericAffExpr{C, V}() where {C, V} = zero(GenericAffExpr{C, V})

Expand Down
2 changes: 1 addition & 1 deletion src/macros.jl
Expand Up @@ -285,7 +285,7 @@ function parse_one_operator_constraint(_error::Function, vectorized::Bool, ::Val
newaff, parseaff = parseExprToplevel(aff, :q)
parsecode = :(q = Val{false}(); $parseaff)
if vectorized
buildcall = :(buildconstraint.($_error, $newaff, $(esc(set))))
buildcall = :(buildconstraint.($_error, $newaff, Ref($(esc(set)))))
else
buildcall = :(buildconstraint($_error, $newaff, $(esc(set))))
end
Expand Down
6 changes: 1 addition & 5 deletions src/parseexpr.jl
Expand Up @@ -280,11 +280,7 @@ function destructive_add!(ex::AbstractArray{<:GenericAffExpr}, c::Number,
end


destructive_add!(ex, c, x) = ex + c*x
destructive_add!(ex, c, x::AbstractArray) = (ex,) .+ c*x
destructive_add!(ex::AbstractArray, c, x) = ex .+ (c*x,)
destructive_add!(ex::AbstractArray, c::AbstractArray, x) = ex .+ c*x
destructive_add!(ex::AbstractArray, c, x::AbstractArray) = ex .+ c*x
destructive_add!(ex, c, x) = ex .+ c * x

destructive_add_with_reorder!(ex, arg) = destructive_add!(ex, 1.0, arg)
# Special case because "Val{false}()" is used as the default empty expression.
Expand Down
3 changes: 3 additions & 0 deletions src/quadexpr.jl
Expand Up @@ -59,6 +59,9 @@ end
Base.zero(q::GenericQuadExpr) = zero(typeof(q))
Base.one(q::GenericQuadExpr) = one(typeof(q))
Base.copy(q::GenericQuadExpr) = GenericQuadExpr(copy(q.aff), copy(q.terms))
if VERSION >= v"0.7-"
Base.broadcastable(q::GenericQuadExpr) = Ref(q)
end

function map_coefficients_inplace!(f::Function, q::GenericQuadExpr)
# The iterator remains valid if existing elements are updated.
Expand Down
3 changes: 3 additions & 0 deletions src/variables.jl
Expand Up @@ -99,6 +99,9 @@ owner_model(v::VariableRef) = v.m

Base.iszero(::VariableRef) = false
Base.copy(v::VariableRef) = VariableRef(v.m, v.index)
if VERSION >= v"0.7-"
Base.broadcastable(v::VariableRef) = Ref(v)
end

isequal_canonical(v::VariableRef, other::VariableRef) = isequal(v, other)

Expand Down
11 changes: 10 additions & 1 deletion test/JuMPExtension.jl
Expand Up @@ -25,8 +25,11 @@ mutable struct MyModel <: JuMP.AbstractModel
Dict{Symbol, Any}())
end
end
if VERSION >= v"0.7-"
Base.broadcastable(model::MyModel) = Ref(model)
end

JuMP.object_dictionary(m::MyModel) = m.objdict
JuMP.object_dictionary(model::MyModel) = model.objdict

# Variables
struct MyVariableRef <: JuMP.AbstractVariableRef
Expand All @@ -35,6 +38,9 @@ struct MyVariableRef <: JuMP.AbstractVariableRef
end
Base.copy(v::MyVariableRef) = v
Base.:(==)(v::MyVariableRef, w::MyVariableRef) = v.model === w.model && v.idx == w.idx
if VERSION >= v"0.7-"
Base.broadcastable(v::MyVariableRef) = Ref(v)
end
JuMP.owner_model(v::MyVariableRef) = v.model
JuMP.isequal_canonical(v::MyVariableRef, w::MyVariableRef) = v == w
JuMP.variabletype(::MyModel) = MyVariableRef
Expand Down Expand Up @@ -102,6 +108,9 @@ struct MyConstraintRef
idx::Int # Index in `model.constraints`
end
JuMP.constrainttype(::MyModel) = MyConstraintRef
if VERSION >= v"0.7-"
Base.broadcastable(cref::MyConstraintRef) = Ref(cref)
end
function JuMP.addconstraint(m::MyModel, c::JuMP.AbstractConstraint, name::String="")
m.nextconidx += 1
cref = MyConstraintRef(m, m.nextconidx)
Expand Down
20 changes: 14 additions & 6 deletions test/macros.jl
Expand Up @@ -159,13 +159,21 @@ end
@test_macro_throws ErrorException @expression(m, x <= 1)
end

@testset "Warn on unexpected assignmnet" begin
@static if VERSION >= v"0.7-"
# https://github.com/JuliaLang/julia/issues/25612
@test_logs((:warn, r"Unexpected assignment"),
macroexpand(JuMP, :(@constraint(m, x[i=1] <= 1))))
@testset "Warn on unexpected assignment" begin
m = Model()
@variable(m, x)
@static if VERSION >= v"1.0"
# function getindex does not accept keyword arguments
@test_throws ErrorException x[i=1]
@test_throws ErrorException @constraint(m, x[i=1] <= 1)
else
@test_warn "Unexpected assignment" macroexpand(:(@constraint(m, x[i=1] <= 1)))
@static if VERSION >= v"0.7-"
# https://github.com/JuliaLang/julia/issues/25612
@test_logs((:warn, r"Unexpected assignment"),
macroexpand(JuMP, :(@constraint(m, x[i=1] <= 1))))
else
@test_warn "Unexpected assignment" macroexpand(:(@constraint(m, x[i=1] <= 1)))
end
end
end
end
Expand Down

0 comments on commit eeb2d6e

Please sign in to comment.