-
-
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
Replace isfinite check in ranges with lo ≤ x ≤ hi #45646
Conversation
Needs a test probably? |
@oscardssmith Review? |
This looks good, but ranges are very finicky, so this probably should get a pkgeval. |
base/range.jl
Outdated
if !isfinite(x) | ||
return false | ||
elseif iszero(step(r)) | ||
if iszero(step(r)) |
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.
if iszero(step(r)) | |
isnan(x) && return false | |
if iszero(step(r)) |
The isfinite
check implicitly covered NaNs. I think an explicit check for NaN is necessary if it's removed? Otherwise NaN in 1.0:2.0
would throw instead of returning false
.
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.
Good catch! Unfortunately, that fix will not work because we don't have isnan
for non-numeric ranges.
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.
I used first(r) <= x <= last(r)
instead.
This should now also support empty ranges with undefined |
Is the set of assumptions we can make about an |
@nanosoldier |
Your package evaluation job has completed - possible new issues were detected. A full report can be found here. |
@nanosoldier |
Your package evaluation job has completed - no new issues were detected. A full report can be found here. |
PkgEval game back positive and I think this is ready to go if someone is willing to give it a final look over. |
looks good to me. |
Co-authored-by: Viral B. Shah <[email protected]> (cherry picked from commit 5811825)
Co-authored-by: Viral B. Shah <[email protected]> (cherry picked from commit 5811825)
Co-authored-by: Viral B. Shah <[email protected]> (cherry picked from commit 5811825)
Co-authored-by: Viral B. Shah <[email protected]> (cherry picked from commit 5811825)
Co-authored-by: Viral B. Shah <[email protected]> (cherry picked from commit 5811825)
Co-authored-by: Viral B. Shah <[email protected]> (cherry picked from commit 5811825)
Co-authored-by: Viral B. Shah <[email protected]> (cherry picked from commit 5811825)
This
isfinite
check is a problem in at least two cases:a
,a ∈ 1:a^2
should holdAbstractRange
states "Supertype for ranges with elements of type T. UnitRange and other types are subtypes of this." (T need not be a number) whereasisfinite
's docstring states "Test whether a number is finite." This check breaks range membership checks for non-numeric elements.The check does not maken = round(Integer, (x - first(r)) / step(r)) + 1
much safer because it is possible to have a number that is too large to round to an Integer and still finite.The new check makes
n = round(Integer, (x - first(r)) / step(r)) + 1
much safer, but it could still throw for ranges with length greater thantypemax(Int)
. Fixes #45747.