From f4a08433693d1ac0e14a72f47bdbf1fd762815ec Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sun, 30 Jul 2023 03:49:11 +0900 Subject: [PATCH 1/6] update `eltype(::Type{I}) where {I<:AbstractInterval{T}}` --- src/IntervalSets.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IntervalSets.jl b/src/IntervalSets.jl index 516dbb3..6f3ff6c 100644 --- a/src/IntervalSets.jl +++ b/src/IntervalSets.jl @@ -63,7 +63,7 @@ isclosedset(d::AbstractInterval) = isleftclosed(d) && isrightclosed(d) isopenset(d::AbstractInterval) = isleftopen(d) && isrightopen(d) eltype(::Type{AbstractInterval{T}}) where {T} = T -@pure eltype(::Type{I}) where {I<:AbstractInterval} = eltype(supertype(I)) +eltype(::Type{I}) where {I<:AbstractInterval{T}} where T = T convert(::Type{AbstractInterval}, i::AbstractInterval) = i convert(::Type{AbstractInterval{T}}, i::AbstractInterval{T}) where T = i From 077c56f1e242699a345cb37cd06c6a438ccf0041 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Sun, 30 Jul 2023 04:06:54 +0900 Subject: [PATCH 2/6] remove methods for `eltype` and add boundstype --- src/IntervalSets.jl | 10 +++++----- test/runtests.jl | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/IntervalSets.jl b/src/IntervalSets.jl index 6f3ff6c..576403b 100644 --- a/src/IntervalSets.jl +++ b/src/IntervalSets.jl @@ -1,7 +1,6 @@ module IntervalSets -using Base: @pure -import Base: eltype, convert, show, in, length, isempty, isequal, isapprox, issubset, ==, hash, +import Base: convert, show, in, length, isempty, isequal, isapprox, issubset, ==, hash, union, intersect, minimum, maximum, extrema, range, clamp, mod, float, ⊇, ⊊, ⊋ using Random @@ -62,8 +61,9 @@ isclosedset(d::AbstractInterval) = isleftclosed(d) && isrightclosed(d) "Is the interval open?" isopenset(d::AbstractInterval) = isleftopen(d) && isrightopen(d) -eltype(::Type{AbstractInterval{T}}) where {T} = T -eltype(::Type{I}) where {I<:AbstractInterval{T}} where T = T +boundstype(i::AbstractInterval) = boundstype(typeof(i)) +boundstype(::Type{AbstractInterval{T}}) where {T} = T +boundstype(::Type{I}) where {I<:AbstractInterval{T}} where T = T convert(::Type{AbstractInterval}, i::AbstractInterval) = i convert(::Type{AbstractInterval{T}}, i::AbstractInterval{T}) where T = i @@ -141,7 +141,7 @@ isequal(A::TypedEndpointsInterval, B::TypedEndpointsInterval) = isempty(A) & ise ==(A::TypedEndpointsInterval{L,R}, B::TypedEndpointsInterval{L,R}) where {L,R} = (leftendpoint(A) == leftendpoint(B) && rightendpoint(A) == rightendpoint(B)) || (isempty(A) && isempty(B)) ==(A::TypedEndpointsInterval, B::TypedEndpointsInterval) = isempty(A) && isempty(B) -function isapprox(A::AbstractInterval, B::AbstractInterval; atol=0, rtol=Base.rtoldefault(eltype(A), eltype(B), atol), kwargs...) +function isapprox(A::AbstractInterval, B::AbstractInterval; atol=0, rtol=Base.rtoldefault(boundstype(A), boundstype(B), atol), kwargs...) closedendpoints(A) != closedendpoints(B) && error("Comparing intervals with different closedness is not defined") isempty(A) != isempty(B) && return false isempty(A) && isempty(B) && return true diff --git a/test/runtests.jl b/test/runtests.jl index e36a964..7f9ddb1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,7 +6,7 @@ import Statistics: mean using Random using Unitful -import IntervalSets: Domain, endpoints, closedendpoints, TypedEndpointsInterval +import IntervalSets: Domain, endpoints, closedendpoints, TypedEndpointsInterval, boundstype struct MyClosedUnitInterval <: TypedEndpointsInterval{:closed,:closed,Int} end endpoints(::MyClosedUnitInterval) = (0,1) @@ -54,8 +54,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end O = @inferred x±y @test O == ClosedInterval(x-y, x+y) - @test eltype(I) == Int - @test eltype(M) == Float64 + @test boundstype(I) == Int + @test boundstype(M) == Float64 @test !isempty(I) @test isempty(J) @@ -642,7 +642,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end @testset "Custom intervals" begin I = MyUnitInterval(true,true) - @test eltype(I) == eltype(typeof(I)) == Int + @test boundstype(I) == boundstype(typeof(I)) == Int @test leftendpoint(I) == 0 @test rightendpoint(I) == 1 @test isleftclosed(I) @@ -822,7 +822,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end @testset "IncompleteInterval" begin I = IncompleteInterval() - @test eltype(I) === Int + @test boundstype(I) === Int @test_throws ErrorException endpoints(I) @test_throws ErrorException closedendpoints(I) @test_throws MethodError 2 in I From fc1f9ea99c487a2ac9f968d1ae4b677638d3afc6 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Tue, 1 Aug 2023 13:10:55 +0900 Subject: [PATCH 3/6] remove unnecessary `boundstype` method, add `@deprecate Base.eltype` --- src/IntervalSets.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IntervalSets.jl b/src/IntervalSets.jl index 576403b..72122be 100644 --- a/src/IntervalSets.jl +++ b/src/IntervalSets.jl @@ -62,8 +62,8 @@ isclosedset(d::AbstractInterval) = isleftclosed(d) && isrightclosed(d) isopenset(d::AbstractInterval) = isleftopen(d) && isrightopen(d) boundstype(i::AbstractInterval) = boundstype(typeof(i)) -boundstype(::Type{AbstractInterval{T}}) where {T} = T boundstype(::Type{I}) where {I<:AbstractInterval{T}} where T = T +@deprecate Base.eltype(I::Type{<:AbstractInterval}) boundstype(I) false convert(::Type{AbstractInterval}, i::AbstractInterval) = i convert(::Type{AbstractInterval{T}}, i::AbstractInterval{T}) where T = i From 72a705f2573bdb41c46b8b66a3add8c8fc10ffbb Mon Sep 17 00:00:00 2001 From: hyrodium Date: Tue, 1 Aug 2023 13:13:22 +0900 Subject: [PATCH 4/6] revert tests for `eltype` --- test/runtests.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 7f9ddb1..51dd71a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -56,6 +56,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end @test boundstype(I) == Int @test boundstype(M) == Float64 + @test eltype(I) == Int + @test eltype(M) == Float64 @test !isempty(I) @test isempty(J) @@ -643,6 +645,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end @testset "Custom intervals" begin I = MyUnitInterval(true,true) @test boundstype(I) == boundstype(typeof(I)) == Int + @test eltype(I) == eltype(typeof(I)) == Int @test leftendpoint(I) == 0 @test rightendpoint(I) == 1 @test isleftclosed(I) @@ -823,6 +826,7 @@ struct IncompleteInterval <: AbstractInterval{Int} end @testset "IncompleteInterval" begin I = IncompleteInterval() @test boundstype(I) === Int + @test eltype(I) === Int @test_throws ErrorException endpoints(I) @test_throws ErrorException closedendpoints(I) @test_throws MethodError 2 in I From dc49a75b6d3f1502cfccdb32b4b31a6043c43863 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Wed, 2 Aug 2023 00:22:38 +0900 Subject: [PATCH 5/6] fix depwarn for Julia 1.6 --- src/IntervalSets.jl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/IntervalSets.jl b/src/IntervalSets.jl index 72122be..80bff29 100644 --- a/src/IntervalSets.jl +++ b/src/IntervalSets.jl @@ -63,7 +63,15 @@ isopenset(d::AbstractInterval) = isleftopen(d) && isrightopen(d) boundstype(i::AbstractInterval) = boundstype(typeof(i)) boundstype(::Type{I}) where {I<:AbstractInterval{T}} where T = T -@deprecate Base.eltype(I::Type{<:AbstractInterval}) boundstype(I) false + +@static if VERSION < v"1.9" + function Base.eltype(I::Type{<:AbstractInterval}) + Base.depwarn("`eltype` for `AbstractInterval` will be replaced with `boundstype` in the next breaking release (v0.8.0).", :eltype) + boundstype(I) + end +else + @deprecate Base.eltype(I::Type{<:AbstractInterval}) boundstype(I) false +end convert(::Type{AbstractInterval}, i::AbstractInterval) = i convert(::Type{AbstractInterval{T}}, i::AbstractInterval{T}) where T = i From 60fa9e81d16d02947cf12381c5aec4064dfa8006 Mon Sep 17 00:00:00 2001 From: hyrodium Date: Wed, 2 Aug 2023 00:24:11 +0900 Subject: [PATCH 6/6] bump version to v0.7.8 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 0d4cefe..2d34bb0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "IntervalSets" uuid = "8197267c-284f-5f27-9208-e0e47529a953" -version = "0.7.7" +version = "0.7.8" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"