Skip to content

Commit

Permalink
0.6 / 0.7 deprecations (#12)
Browse files Browse the repository at this point in the history
* Parametrize AbstractInterval and use @compat for 0.6 syntax

* 0.6 inner constructor syntax

* Update REQUIRE to require Julia 0.6 and corresponding version of StaticArrays

* Replace immutable -> struct

* Remove @compat

* type -> mutable struct

* Remove pre-0.6 stuff

* Use of new syntax in functions and structs in src/interval/

* Upgrade syntax in src/decorations

* Upgrade syntax in src/multidim

* Upgrade files in src/

I couldn't upgrade src/plot_recipes/plot_recipes.jl; seemingly
the macro `@recipe` does not handle (yet) the new syntax.
  • Loading branch information
dpsanders authored and lbenet committed Jun 19, 2017
1 parent 6a45780 commit 96e9d80
Show file tree
Hide file tree
Showing 21 changed files with 209 additions and 191 deletions.
7 changes: 4 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
julia 0.5
julia 0.6-pre
CRlibm 0.5
StaticArrays 0.3
StaticArrays 0.5
FastRounding 0.0.4
AdjacentFloats 0.0.4
AdjacentFloats 0.0.5
RecipesBase

2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ makedocs(
deploydocs(
repo = "github.com/JuliaIntervals/IntervalArithmetic.jl.git",
target = "build",
julia = "0.5",
julia = "0.6",
osname = "linux",
deps = nothing,
make = nothing
Expand Down
55 changes: 28 additions & 27 deletions src/decorations/functions.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This file is part of the IntervalArithmetic.jl package; MIT licensed

# zero, one
zero{T<:Real}(a::DecoratedInterval{T}) = DecoratedInterval(zero(T))
zero{T<:Real}(::Type{DecoratedInterval{T}}) = DecoratedInterval(zero(T))
one{T<:Real}(a::DecoratedInterval{T}) = DecoratedInterval(one(T))
one{T<:Real}(::Type{DecoratedInterval{T}}) = DecoratedInterval(one(T))
zero(a::DecoratedInterval{T}) where T<:Real = DecoratedInterval(zero(T))
zero(::Type{DecoratedInterval{T}}) where T<:Real = DecoratedInterval(zero(T))
one(a::DecoratedInterval{T}) where T<:Real = DecoratedInterval(one(T))
one(::Type{DecoratedInterval{T}}) where T<:Real = DecoratedInterval(one(T))


## Bool functions
Expand All @@ -28,7 +28,7 @@ for f in bool_binary_functions
$(f)(interval_part(xx), interval_part(yy))
end

in{T<:Real}(x::T, a::DecoratedInterval) = in(x, interval_part(a))
in(x::T, a::DecoratedInterval) where T<:Real = in(x, interval_part(a))


## scalar functions: mig, mag and friends
Expand All @@ -37,7 +37,7 @@ scalar_functions = (
)

for f in scalar_functions
@eval $(f){T}(xx::DecoratedInterval{T}) = $f(interval_part(xx))
@eval $(f)(xx::DecoratedInterval{T}) where T = $f(interval_part(xx))
end


Expand All @@ -47,7 +47,7 @@ arithm_functions = ( :+, :-, :* )
+(xx::DecoratedInterval) = xx
-(xx::DecoratedInterval) = DecoratedInterval(-interval_part(xx), decoration(xx))
for f in arithm_functions
@eval function $(f){T}(xx::DecoratedInterval{T}, yy::DecoratedInterval{T})
@eval function $(f)(xx::DecoratedInterval{T}, yy::DecoratedInterval{T}) where T
x = interval_part(xx)
y = interval_part(yy)
r = $f(x, y)
Expand All @@ -57,15 +57,15 @@ for f in arithm_functions
end

# Division
function inv{T}(xx::DecoratedInterval{T})
function inv(xx::DecoratedInterval{T}) where T
x = interval_part(xx)
dx = decoration(xx)
dx = zero(T) x ? min(dx,trv) : dx
r = inv(x)
dx = min(decoration(r), dx)
DecoratedInterval( r, dx )
end
function /{T}(xx::DecoratedInterval{T}, yy::DecoratedInterval{T})
function /(xx::DecoratedInterval{T}, yy::DecoratedInterval{T}) where T
x = interval_part(xx)
y = interval_part(yy)
r = x / y
Expand All @@ -76,7 +76,7 @@ function /{T}(xx::DecoratedInterval{T}, yy::DecoratedInterval{T})
end

## fma
function fma{T}(xx::DecoratedInterval{T}, yy::DecoratedInterval{T}, zz::DecoratedInterval{T})
function fma(xx::DecoratedInterval{T}, yy::DecoratedInterval{T}, zz::DecoratedInterval{T}) where T
r = fma(interval_part(xx), interval_part(yy), interval_part(zz))
d = min(decoration(xx), decoration(yy), decoration(zz))
d = min(decoration(r), d)
Expand All @@ -85,15 +85,15 @@ end


# power function must be defined separately and carefully
function ^{T}(xx::DecoratedInterval{T}, n::Integer)
function ^(xx::DecoratedInterval{T}, n::Integer) where T
x = interval_part(xx)
r = x^n
d = min(decoration(xx), decoration(r))
n < 0 && zero(T) x && return DecoratedInterval(r, trv)
DecoratedInterval(r, d)
end

function ^{T}(xx::DecoratedInterval{T}, q::AbstractFloat)
function ^(xx::DecoratedInterval{T}, q::AbstractFloat) where T
x = interval_part(xx)
r = x^q
d = min(decoration(xx), decoration(r))
Expand All @@ -104,7 +104,7 @@ function ^{T}(xx::DecoratedInterval{T}, q::AbstractFloat)
DecoratedInterval(r, trv)
end

function ^{T, S<:Integer}(xx::DecoratedInterval{T}, q::Rational{S})
function ^(xx::DecoratedInterval{T}, q::Rational{S}) where {T, S<:Integer}
x = interval_part(xx)
r = x^q
d = min(decoration(xx), decoration(r))
Expand All @@ -115,7 +115,7 @@ function ^{T, S<:Integer}(xx::DecoratedInterval{T}, q::Rational{S})
DecoratedInterval(r, trv)
end

function ^{T,S}(xx::DecoratedInterval{T}, qq::DecoratedInterval{S})
function ^(xx::DecoratedInterval{T}, qq::DecoratedInterval{S}) where {T,S}
x = interval_part(xx)
q = interval_part(qq)
r = x^q
Expand All @@ -128,16 +128,17 @@ function ^{T,S}(xx::DecoratedInterval{T}, qq::DecoratedInterval{S})
DecoratedInterval(r, trv)
end

^{T,S}(xx::DecoratedInterval{T}, q::Interval{S}) = xx^DecoratedInterval(q)
^(xx::DecoratedInterval{T}, q::Interval{S}) where {T,S} =
xx^DecoratedInterval(q)

## Discontinuous functions (sign, ceil, floor, trunc) and round
function sign{T}(xx::DecoratedInterval{T})
function sign(xx::DecoratedInterval{T}) where T
r = sign(interval_part(xx))
d = decoration(xx)
isthin(r) && return DecoratedInterval(r, d)
DecoratedInterval(r, min(d,def))
end
function ceil{T}(xx::DecoratedInterval{T})
function ceil(xx::DecoratedInterval{T}) where T
x = interval_part(xx)
r = ceil(x)
d = decoration(xx)
Expand All @@ -147,7 +148,7 @@ function ceil{T}(xx::DecoratedInterval{T})
isthin(r) && return DecoratedInterval(r, d)
DecoratedInterval(r, min(d,def))
end
function floor{T}(xx::DecoratedInterval{T})
function floor(xx::DecoratedInterval{T}) where T
x = interval_part(xx)
r = floor(x)
d = decoration(xx)
Expand All @@ -157,7 +158,7 @@ function floor{T}(xx::DecoratedInterval{T})
isthin(r) && return DecoratedInterval(r, d)
DecoratedInterval(r, min(d,def))
end
function trunc{T}(xx::DecoratedInterval{T})
function trunc(xx::DecoratedInterval{T}) where T
x = interval_part(xx)
r = trunc(x)
d = decoration(xx)
Expand Down Expand Up @@ -198,23 +199,23 @@ round(xx::DecoratedInterval, ::RoundingMode{:Down}) = floor(xx)
binary_functions = ( :min, :max )

for f in binary_functions
@eval function $(f){T}(xx::DecoratedInterval{T}, yy::DecoratedInterval{T})
@eval function $(f)(xx::DecoratedInterval{T}, yy::DecoratedInterval{T}) where T
r = $f(interval_part(xx), interval_part(yy))
d = min(decoration(r), decoration(xx), decoration(yy))
DecoratedInterval(r, d)
end
end

## abs
abs{T}(xx::DecoratedInterval{T}) =
abs(xx::DecoratedInterval{T}) where T =
DecoratedInterval(abs(interval_part(xx)), decoration(xx))


## Other (cancel and set) functions
other_functions = ( :cancelplus, :cancelminus, :intersect, :hull, :union )

for f in other_functions
@eval $(f){T}(xx::DecoratedInterval{T}, yy::DecoratedInterval{T}) =
@eval $(f)(xx::DecoratedInterval{T}, yy::DecoratedInterval{T}) where T =
DecoratedInterval($(f)(interval_part(xx), interval_part(yy)), trv)
end

Expand Down Expand Up @@ -263,15 +264,15 @@ unrestricted_functions =(
:asinh )

for f in unrestricted_functions
@eval function $(f){T}(xx::DecoratedInterval{T})
@eval function $(f)(xx::DecoratedInterval{T}) where T
x = interval_part(xx)
r = $f(x)
d = min(decoration(r), decoration(xx))
DecoratedInterval(r, d)
end
end

function tan{T}(xx::DecoratedInterval{T})
function tan(xx::DecoratedInterval{T}) where T
x = interval_part(xx)
r = tan(x)
d = min(decoration(r), decoration(xx))
Expand All @@ -289,7 +290,7 @@ function decay(a::DECORATION)
ill
end

function atan2{T}(yy::DecoratedInterval{T}, xx::DecoratedInterval{T})
function atan2(yy::DecoratedInterval{T}, xx::DecoratedInterval{T}) where T
x = interval_part(xx)
y = interval_part(yy)
r = atan2(y, x)
Expand Down Expand Up @@ -328,7 +329,7 @@ restricted_functions2 = Dict(
# Define functions with restricted domains on DecoratedInterval's:
for (f, domain) in restricted_functions1
domain = Interval(domain...)
@eval function Base.$(f){T}(xx::DecoratedInterval{T})
@eval function Base.$(f)(xx::DecoratedInterval{T}) where T
x = interval_part(xx)
r = $(f)(x)
d = min(decoration(xx), decoration(r))
Expand All @@ -339,7 +340,7 @@ end

for (f, domain) in restricted_functions2
domain = Interval(domain...)
@eval function Base.$(f){T}(xx::DecoratedInterval{T})
@eval function Base.$(f)(xx::DecoratedInterval{T}) where T
x = interval_part(xx)
r = $(f)(x)
d = min(decoration(xx), decoration(r))
Expand Down
55 changes: 35 additions & 20 deletions src/decorations/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,56 @@ A `DecoratedInterval` is an interval, together with a *decoration*, i.e.
a flag that records the status of the interval when thought of as the result
of a previously executed sequence of functions acting on an initial interval.
"""
type DecoratedInterval{T<:Real} <: AbstractInterval{T}
struct DecoratedInterval{T<:Real} <: AbstractInterval{T}
interval::Interval{T}
decoration::DECORATION

function DecoratedInterval(I::Interval, d::DECORATION)
function DecoratedInterval{T}(I::Interval, d::DECORATION) where T
dd = decoration(I)
dd <= trv && return new(I, dd)
d == ill && return new(nai(I), d)
return new(I, d)
dd <= trv && return new{T}(I, dd)
d == ill && return new{T}(nai(I), d)
return new{T}(I, d)
end
end

DecoratedInterval{T<:AbstractFloat}(I::Interval{T}, d::DECORATION) =
DecoratedInterval(I::Interval{T}, d::DECORATION) where T<:AbstractFloat =
DecoratedInterval{T}(I, d)
function DecoratedInterval{T<:Real}(a::T, b::T, d::DECORATION)

function DecoratedInterval(a::T, b::T, d::DECORATION) where T<:Real
a > b && return DecoratedInterval(nai(T), ill)
DecoratedInterval(Interval(a,b), d)
end
DecoratedInterval{T<:Real}(a::T, d::DECORATION) = DecoratedInterval(Interval(a,a), d)

DecoratedInterval(a::T, d::DECORATION) where T<:Real =
DecoratedInterval(Interval(a,a), d)

DecoratedInterval(a::Tuple, d::DECORATION) = DecoratedInterval(a..., d)
DecoratedInterval{T<:Real, S<:Real}(a::T, b::S, d::DECORATION) =

DecoratedInterval(a::T, b::S, d::DECORATION) where {T<:Real, S<:Real} =
DecoratedInterval(promote(a,b)..., d)

# Automatic decorations for an interval
DecoratedInterval(I::Interval) = DecoratedInterval(I, decoration(I))
function DecoratedInterval{T<:Real}(a::T, b::T)

function DecoratedInterval(a::T, b::T) where T<:Real
a > b && return DecoratedInterval(nai(T), ill)
DecoratedInterval(Interval(a,b))
end
DecoratedInterval{T<:Integer}(a::T, b::T) = DecoratedInterval(float(a),float(b))
DecoratedInterval{T<:Real}(a::T) = DecoratedInterval(Interval(a,a))
DecoratedInterval{T<:Real, S<:Real}(a::T, b::S) = DecoratedInterval(promote(a, b)...)

DecoratedInterval(a::T, b::T) where T<:Integer =
DecoratedInterval(float(a),float(b))

DecoratedInterval(a::T) where T<:Real = DecoratedInterval(Interval(a,a))

DecoratedInterval(a::T, b::S) where {T<:Real, S<:Real} =
DecoratedInterval(promote(a, b)...)

DecoratedInterval(a::Tuple) = DecoratedInterval(a...)

DecoratedInterval(I::DecoratedInterval, dec::DECORATION) = DecoratedInterval(I.interval, dec)

interval_part(x::DecoratedInterval) = x.interval

decoration(x::DecoratedInterval) = x.decoration

# Automatic decorations for an Interval
Expand All @@ -83,25 +96,27 @@ end
# promote_rule{T<:Real, N, R<:Real}(::Type{DecoratedInterval{T}},
# ::Type{ForwardDiff.Dual{N,R}}) = ForwardDiff.Dual{N, DecoratedInterval{promote_type(T,R)}}

promote_rule{T<:Real, S<:Real}(::Type{DecoratedInterval{T}}, ::Type{S}) =
DecoratedInterval{promote_type(T, S)}
promote_rule{T<:Real, S<:Real}(::Type{DecoratedInterval{T}}, ::Type{DecoratedInterval{S}}) =
promote_rule(::Type{DecoratedInterval{T}}, ::Type{S}) where {T<:Real, S<:Real} =
DecoratedInterval{promote_type(T, S)}

convert{T<:Real, S<:Real}(::Type{DecoratedInterval{T}}, x::S) =
promote_rule(::Type{DecoratedInterval{T}}, ::Type{DecoratedInterval{S}}) where
{T<:Real, S<:Real} = DecoratedInterval{promote_type(T, S)}

convert(::Type{DecoratedInterval{T}}, x::S) where {T<:Real, S<:Real} =
DecoratedInterval( Interval(T(x, RoundDown), T(x, RoundUp)) )
convert{T<:Real, S<:Integer}(::Type{DecoratedInterval{T}}, x::S) =

convert(::Type{DecoratedInterval{T}}, x::S) where {T<:Real, S<:Integer} =
DecoratedInterval( Interval(T(x), T(x)) )
# function convert{T<:AbstractFloat}(::Type{DecoratedInterval{T}}, x::Float64)
# convert(DecoratedInterval{T}, rationalize(x))
# end
function convert{T<:Real}(::Type{DecoratedInterval{T}}, xx::DecoratedInterval)
function convert(::Type{DecoratedInterval{T}}, xx::DecoratedInterval) where T<:Real
x = interval_part(xx)
x = convert(Interval{T},x)
DecoratedInterval( x, decoration(xx) )
end

convert{T<:AbstractFloat}(::Type{DecoratedInterval{T}}, x::AbstractString) =
convert(::Type{DecoratedInterval{T}}, x::AbstractString) where T<:AbstractFloat =
parse(DecoratedInterval{T}, x)

big(x::DecoratedInterval) = DecoratedInterval(big(interval_part(x)),
Expand Down
15 changes: 8 additions & 7 deletions src/display.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type DisplayParameters
mutable struct DisplayParameters
format::Symbol
decorations::Bool
sigfigs::Int
Expand Down Expand Up @@ -159,8 +159,8 @@ function basic_representation(a::Interval, format=nothing)
output
end

function basic_representation{T<:Integer}(a::Interval{Rational{T}},
format=nothing)
function basic_representation(a::Interval{Rational{T}}, format=nothing) where
T<:Integer

if isempty(a)
return ""
Expand Down Expand Up @@ -195,7 +195,8 @@ end


# fall-back:
representation{T}(a::Interval{T}, format=nothing) = basic_representation(a, format)
representation(a::Interval{T}, format=nothing) where T =
basic_representation(a, format)

function representation(a::Interval{BigFloat}, format=nothing)

Expand All @@ -216,7 +217,7 @@ function representation(a::Interval{BigFloat}, format=nothing)
end


function representation{T}(a::DecoratedInterval{T}, format=nothing)
function representation(a::DecoratedInterval{T}, format=nothing) where T

if format == nothing
format = display_params.format # default
Expand Down Expand Up @@ -254,8 +255,8 @@ end


for T in (Interval, DecoratedInterval)
@eval show{S}(io::IO, a::$T{S}) = print(io, representation(a))
@eval showall{S}(io::IO, a::$T{S}) = print(io, representation(a, :full))
@eval show(io::IO, a::$T{S}) where S = print(io, representation(a))
@eval showall(io::IO, a::$T{S}) where S = print(io, representation(a, :full))
end

T = IntervalBox
Expand Down
Loading

0 comments on commit 96e9d80

Please sign in to comment.