diff --git a/.travis.yml b/.travis.yml index f87ed7adf24..849e45c3442 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: @@ -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())' diff --git a/appveyor.yml b/appveyor.yml index 8c507ed5d1e..0805f337aad 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,6 +2,7 @@ environment: matrix: - julia_version: 0.6 - julia_version: 0.7 + - julia_version: 1.0 platform: - x86 # 32-bit diff --git a/src/JuMP.jl b/src/JuMP.jl index edf29986e10..82ddc56b430 100644 --- a/src/JuMP.jl +++ b/src/JuMP.jl @@ -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 @@ -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 diff --git a/src/affexpr.jl b/src/affexpr.jl index 5ff493ceabb..d95ba525576 100644 --- a/src/affexpr.jl +++ b/src/affexpr.jl @@ -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}) diff --git a/src/macros.jl b/src/macros.jl index a7be7d2ad89..e2ebf98034c 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -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 diff --git a/src/parseexpr.jl b/src/parseexpr.jl index f0abdfb2575..b90f8bc8799 100644 --- a/src/parseexpr.jl +++ b/src/parseexpr.jl @@ -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. diff --git a/src/quadexpr.jl b/src/quadexpr.jl index 3a5655a662c..462ebae74dc 100644 --- a/src/quadexpr.jl +++ b/src/quadexpr.jl @@ -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. diff --git a/src/variables.jl b/src/variables.jl index 8cf8a50cca9..8f425a92a4b 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -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) diff --git a/test/JuMPExtension.jl b/test/JuMPExtension.jl index 690177d804e..46954bd8dc7 100644 --- a/test/JuMPExtension.jl +++ b/test/JuMPExtension.jl @@ -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 @@ -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 @@ -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) diff --git a/test/macros.jl b/test/macros.jl index d720edc821d..e6af77b3f97 100644 --- a/test/macros.jl +++ b/test/macros.jl @@ -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