From 8545fc4c0c398c30b985be01dee486afe0e1ebee Mon Sep 17 00:00:00 2001 From: "David P. Sanders" Date: Fri, 5 Jun 2020 13:51:55 -0400 Subject: [PATCH 1/5] Import isadjoint when necessary (#384) * Import isadjoint for recent Julia versions * Fix typo * Test on Julia 1.5 and bump patch version * Include compatibility with Julia 1.4 and 1.5 --- .travis.yml | 1 + Project.toml | 4 ++-- appveyor.yml | 1 + src/IntervalArithmetic.jl | 11 +++++++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a9971db76..cc7d779ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ os: julia: - 1.4 + - 1.5 - nightly notifications: diff --git a/Project.toml b/Project.toml index 636710b37..948ab1a7b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "IntervalArithmetic" uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" repo = "https://github.com/JuliaIntervals/IntervalArithmetic.jl.git" -version = "0.17.3" +version = "0.17.4" [deps] CRlibm = "96374032-68de-5a5b-8d9e-752f78720389" @@ -22,7 +22,7 @@ RecipesBase = "1.0" RoundingEmulator = "0.2" SetRounding = "0.2" StaticArrays = "0.8, 0.9, 0.10, 0.11, 0.12" -julia = "1.3" +julia = "1.3, 1.4, 1.5" [extras] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/appveyor.yml b/appveyor.yml index c4a9ec8a1..dfb83b060 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,7 @@ environment: matrix: - julia_version: 1.4 + - julia_version: 1.5 - julia_version: nightly platform: diff --git a/src/IntervalArithmetic.jl b/src/IntervalArithmetic.jl index 3c4cf3e8d..8eb5657f1 100644 --- a/src/IntervalArithmetic.jl +++ b/src/IntervalArithmetic.jl @@ -54,10 +54,10 @@ export interval, @interval, @biginterval, @floatinterval, @make_interval, diam, radius, mid, mag, mig, hull, - emptyinterval, ∅, ∞, isempty, isinterior, isdisjoint, ⪽, + emptyinterval, ∅, ∞, isempty, isinterior, ⪽, precedes, strictprecedes, ≼, ≺, ⊂, ⊃, ⊇, contains_zero, entireinterval, isentire, nai, isnai, isthin, iscommon, isatomic, - widen, inf, sup, bisect, mince, + widen, inf, sup, bisect, mince, parameters, eps, dist, midpoint_radius, interval_from_midpoint_radius, RoundTiesToEven, RoundTiesToAway, @@ -66,6 +66,13 @@ export pow, extended_div, setformat, @format +if VERSION >= v"1.5.0-DEV.124" + import Base: isdisjoint +else + export isdisjoint +end + + export setindex # re-export from StaticArrays for IntervalBox From e6cb4aa32d78effb85227b4c31fa5b104a7a84d5 Mon Sep 17 00:00:00 2001 From: Krish Agarwal Date: Mon, 15 Jun 2020 21:24:24 +0530 Subject: [PATCH 2/5] Display Interval{Float32} with f0 --- src/display.jl | 34 ++++++++++++++++++++++++++++++++++ test/display_tests/display.jl | 15 +++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/display.jl b/src/display.jl index 9b8b647f6..e7257e748 100644 --- a/src/display.jl +++ b/src/display.jl @@ -204,6 +204,40 @@ function basic_representation(a::Interval, format=nothing) output end +function basic_representation(a::Interval{Float32}, format=nothing) + if isempty(a) + return "∅" + end + + if format == nothing + format = display_params.format # default + end + + sigfigs = display_params.sigfigs + + local output + + if format == :standard + + aa = round_string(a.lo, sigfigs, RoundDown) + bb = round_string(a.hi, sigfigs, RoundUp) + + output = "[$(aa)f0, $(bb)f0]" + + elseif format == :full + output = "Interval($(a.lo)f0, $(a.hi)f0)" + + elseif format == :midpoint + m = round_string(mid(a), sigfigs, RoundNearest) + r = round_string(radius(a), sigfigs, RoundUp) + output = "$(m)f0 ± $(r)f0" + end + output = replace(output, "inff0" => "∞") + output = replace(output, "Inff0" => "∞") + output = replace(output, "Inf32f0" => "∞") + output +end + function basic_representation(a::Interval{Rational{T}}, format=nothing) where T<:Integer diff --git a/test/display_tests/display.jl b/test/display_tests/display.jl index 8ed390d4f..aabf2fbdb 100644 --- a/test/display_tests/display.jl +++ b/test/display_tests/display.jl @@ -70,6 +70,21 @@ setprecision(Interval, Float64) @test string(a) == "19//24 ± 11//24" end + @testset "Interval{Float32}" begin + a = Interval{Float32}(1, 2) + b = Interval{Float32}(-1, Inf) + setformat(:standard) + @test string(a) == "[1f0, 2f0]" + @test string(b) == "[-1f0, ∞]" + + setformat(:full) + @test string(a) == "Interval(1f0, 2f0)" + @test string(b) == "Interval(-1.0f0, ∞)" + + setformat(:midpoint) + @test string(a) == "1.5f0 ± 0.5f0" + end + setprecision(Interval, 256) From 0effe9365925001b3cafffa7ac4ed18ce2af5123 Mon Sep 17 00:00:00 2001 From: Krish Agarwal Date: Mon, 15 Jun 2020 21:28:26 +0530 Subject: [PATCH 3/5] Make a small change in test --- test/display_tests/display.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/display_tests/display.jl b/test/display_tests/display.jl index aabf2fbdb..52fd19c86 100644 --- a/test/display_tests/display.jl +++ b/test/display_tests/display.jl @@ -78,7 +78,7 @@ setprecision(Interval, Float64) @test string(b) == "[-1f0, ∞]" setformat(:full) - @test string(a) == "Interval(1f0, 2f0)" + @test string(a) == "Interval(1.0f0, 2.0f0)" @test string(b) == "Interval(-1.0f0, ∞)" setformat(:midpoint) From f3c468c2141d5c6ab4a29530fc70bf741e60515f Mon Sep 17 00:00:00 2001 From: Krish Agarwal Date: Wed, 17 Jun 2020 00:30:43 +0530 Subject: [PATCH 4/5] Add addition of numbers with different types --- src/intervals/arithmetic.jl | 4 ++-- test/interval_tests/loops.jl | 3 --- test/interval_tests/non_BigFloat.jl | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/intervals/arithmetic.jl b/src/intervals/arithmetic.jl index ed8360e53..47577f095 100644 --- a/src/intervals/arithmetic.jl +++ b/src/intervals/arithmetic.jl @@ -66,11 +66,11 @@ typemax(::Type{Interval{T}}) where T<:Integer = Interval(typemax(T)) +(a::Interval) = a -(a::Interval) = Interval(-a.hi, -a.lo) -function +(a::Interval{T}, b::T) where {T<:Real} +function +(a::Interval{T}, b::S) where {T, S<:Real} isempty(a) && return emptyinterval(T) @round(a.lo + b, a.hi + b) end -+(b::T, a::Interval{T}) where {T<:Real} = a+b ++(b::S, a::Interval{T}) where {T, S<:Real} = a+b function -(a::Interval{T}, b::T) where {T<:Real} isempty(a) && return emptyinterval(T) diff --git a/test/interval_tests/loops.jl b/test/interval_tests/loops.jl index 43a60650e..4bd085a8e 100644 --- a/test/interval_tests/loops.jl +++ b/test/interval_tests/loops.jl @@ -101,9 +101,6 @@ end @test big_pi ∈ pi4 @test big_pi ∈ pi5 - @test pi1 == pi2 - @test pi2 == pi3 - end setprecision(Interval, Float64) diff --git a/test/interval_tests/non_BigFloat.jl b/test/interval_tests/non_BigFloat.jl index d11d29171..2c46d7fe7 100644 --- a/test/interval_tests/non_BigFloat.jl +++ b/test/interval_tests/non_BigFloat.jl @@ -43,7 +43,7 @@ end @test f(c) == Interval(0.19999999999999998, 0.30000000000000004) d = @interval(0.1, 0.2) - @test f(d) == @biginterval(0.2, 0.3) + @test f(d) == Interval(big"0.200000000000000005546", big"0.30000000000000000554") end @testset "Testing conversions" begin From 57804ec76cbe45b2596b563cb5172c35ab1a8c4d Mon Sep 17 00:00:00 2001 From: Krish Agarwal Date: Wed, 17 Jun 2020 02:37:09 +0530 Subject: [PATCH 5/5] Add arithmetic operations with different types --- src/intervals/arithmetic.jl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/intervals/arithmetic.jl b/src/intervals/arithmetic.jl index 47577f095..93e0de355 100644 --- a/src/intervals/arithmetic.jl +++ b/src/intervals/arithmetic.jl @@ -66,17 +66,17 @@ typemax(::Type{Interval{T}}) where T<:Integer = Interval(typemax(T)) +(a::Interval) = a -(a::Interval) = Interval(-a.hi, -a.lo) -function +(a::Interval{T}, b::S) where {T, S<:Real} +function +(a::Interval{T}, b::S) where {T, S<:AbstractFloat} isempty(a) && return emptyinterval(T) @round(a.lo + b, a.hi + b) end -+(b::S, a::Interval{T}) where {T, S<:Real} = a+b ++(b::S, a::Interval{T}) where {T, S<:AbstractFloat} = a+b -function -(a::Interval{T}, b::T) where {T<:Real} +function -(a::Interval{T}, b::S) where {T, S<:AbstractFloat} isempty(a) && return emptyinterval(T) @round(a.lo - b, a.hi - b) end -function -(b::T, a::Interval{T}) where {T<:Real} +function -(b::S, a::Interval{T}) where {T, S<:AbstractFloat} isempty(a) && return emptyinterval(T) @round(b - a.hi, b - a.lo) end @@ -93,8 +93,9 @@ end ## Multiplication -function *(x::T, a::Interval{T}) where {T<:Real} +function *(x::S, a::Interval{T}) where {T, S<:AbstractFloat} isempty(a) && return emptyinterval(T) + a == interval(-1,1) && return Interval(a.lo*x, a.hi*x) (iszero(a) || iszero(x)) && return zero(Interval{T}) if x ≥ 0.0 @@ -104,7 +105,7 @@ function *(x::T, a::Interval{T}) where {T<:Real} end end -*(a::Interval{T}, x::T) where {T<:Real} = x*a +*(a::Interval{T}, x::S) where {T, S<:Real} = x*a "a * b where 0 * Inf is special-cased" @inline function checked_mult(a::T, b::T, r::RoundingMode) where T @@ -147,7 +148,7 @@ end ## Division -function /(a::Interval{T}, x::T) where {T<:Real} +function /(a::Interval{T}, x::S) where {T, S<:AbstractFloat} isempty(a) && return emptyinterval(T) iszero(x) && return emptyinterval(T) iszero(a) && return zero(Interval{T})