-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
issubset aces Discrete Math but flunks Topology #28871
Conversation
does this work with testing if open intervals subset other open intervals? |
Assuming an help?> issubset
search: issubset
issubset(a, b)
⊆(a,b) -> Bool
⊇(b, a) -> Bool
Determine whether every element of a is also in b, using in. so (EDIT: the docstring doesn't preclude a specialized definition, of course. But there isn't a reasonable fallback definition if the first argument isn't iterable.) |
base/abstractset.jl
Outdated
|
||
if rlen > lenthresh && !isa(r, AbstractSet) | ||
return issubset(l, Set(r)) | ||
if IteratorSize(r) isa Union{HasLength,HasShape} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a function defined for that: Base.haslength(r)
;-)
Updated to use |
(cherry picked from commit 24de931)
(cherry picked from commit 24de931)
(cherry picked from commit 24de931)
(cherry picked from commit 24de931)
#26198 did some fantastic performance tuning of
issubset
based on a very thorough analysis of scaling behavior. However, the change implicitly assumed that the "superset" is countable, specifically thatlength
is defined and will return an integer value. Ranges are an example of a container for which this succeeds (this example leverages the fact that numbers are iterable):So far so good. However,
length
can't be reasonably defined for many mathematical sets, and as a consequence bad things happen inissubset
:This PR addresses the issue in a minimalistic fashion: it checks the
IteratorSize
trait of the superset, and skips the performance-tuning block iflength
can't reasonably be expected to succeed.This isn't an ideal solution, because
HasLength()
is the default, but at least it gives package authors a means to avoid the bad behavior.