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

Add superset function #42

Merged
merged 2 commits into from
Jul 17, 2018
Merged

Add superset function #42

merged 2 commits into from
Jul 17, 2018

Conversation

omus
Copy link
Collaborator

@omus omus commented Jul 14, 2018

  • Add superset function that creates an interval which encompasses all of the intervals within an array
  • Rename interval check functions to start with "is" (with deprecations)
  • Add Interval constructor which takes Endpoints

src/interval.jl Outdated
"""
superset(intervals::AbstractArray{<:AbstractInterval}) -> Interval

Create a single interval which encompasses all of the provided intervals.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be worthwhile to mention that this is the smallest such interval?

src/interval.jl Outdated
Create a single interval which encompasses all of the provided intervals.
"""
function superset(intervals::AbstractArray{<:AbstractInterval})
left = minimum(Intervals.LeftEndpoint.(intervals))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be more efficient to only make one pass over the array by providing the function as an argument to maximum and minimum, e.g.

left = minimum(LeftEndpoint, intervals)
right = maximum(RightEndpoint, intervals)

(Also note that the module prefix shouldn't be necessary within the module.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I was developing this in the REPL which is why I have the module prefix

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it isn't more efficient:

julia> @btime superset([1..2, 4..5])  # minimum(LeftEndpoint.(intervals))
  123.302 ns (5 allocations: 416 bytes)
Interval{Int64}(1, 5, Inclusivity(true, true))

julia> @btime superset([1..2, 4..5])  # minimum(LeftEndpoint, intervals)
  1.363 μs (17 allocations: 640 bytes)
Interval{Int64}(1, 5, Inclusivity(true, true))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's... really weird. 🤔


# BEGIN Intervals 0.1 deprecations

@deprecate less_than_disjoint(a, b) is_less_than_disjoint(a, b) true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to reuse some Base terminology here and call it like isless_disjoint?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is better. Do you think that greater_than_disjoint(a, b) should be deprecated to isless_disjoint(b, a)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that seems reasonable.

@codecov
Copy link

codecov bot commented Jul 15, 2018

Codecov Report

Merging #42 into master will increase coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #42      +/-   ##
==========================================
+ Coverage   98.07%   98.12%   +0.04%     
==========================================
  Files           6        6              
  Lines         208      213       +5     
==========================================
+ Hits          204      209       +5     
  Misses          4        4
Impacted Files Coverage Δ
src/Intervals.jl 100% <ø> (ø) ⬆️
src/interval.jl 96.73% <100%> (+0.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 171b831...b0c0b05. Read the comment docs.

@omus
Copy link
Collaborator Author

omus commented Jul 15, 2018

Tests pass on Julia 0.6. Looks like some breaking changes happened in 0.7 since #30

@ararslan
Copy link
Contributor

Looks like that was JuliaLang/julia#27302.

@omus
Copy link
Collaborator Author

omus commented Jul 17, 2018

Rebased on top of #43 which should address the 0.7 issues

@omus
Copy link
Collaborator Author

omus commented Jul 17, 2018

32-bit issues on AppVeyor with Coverage. Intervals test all pass.

src/interval.jl Outdated
"""
≪(a::AbstractInterval, b::AbstractInterval) -> Bool
less_than_disjoint(a::AbstractInterval, b::AbstractInterval) -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps just change the reference here to isless_disjoint?

Copy link
Collaborator Author

@omus omus Jul 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up removing the reference here as there isn't a isgreater_disjoint for the other docstring. Additionally, this specific docstring will only appear with help?> ≪ and not with help?> isless_disjoint / help?> less_than_disjoint

src/interval.jl Outdated
@@ -228,26 +231,26 @@ end
Base.:⊈(a::AbstractInterval, b::AbstractInterval) = !issubset(a, b)
Base.:⊉(a::AbstractInterval, b::AbstractInterval) = !issubset(b, a)

function overlaps(a::AbstractInterval, b::AbstractInterval)
function isoverlapping(a::AbstractInterval, b::AbstractInterval)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think overlaps is easier to read and has precedent with contains as a predicate name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though contains is deprecated in 0.7 in favor of occursin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same deal with plural predicate though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Jeff's rule of thumb for 2-arg predicates is that it reads like English if the function is put between the arguments. To that end, a overlaps b makes sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change these back. Mainly I was thinking about these after changing less_than_disjoint to isless_disjoint and was thinking these should also start with is for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Votes are to leave this as overlaps?

src/interval.jl Outdated
left = max(LeftEndpoint(a), LeftEndpoint(b))
right = min(RightEndpoint(a), RightEndpoint(b))

return left <= right
end

function contiguous(a::AbstractInterval, b::AbstractInterval)
function iscontiguous(a::AbstractInterval, b::AbstractInterval)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is implies a predicate with one value. I think contiguous is fine but I don't have an issue with changing this. If you do change it, however, it should be arecontiguous.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based upon Alex's comment should this be contiguouswith? For example a contiguouswith b.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively: adjacentto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to go with the "adjacent" terminology rather than "contiguous," I think adjacent itself is a fine enough name. That said, I don't really have a problem with contiguous, but I find continugouswith to be a bit of a mouthful.

@omus
Copy link
Collaborator Author

omus commented Jul 17, 2018

I'm going to move the "is" changes to another PR as they seem more controversial (see #45)

@iamed2 iamed2 merged commit 6b051a1 into master Jul 17, 2018
@iamed2 iamed2 deleted the cv/superset branch July 17, 2018 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants