Skip to content

Commit

Permalink
Merge branch 'master' into lb/aqua
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHnt committed Nov 13, 2024
2 parents d30a6ef + ec34419 commit 082dff6
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 124 deletions.
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
name = "IntervalArithmetic"
uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
repo = "https://github.com/JuliaIntervals/IntervalArithmetic.jl.git"
version = "0.22.17"
version = "0.22.19"

[deps]
CRlibm_jll = "4e9b3aee-d8a1-5a3d-ad8b-7d824db253f0"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
RoundingEmulator = "5eaf0fd0-dfba-4ccb-bf02-d820a40db705"

[weakdeps]
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
<<<<<<< HEAD
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
=======
>>>>>>> JuliaIntervals/master

[extensions]
IntervalArithmeticDiffRulesExt = "DiffRules"
IntervalArithmeticForwardDiffExt = "ForwardDiff"
IntervalArithmeticIntervalSetsExt = "IntervalSets"
<<<<<<< HEAD
IntervalArithmeticLinearAlgebraExt = "LinearAlgebra"
IntervalArithmeticRecipesBaseExt = "RecipesBase"
=======
>>>>>>> JuliaIntervals/master

[compat]
CRlibm_jll = "1"
Expand Down
6 changes: 5 additions & 1 deletion ext/IntervalArithmeticForwardDiffExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module IntervalArithmeticForwardDiffExt

using IntervalArithmetic, ForwardDiff
using ForwardDiff: Dual, , value, partials
using ForwardDiff: Dual, Partials, , value, partials

# Needed to avoid method ambiguities:
ForwardDiff.can_dual(::Type{ExactReal}) = true
Expand Down Expand Up @@ -90,4 +90,8 @@ function Base.:(^)(x::ExactReal, y::Dual{<:Ty}) where {Ty}
end
end

# resolve ambiguity

Base.convert(::Type{Dual{T,V,N}}, x::ExactReal) where {T,V,N} = Dual{T}(V(x), zero(Partials{N,V}))

end
24 changes: 19 additions & 5 deletions src/IntervalArithmetic.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
IntervalArithmetic
Library for validated numerics using interval arithmetic.
Learn more: https://github.com/JuliaIntervals/IntervalArithmetic.jl
"""
module IntervalArithmetic

import CRlibm_jll
Expand All @@ -8,16 +15,23 @@ using MacroTools: MacroTools, prewalk, postwalk, @capture
#

include("intervals/intervals.jl")
# convenient alias
const RealOrComplexI{T} = Union{Interval{T},Complex{Interval{T}}}
const ComplexI{T} = Complex{Interval{T}}
const RealIntervalType{T} = Union{BareInterval{T},Interval{T}}
export RealOrComplexI, ComplexI, RealIntervalType

#

include("display.jl")
export setdisplay

#

include("symbols.jl")

# convenient alias
const RealOrComplexI{T} = Union{Interval{T},Complex{Interval{T}}}
const ComplexI{T} = Complex{Interval{T}}
const RealIntervalType{T} = Union{BareInterval{T},Interval{T}}
export RealOrComplexI, ComplexI, RealIntervalType
#

include("matmul.jl")

end
8 changes: 4 additions & 4 deletions src/intervals/construction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,6 @@ isguaranteed(x::Complex{<:Interval}) = isguaranteed(real(x)) & isguaranteed(imag

isguaranteed(::Number) = false

Interval{T}(x::Interval) where {T<:NumTypes} = convert(Interval{T}, x) # needed to resolve method ambiguity
# Interval{T}(x) where {T<:NumTypes} = convert(Interval{T}, x)
# Interval{T}(x::Interval{T}) where {T<:NumTypes} = convert(Interval{T}, x) # needed to resolve method ambiguity

#

"""
Expand Down Expand Up @@ -569,6 +565,10 @@ Base.promote_rule(::Type{T}, ::Type{Interval{S}}) where {T<:AbstractIrrational,S

# conversion

Interval{T}(x::Real) where {T<:NumTypes} = convert(Interval{T}, x)
Interval(x::Real) = Interval{promote_numtype(numtype(x), numtype(x))}(x)
Interval{T}(x::Interval) where {T<:NumTypes} = convert(Interval{T}, x) # needed to resolve method ambiguity

Base.convert(::Type{Interval{T}}, x::Interval) where {T<:NumTypes} = interval(T, x)

function Base.convert(::Type{Interval{T}}, x::Complex{<:Interval}) where {T<:NumTypes}
Expand Down
6 changes: 5 additions & 1 deletion src/intervals/exact_literals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ Base.promote_rule(::Type{ExactReal{T}}, ::Type{ExactReal{S}}) where {T<:Real,S<:

# to BareInterval

BareInterval{T}(x::ExactReal) where {T<:NumTypes} = convert(BareInterval{T}, x)
BareInterval(x::ExactReal) = BareInterval{promote_numtype(numtype(x.value), numtype(x.value))}(x)

Base.convert(::Type{BareInterval{T}}, x::ExactReal) where {T<:NumTypes} = bareinterval(T, x.value)

Base.promote_rule(::Type{BareInterval{T}}, ::Type{ExactReal{S}}) where {T<:NumTypes,S<:Real} =
Expand All @@ -107,8 +110,9 @@ Base.promote_rule(::Type{ExactReal{T}}, ::Type{Interval{S}}) where {T<:Real,S<:N

# to Real

# allows Interval{<:NumTypes}(::ExactReal)
(::Type{T})(x::ExactReal) where {T<:Real} = convert(T, x)
Interval{T}(x::ExactReal) where {T<:NumTypes} = convert(Interval{T}, x) # needed to resolve ambiguity
Interval(x::ExactReal) = Interval{promote_numtype(numtype(x.value), numtype(x.value))}(x) # needed to resolve ambiguity

Base.convert(::Type{T}, x::ExactReal) where {T<:Real} = convert(T, x.value)

Expand Down
2 changes: 1 addition & 1 deletion src/intervals/interval_operations/boolean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function isdisjoint_interval(x::AbstractVector, y::AbstractVector)
return any(t -> isdisjoint_interval(t[1], t[2]), zip(x, y))
end

isdisjoint_interval(x, y, z, w...) = isdisjoint_interval(x, y) & isdisjoint_interval(y, z, w...)
isdisjoint_interval(x, y, z, w...) = isdisjoint_interval(x, y) & isdisjoint_interval(x, z) & isdisjoint_interval(y, z, w...)

"""
isweakless(x, y)
Expand Down
2 changes: 1 addition & 1 deletion src/intervals/intervals.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Construction and composability with numbers
include("construction.jl")
export BareInterval, bareinterval, decoration, ill, trv, def, dac, com,
Interval, interval, isguaranteed, @interval, @I_str
Interval, interval, isguaranteed, @interval, @I_str
include("parsing.jl")
include("real_interface.jl")
include("exact_literals.jl")
Expand Down
Loading

0 comments on commit 082dff6

Please sign in to comment.