Skip to content

Commit

Permalink
Merge pull request #1665 from JuliaOpt/bl/dropJulia0.6
Browse files Browse the repository at this point in the history
Drop Julia v0.6
  • Loading branch information
blegat committed Dec 6, 2018
2 parents 567097a + 26c6317 commit 9d8d315
Show file tree
Hide file tree
Showing 39 changed files with 382 additions and 755 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,6 @@ os:
# - osx # Disable to speed up CI. JuMP has no binary dependency so the result
# with osx and linux should be similar.
julia:
- 0.6
- 0.7
- 1.0
# This is left as an example for the next big version switch.
Expand Down
3 changes: 1 addition & 2 deletions REQUIRE
@@ -1,7 +1,6 @@
julia 0.6
julia 0.7
MathOptInterface 0.6.3 0.7
ForwardDiff 0.5 0.11
Calculus
DataStructures
NaNMath 0.2.1
Compat 1.0.0
3 changes: 1 addition & 2 deletions appveyor.yml
@@ -1,7 +1,6 @@
environment:
matrix:
# - julia_version: 0.6 # Disabled to speed up CI, Julia v0.6 and v0.7 are still
# - julia_version: 0.7 # tested on Linux with Travis
# - julia_version: 0.7 # Disabled to speed up CI, tested on Linux with Travis
- julia_version: 1.0

platform:
Expand Down
5 changes: 2 additions & 3 deletions src/Derivatives/Derivatives.jl
@@ -1,8 +1,7 @@
module Derivatives

using Compat
using Compat.LinearAlgebra
using Compat.SparseArrays
using LinearAlgebra
using SparseArrays

using Base.Meta
using ForwardDiff
Expand Down
2 changes: 0 additions & 2 deletions src/Derivatives/coloring.jl
@@ -1,7 +1,5 @@
module Coloring

using Compat

import DataStructures

include("topological_sort.jl")
Expand Down
35 changes: 11 additions & 24 deletions src/JuMP.jl
Expand Up @@ -8,13 +8,10 @@
# See http://github.com/JuliaOpt/JuMP.jl
#############################################################################

VERSION < v"0.7.0-beta2.199" && __precompile__()

module JuMP

using Compat
using Compat.LinearAlgebra
using Compat.SparseArrays
using LinearAlgebra
using SparseArrays

import MathOptInterface
const MOI = MathOptInterface
Expand Down Expand Up @@ -256,9 +253,7 @@ function direct_model(backend::MOI.ModelLike)
Dict{Symbol, Any}())
end

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


