Skip to content

Commit 4fcf410

Browse files
committed
remove methods for eltype and add boundstype
1 parent 5148556 commit 4fcf410

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/IntervalSets.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module IntervalSets
22

3-
using Base: @pure
4-
import Base: eltype, convert, show, in, length, isempty, isequal, isapprox, issubset, ==, hash,
3+
import Base: convert, show, in, length, isempty, isequal, isapprox, issubset, ==, hash,
54
union, intersect, minimum, maximum, extrema, range, clamp, mod, float, , ,
65

76
using Random
@@ -62,8 +61,9 @@ isclosedset(d::AbstractInterval) = isleftclosed(d) && isrightclosed(d)
6261
"Is the interval open?"
6362
isopenset(d::AbstractInterval) = isleftopen(d) && isrightopen(d)
6463

65-
eltype(::Type{AbstractInterval{T}}) where {T} = T
66-
eltype(::Type{I}) where {I<:AbstractInterval{T}} where T = T
64+
boundstype(i::AbstractInterval) = boundstype(typeof(i))
65+
boundstype(::Type{AbstractInterval{T}}) where {T} = T
66+
boundstype(::Type{I}) where {I<:AbstractInterval{T}} where T = T
6767

6868
convert(::Type{AbstractInterval}, i::AbstractInterval) = i
6969
convert(::Type{AbstractInterval{T}}, i::AbstractInterval{T}) where T = i
@@ -141,7 +141,7 @@ isequal(A::TypedEndpointsInterval, B::TypedEndpointsInterval) = isempty(A) & ise
141141
==(A::TypedEndpointsInterval{L,R}, B::TypedEndpointsInterval{L,R}) where {L,R} = (leftendpoint(A) == leftendpoint(B) && rightendpoint(A) == rightendpoint(B)) || (isempty(A) && isempty(B))
142142
==(A::TypedEndpointsInterval, B::TypedEndpointsInterval) = isempty(A) && isempty(B)
143143

144-
function isapprox(A::AbstractInterval, B::AbstractInterval; atol=0, rtol=Base.rtoldefault(eltype(A), eltype(B), atol), kwargs...)
144+
function isapprox(A::AbstractInterval, B::AbstractInterval; atol=0, rtol=Base.rtoldefault(boundstype(A), boundstype(B), atol), kwargs...)
145145
closedendpoints(A) != closedendpoints(B) && error("Comparing intervals with different closedness is not defined")
146146
isempty(A) != isempty(B) && return false
147147
isempty(A) && isempty(B) && return true

test/runtests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Statistics: mean
66
using Random
77
using Unitful
88

9-
import IntervalSets: Domain, endpoints, closedendpoints, TypedEndpointsInterval
9+
import IntervalSets: Domain, endpoints, closedendpoints, TypedEndpointsInterval, boundstype
1010

1111
struct MyClosedUnitInterval <: TypedEndpointsInterval{:closed,:closed,Int} end
1212
endpoints(::MyClosedUnitInterval) = (0,1)
@@ -54,8 +54,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end
5454
O = @inferred x±y
5555
@test O == ClosedInterval(x-y, x+y)
5656

57-
@test eltype(I) == Int
58-
@test eltype(M) == Float64
57+
@test boundstype(I) == Int
58+
@test boundstype(M) == Float64
5959

6060
@test !isempty(I)
6161
@test isempty(J)
@@ -642,7 +642,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end
642642

643643
@testset "Custom intervals" begin
644644
I = MyUnitInterval(true,true)
645-
@test eltype(I) == eltype(typeof(I)) == Int
645+
@test boundstype(I) == boundstype(typeof(I)) == Int
646646
@test leftendpoint(I) == 0
647647
@test rightendpoint(I) == 1
648648
@test isleftclosed(I)
@@ -822,7 +822,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end
822822

823823
@testset "IncompleteInterval" begin
824824
I = IncompleteInterval()
825-
@test eltype(I) === Int
825+
@test boundstype(I) === Int
826826
@test_throws ErrorException endpoints(I)
827827
@test_throws ErrorException closedendpoints(I)
828828
@test_throws MethodError 2 in I

0 commit comments

Comments
 (0)