Skip to content

Commit

Permalink
Update to Julia 0.7 and 1.0 (#94)
Browse files Browse the repository at this point in the history
* Base.Test -> Test

* Fix some deprecations

* Fix a Smiley test and more deprecations

* Fix linear alebra tests

* New iteration protocol

* Remove lexcmp

* Update REQUIRE, .travis.yml and appveyor.yml for 0.7 and 1.0

* Pedal back ForwardDiff requirement
  • Loading branch information
dpsanders authored Sep 6, 2018
1 parent f7e2d85 commit 873aa00
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 124 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ os:
- osx

julia:
- 0.6
- 0.7
- 1.0
- nightly

matrix:
Expand Down
8 changes: 4 additions & 4 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
julia 0.6 0.7
IntervalArithmetic 0.14 0.15
ForwardDiff 0.7.5
StaticArrays 0.7.1
julia 0.7
IntervalArithmetic 0.15
ForwardDiff 0.8
StaticArrays 0.8
Polynomials
40 changes: 22 additions & 18 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- julia_version: 0.7
- julia_version: 1
- julia_version: nightly

matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
platform:
- x86 # 32-bit
- x64 # 64-bit

# # Uncomment the following lines to allow failures on nightly julia
# # (tests will run but not make your overall status red)
# matrix:
# allow_failures:
# - julia_version: nightly

branches:
only:
Expand All @@ -21,19 +26,18 @@ notifications:
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"IntervalRootFinding\"); Pkg.build(\"IntervalRootFinding\")"
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"IntervalRootFinding\")"
- echo "%JL_TEST_SCRIPT%"
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
19 changes: 2 additions & 17 deletions src/IntervalRootFinding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ using IntervalArithmetic
using ForwardDiff
using StaticArrays

using LinearAlgebra: I, Diagonal


import Base: , show, big, \

Expand Down Expand Up @@ -120,23 +122,6 @@ function find_roots_midpoint(f::Function, a::Real, b::Real, method::Function=new

end

function Base.lexcmp(a::Interval{T}, b::Interval{T}) where {T}
#@show a, b
if a.lo < b.lo
return -1
elseif a.lo == b.lo
if a.hi < b.hi
return -1
else
return 0
end
end
return 1

end

Base.lexcmp(a::Root{T}, b::Root{T}) where {T} = lexcmp(a.interval, b.interval)


function clean_roots(f, roots)

Expand Down
18 changes: 9 additions & 9 deletions src/contractors.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export Bisection, Newton, Krawczyk


doc"""
"""
Contractor{F}
Abstract type for contractors.
"""
abstract type Contractor{F} end

doc"""
"""
Bisection{F} <: Contractor{F}
Contractor type for the bisection method.
Expand All @@ -27,7 +27,7 @@ function (contractor::Bisection)(X, tol)
return :unknown, X
end

doc"""
"""
newtonlike_contract(op, X, tol)
Contraction operation for contractors using the first derivative of the
Expand Down Expand Up @@ -57,7 +57,7 @@ function newtonlike_contract(op, C, X, tol)
return :unknown, NX
end

doc"""
"""
Newton{F, FP} <: Contractor{F}
Contractor type for the Newton method.
Expand All @@ -76,7 +76,7 @@ function (C::Newton)(X, tol)
end


doc"""
"""
Single-variable Newton operator
"""
function 𝒩(f, X::Interval{T}) where {T}
Expand All @@ -97,7 +97,7 @@ function 𝒩(f, X::Interval{T}, dX::Interval{T}) where {T}
m - (f(m) / dX)
end

doc"""
"""
Multi-variable Newton operator.
"""
function 𝒩(f::Function, jacobian::Function, X::IntervalBox) # multidimensional Newton operator
Expand All @@ -108,7 +108,7 @@ function 𝒩(f::Function, jacobian::Function, X::IntervalBox) # multidimension
end


doc"""
"""
Krawczyk{F, FP} <: Contractor{F}
Contractor type for the Krawczyk method.
Expand All @@ -127,7 +127,7 @@ function (C::Krawczyk)(X, tol)
end


doc"""
"""
Single-variable Krawczyk operator
"""
function 𝒦(f, f′, X::Interval{T}) where {T}
Expand All @@ -137,7 +137,7 @@ function 𝒦(f, f′, X::Interval{T}) where {T}
m - Y*f(m) + (1 - Y*f′(X)) * (X - m)
end

doc"""
"""
Multi-variable Krawczyk operator
"""
function 𝒦(f, jacobian, X::IntervalBox{T}) where {T}
Expand Down
2 changes: 1 addition & 1 deletion src/krawczyk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# const D = differentiate

doc"""Returns two intervals, the first being a point within the
"""Returns two intervals, the first being a point within the
interval x such that the interval corresponding to the derivative of f there
does not contain zero, and the second is the inverse of its derivative"""
function guarded_derivative_midpoint(f::Function, f_prime::Function, x::Interval{T}) where {T}
Expand Down
40 changes: 23 additions & 17 deletions src/linear_eq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,55 +86,61 @@ end

function gauss_elimination_interval(A::AbstractMatrix, b::AbstractArray; precondition=true)

n = size(A, 1)
x = similar(b)
x .= -1e16..1e16
x = gauss_elimination_interval!(x, A, b, precondition=precondition)

return x
end
"""
Solves the system of linear equations using Gaussian Elimination,
with (or without) preconditioning. (kwarg - `precondition`)
Luc Jaulin, Michel Kieffer, Olivier Didrit and Eric Walter - Applied Interval Analysis - Page 72
Solves the system of linear equations using Gaussian Elimination.
Preconditioning is used when the `precondition` keyword argument is `true`.
REF: Luc Jaulin et al.,
*Applied Interval Analysis*, pg. 72
"""
function gauss_elimination_interval!(x::AbstractArray, a::AbstractMatrix, b::AbstractArray; precondition=true)
function gauss_elimination_interval!(x::AbstractArray, A::AbstractMatrix, b::AbstractArray; precondition=true)

if precondition
((a, b) = preconditioner(a, b))
(A, b) = preconditioner(A, b)
else
a = copy(a)
A = copy(A)
b = copy(b)
end
n = size(a, 1)

p = zeros(x)
n = size(A, 1)

p = similar(b)
p .= 0

for i in 1:(n-1)
if 0 a[i, i] # diagonal matrix is not invertible
if 0 A[i, i] # diagonal matrix is not invertible
p .= entireinterval(b[1])
return p .∩ x
return p .∩ x # return x?
end

for j in (i+1):n
α = a[j, i] / a[i, i]
α = A[j, i] / A[i, i]
b[j] -= α * b[i]

for k in (i+1):n
a[j, k] -= α * a[i, k]
A[j, k] -= α * A[i, k]
end
end
end

for i in n:-1:1
sum = 0

temp = zero(b[1])

for j in (i+1):n
sum += a[i, j] * p[j]
temp += A[i, j] * p[j]
end
p[i] = (b[i] - sum) / a[i, i]

p[i] = (b[i] - temp) / A[i, i]
end

p .∩ x
return p .∩ x
end

function gauss_elimination_interval1(A::AbstractMatrix, b::AbstractArray; precondition=true)
Expand Down
9 changes: 3 additions & 6 deletions src/newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

# Newton method



doc"""If a root is known to be inside an interval,
"""If a root is known to be inside an interval,
`newton_refine` iterates the interval Newton method until that root is found."""
function newton_refine(f::Function, f_prime::Function, X::Union{Interval{T}, IntervalBox{N,T}};
tolerance=eps(T), debug=false) where {N,T}
Expand All @@ -30,7 +28,7 @@ end



doc"""If a root is known to be inside an interval,
"""If a root is known to be inside an interval,
`newton_refine` iterates the interval Newton method until that root is found."""
function newton_refine(f::Function, f_prime::Function, X::Interval{T};
tolerance=eps(T), debug=false) where {T}
Expand Down Expand Up @@ -60,11 +58,10 @@ end



doc"""`newton` performs the interval Newton method on the given function `f`
"""`newton` performs the interval Newton method on the given function `f`
with its optional derivative `f_prime` and initial interval `x`.
Optional keyword arguments give the `tolerance`, `maxlevel` at which to stop
subdividing, and a `debug` boolean argument that prints out diagnostic information."""

function newton(f::Function, f_prime::Function, x::Interval{T}, level::Int=0;
tolerance=eps(T), debug=false, maxlevel=30) where {T}

Expand Down
8 changes: 3 additions & 5 deletions src/newton1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ with its derivative `f′` and initial interval `x`.
Optional keyword arguments give the tolerances `reltol` and `abstol`.
`reltol` is the tolerance on the relative error whereas `abstol` is the tolerance on |f(X)|,
and a `debug` boolean argument that prints out diagnostic information."""

function newton1d{T}(f::Function, f′::Function, x::Interval{T};
reltol=eps(T), abstol=eps(T), debug=false, debugroot=false)
function newton1d(f::Function, f′::Function, x::Interval{T};
reltol=eps(T), abstol=eps(T), debug=false, debugroot=false) where {T}

L = Interval{T}[] # Array to hold the intervals still to be processed

Expand Down Expand Up @@ -201,6 +200,5 @@ end
Optional keyword arguments give the tolerances `reltol` and `abstol`.
`reltol` is the tolerance on the relative error whereas `abstol` is the tolerance on |f(X)|,
and a `debug` boolean argument that prints out diagnostic information."""

newton1d{T}(f::Function, x::Interval{T}; args...) =
newton1d(f::Function, x::Interval{T}; args...) where {T} =
newton1d(f, x->D(f,x), x; args...)
4 changes: 2 additions & 2 deletions src/quadratic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Helper function for quadratic_interval that computes roots of a
real quadratic using interval arithmetic to bound rounding errors.
"""
function quadratic_helper!{T}(a::Interval{T}, b::Interval{T}, c::Interval{T}, L::Array{Interval{T}})
function quadratic_helper!(a::Interval{T}, b::Interval{T}, c::Interval{T}, L::Array{Interval{T}}) where {T}

Δ = b^2 - 4*a*c

Expand Down Expand Up @@ -40,7 +40,7 @@ This algorithm finds the set of points where `F.lo(x) ≥ 0` and the set
of points where `F.hi(x) ≤ 0` and takes the intersection of these two sets.
Eldon Hansen and G. William Walster : Global Optimization Using Interval Analysis - Chapter 8
"""
function quadratic_roots{T}(a::Interval{T}, b::Interval{T}, c::Interval{T})
function quadratic_roots(a::Interval{T}, b::Interval{T}, c::Interval{T}) where {T}

L = Interval{T}[]
R = Interval{T}[]
Expand Down
2 changes: 1 addition & 1 deletion src/root_object.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ root_status(x::Root) = x.status

show(io::IO, root::Root) = print(io, "Root($(root.interval), :$(root.status))")

isunique{T}(root::Root{T}) = (root.status == :unique)
isunique(root::Root{T}) where {T} = (root.status == :unique)

(a::Interval, b::Root) = a b.interval # the Root object has the interval in the first entry
(a::Root, b::Root) = a.interval b.interval
Expand Down
Loading

0 comments on commit 873aa00

Please sign in to comment.