"""
Expand Down Expand Up @@ -402,13 +397,11 @@ set_optimize_hook(model::Model, f) = (model.optimize_hook = f)
abstract type AbstractJuMPScalar end


@static if VERSION >= v"0.7-"
# These are required to create symmetric containers of AbstractJuMPScalars.
Compat.LinearAlgebra.symmetric_type(::Type{T}) where T <: AbstractJuMPScalar = T
Compat.LinearAlgebra.symmetric(scalar::AbstractJuMPScalar, ::Symbol) = scalar
# This is required for linear algebra operations involving transposes.
Compat.LinearAlgebra.adjoint(scalar::AbstractJuMPScalar) = scalar
end
# These are required to create symmetric containers of AbstractJuMPScalars.
LinearAlgebra.symmetric_type(::Type{T}) where T <: AbstractJuMPScalar = T
LinearAlgebra.symmetric(scalar::AbstractJuMPScalar, ::Symbol) = scalar
# This is required for linear algebra operations involving transposes.
LinearAlgebra.adjoint(scalar::AbstractJuMPScalar) = scalar

"""
owner_model(s::AbstractJuMPScalar)
Expand All @@ -417,14 +410,8 @@ Return the model owning the scalar `s`.
"""
function owner_model end

if VERSION < v"0.7-"
Base.start(::AbstractJuMPScalar) = false
Base.next(x::AbstractJuMPScalar, state) = (x, true)
Base.done(::AbstractJuMPScalar, state) = state
else
Base.iterate(x::AbstractJuMPScalar) = (x, true)
Base.iterate(::AbstractJuMPScalar, state) = nothing
end
Base.iterate(x::AbstractJuMPScalar) = (x, true)
Base.iterate(::AbstractJuMPScalar, state) = nothing
Base.isempty(::AbstractJuMPScalar) = false

# Check if two arrays of AbstractJuMPScalars are equal. Useful for testing.
Expand Down Expand Up @@ -614,7 +601,7 @@ function operator_warn(::AbstractModel) end
function operator_warn(model::Model)
model.operator_counter += 1
if model.operator_counter > 20000
Compat.@warn(
@warn(
"The addition operator has been used on JuMP expressions a large " *
"number of times. This warning is safe to ignore but may " *
"indicate that model generation is slower than necessary. For " *
Expand Down
199 changes: 71 additions & 128 deletions src/JuMPArray.jl
Expand Up @@ -150,92 +150,80 @@ Base.setindex!(A::JuMPArray, v, idx::CartesianIndex) = A.data[idx] = v

# AbstractArray interface

if VERSION < v"0.7-"
# We don't define size because it causes 'end' to behave incorrectly. Better
# to error.
Base.size(A::JuMPArray) = error("JuMPArray does not define size().")
Base.linearindices(A::JuMPArray) = error("JuMPArray does not support this operation.")
Base.indices(A::JuMPArray) = A.axes
else
Base.size(A::JuMPArray) = size(A.data)
Base.LinearIndices(A::JuMPArray) = error("JuMPArray does not support this operation.")
Base.axes(A::JuMPArray) = A.axes
Base.CartesianIndices(a::JuMPArray) = CartesianIndices(a.data)
"""
JuMPArrayKey
Structure to hold a JuMPArray key when it is viewed as key-value collection.
"""
struct JuMPArrayKey{T<:Tuple}
I::T
end
Base.getindex(k::JuMPArrayKey, args...) = getindex(k.I, args...)
Base.size(A::JuMPArray) = size(A.data)
Base.LinearIndices(A::JuMPArray) = error("JuMPArray does not support this operation.")
Base.axes(A::JuMPArray) = A.axes
Base.CartesianIndices(a::JuMPArray) = CartesianIndices(a.data)
"""
JuMPArrayKey
struct JuMPArrayKeys{T<:Tuple}
product_iter::Base.Iterators.ProductIterator{T}
end
function Base.iterate(iter::JuMPArrayKeys)
next = iterate(iter.product_iter)
return next == nothing ? nothing : (JuMPArrayKey(next[1]), next[2])
end
function Base.iterate(iter::JuMPArrayKeys, state)
next = iterate(iter.product_iter, state)
return next == nothing ? nothing : (JuMPArrayKey(next[1]), next[2])
end
Base.length(iter::JuMPArrayKeys) = length(iter.product_iter)
function Base.eltype(iter::JuMPArrayKeys)
return JuMPArrayKey{eltype(iter.product_iter)}
end
function Base.keys(a::JuMPArray)
return JuMPArrayKeys(Base.Iterators.product(a.axes...))
end
Base.getindex(a::JuMPArray, k::JuMPArrayKey) = a[k.I...]
Structure to hold a JuMPArray key when it is viewed as key-value collection.
"""
struct JuMPArrayKey{T<:Tuple}
I::T
end
Base.getindex(k::JuMPArrayKey, args...) = getindex(k.I, args...)

struct JuMPArrayKeys{T<:Tuple}
product_iter::Base.Iterators.ProductIterator{T}
end
function Base.iterate(iter::JuMPArrayKeys)
next = iterate(iter.product_iter)
return next == nothing ? nothing : (JuMPArrayKey(next[1]), next[2])
end
function Base.iterate(iter::JuMPArrayKeys, state)
next = iterate(iter.product_iter, state)
return next == nothing ? nothing : (JuMPArrayKey(next[1]), next[2])
end
Base.length(iter::JuMPArrayKeys) = length(iter.product_iter)
function Base.eltype(iter::JuMPArrayKeys)
return JuMPArrayKey{eltype(iter.product_iter)}
end
function Base.keys(a::JuMPArray)
return JuMPArrayKeys(Base.Iterators.product(a.axes...))
end
Base.getindex(a::JuMPArray, k::JuMPArrayKey) = a[k.I...]

# Arbitrary typed indices. Linear indexing not supported.
struct IndexAnyCartesian <: Base.IndexStyle end
Base.IndexStyle(::Type{JuMPArray{T,N,Ax}}) where {T,N,Ax} = IndexAnyCartesian()

@static if VERSION < v"0.7-"
Base.broadcast(f::Function, A::JuMPArray) = JuMPArray(broadcast(f, A.data), A.axes, A.lookup)
else
# This implementation follows the instructions at
# https://docs.julialang.org/en/latest/manual/interfaces/#man-interfaces-broadcasting-1
# for implementing broadcast. We eagerly evaluate expressions involving
# JuMPArrays, overriding operation fusion. For now, nested (fused)
# broadcasts like f.(A .+ 1) don't work, and we don't support broadcasts
# where multiple JuMPArrays appear. This is a stopgap solution to get tests
# passing on Julia 0.7 and leaves lots of room for improvement.
struct JuMPArrayBroadcastStyle <: Broadcast.BroadcastStyle end
Base.BroadcastStyle(::Type{<:JuMPArray}) = JuMPArrayBroadcastStyle()
function Base.Broadcast.broadcasted(::JuMPArrayBroadcastStyle, f, args...)
array = find_jump_array(args)
if sum(arg isa JuMPArray for arg in args) > 1
error("Broadcast operations with multiple JuMPArrays are not yet " *
"supported.")
end
result_data = broadcast(f, unpack_jump_array(args)...)
return JuMPArray(result_data, array.axes, array.lookup)
end
function find_jump_array(args::Tuple)
return find_jump_array(args[1], Base.tail(args))
end
find_jump_array(array::JuMPArray, rest) = array
find_jump_array(::Any, rest) = find_jump_array(rest)
function find_jump_array(broadcasted::Broadcast.Broadcasted)
error("Unsupported nested broadcast operation. JuMPArray supports " *
"only simple broadcast operations like f.(A) but not f.(A .+ 1).")
# This implementation follows the instructions at
# https://docs.julialang.org/en/latest/manual/interfaces/#man-interfaces-broadcasting-1
# for implementing broadcast. We eagerly evaluate expressions involving
# JuMPArrays, overriding operation fusion. For now, nested (fused)
# broadcasts like f.(A .+ 1) don't work, and we don't support broadcasts
# where multiple JuMPArrays appear. This is a stopgap solution to get tests
# passing on Julia 0.7 and leaves lots of room for improvement.
struct JuMPArrayBroadcastStyle <: Broadcast.BroadcastStyle end
Base.BroadcastStyle(::Type{<:JuMPArray}) = JuMPArrayBroadcastStyle()
function Base.Broadcast.broadcasted(::JuMPArrayBroadcastStyle, f, args...)
array = find_jump_array(args)
if sum(arg isa JuMPArray for arg in args) > 1
error("Broadcast operations with multiple JuMPArrays are not yet " *
"supported.")
end
result_data = broadcast(f, unpack_jump_array(args)...)
return JuMPArray(result_data, array.axes, array.lookup)
end
function find_jump_array(args::Tuple)
return find_jump_array(args[1], Base.tail(args))
end
find_jump_array(array::JuMPArray, rest) = array
find_jump_array(::Any, rest) = find_jump_array(rest)
function find_jump_array(broadcasted::Broadcast.Broadcasted)
error("Unsupported nested broadcast operation. JuMPArray supports " *
"only simple broadcast operations like f.(A) but not f.(A .+ 1).")
end

function unpack_jump_array(args::Tuple)
return unpack_jump_array(args[1], Base.tail(args))
end
unpack_jump_array(args::Tuple{}) = ()
function unpack_jump_array(array::JuMPArray, rest)
return (array.data, unpack_jump_array(rest)...)
end
unpack_jump_array(other::Any, rest) = (other, unpack_jump_array(rest)...)
function unpack_jump_array(args::Tuple)
return unpack_jump_array(args[1], Base.tail(args))
end
unpack_jump_array(args::Tuple{}) = ()
function unpack_jump_array(array::JuMPArray, rest)
return (array.data, unpack_jump_array(rest)...)
end
unpack_jump_array(other::Any, rest) = (other, unpack_jump_array(rest)...)

Base.isempty(A::JuMPArray) = isempty(A.data)

Expand Down Expand Up @@ -293,7 +281,7 @@ function Base.show_nd(io::IO, a::JuMPArray, print_matrix::Function, label_slices
if isempty(a)
return
end
tailinds = Base.tail(Base.tail(Compat.axes(a.data)))
tailinds = Base.tail(Base.tail(axes(a.data)))
nd = ndims(a)-2
for I in CartesianIndices(tailinds)
idxs = I.I
Expand Down Expand Up @@ -326,62 +314,17 @@ function Base.show_nd(io::IO, a::JuMPArray, print_matrix::Function, label_slices
show(io, a.axes[end][idxs[end]])
println(io, "] =")
end
slice = view(a.data, Compat.axes(a.data,1), Compat.axes(a.data,2),
slice = view(a.data, axes(a.data,1), axes(a.data,2),
idxs...)
Base.print_matrix(io, slice)
print(io, idxs == map(last,tailinds) ? "" : "\n\n")
@label skip
end
end

@static if VERSION >= v"0.7-"
function Base.show(io::IO, array::JuMPArray)
summary(io, array)
isempty(array) && return
println(io, ":")
Base.print_array(io, array)
end
else
function Base.showarray(io::IO, X::JuMPArray, repr::Bool = true; header = true)
repr = false
#if repr && ndims(X) == 1
# return Base.show_vector(io, X, "[", "]")
#end
if !haskey(io, :compact)
io = IOContext(io, :compact => true)
end
if !repr && get(io, :limit, false) && eltype(X) === Method
# override usual show method for Vector{Method}: don't abbreviate long lists
io = IOContext(io, :limit => false)
end
(!repr && header) && print(io, summary(X))
if !isempty(X.data)
(!repr && header) && println(io, ":")
if ndims(X.data) == 0
if isassigned(X.data)
return show(io, X.data[])
else
return print(io, undef_ref_str)
end
end
#if repr
# if ndims(X.data) <= 2
# Base.print_matrix_repr(io, X)
# else
# show_nd(io, X, print_matrix_repr, false)
# end
#else
punct = (" ", " ", "")
if ndims(X.data) <= 2
Base.print_matrix(io, X.data, punct...)
else
Base.show_nd(io, X,
(io, slice) -> Base.print_matrix(io, slice, punct...),
!repr)
end
#end
elseif repr
Base.repremptyarray(io, X.data)
end
end
function Base.show(io::IO, array::JuMPArray)
summary(io, array)
isempty(array) && return
println(io, ":")
Base.print_array(io, array)
end

0 comments on commit 9d8d315

Please sign in to comment.