Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compute intersect of multiple intervals #166

Open
glennmoy opened this issue Jun 2, 2021 · 2 comments
Open

Cannot compute intersect of multiple intervals #166

glennmoy opened this issue Jun 2, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@glennmoy
Copy link
Member

glennmoy commented Jun 2, 2021

Base.intersect can accept multiple arguments, but Intervals.intersect only accepts two.
This is limiting if one wants to compute the intersection of multiple intervals at the same time.

MWE

julia> intersect(1..10, 1..3, 1..6)
ERROR: MethodError: no method matching length(::Interval{Int64, Closed, Closed})
Closest candidates are:
  length(::Union{Base.KeySet, Base.ValueIterator}) at abstractdict.jl:58
  length(::Union{LinearAlgebra.Adjoint{T, S}, LinearAlgebra.Transpose{T, S}} where {T, S}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/adjtrans.jl:195
  length(::Union{DataStructures.OrderedRobinDict, DataStructures.RobinDict}) at /Users/glenn/.julia/packages/DataStructures/ixwFs/src/ordered_robin_dict.jl:86
  ...
Stacktrace:
 [1] union!(s::Set{Int64}, itr::Interval{Int64, Closed, Closed})
   @ Base ./abstractset.jl:89
 [2] Set{Int64}(itr::Interval{Int64, Closed, Closed})
   @ Base ./set.jl:10
 [3] _Set(itr::Interval{Int64, Closed, Closed}, #unused#::Base.HasEltype)
   @ Base ./set.jl:23
 [4] Set(itr::Interval{Int64, Closed, Closed})
   @ Base ./set.jl:21
 [5] _shrink(shrinker!::Function, itr::Interval{Int64, Closed, Closed}, itrs::Tuple{Interval{Int64, Closed, Closed}, Interval{Int64, Closed, Closed}})
   @ Base ./array.jl:2607
 [6] intersect(::Interval{Int64, Closed, Closed}, ::Interval{Int64, Closed, Closed}, ::Interval{Int64, Closed, Closed})
   @ Base ./array.jl:2611
 [7] top-level scope
   @ REPL[128]:1

Compared to Base.intersect

julia> intersect(1:10, 1:3, 1:6)
1:3
@glennmoy glennmoy added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Jun 2, 2021
@omus
Copy link
Collaborator

omus commented Jun 2, 2021

Work around if you want one:

julia> foldl(intersect, [1..10, 1..3, 1..6])
Interval{Int64, Closed, Closed}(1, 3)

@glennmoy
Copy link
Member Author

glennmoy commented Jun 2, 2021

thanks! this came up during a POC discussion so it's not blocking but I might try my hand at the fix during the week if I get the chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants