-
-
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
linspace with 1 or 0 elements is sorted #15245
Conversation
@@ -744,7 +744,7 @@ reverse(r::LinSpace) = LinSpace(r.stop, r.start, r.len, r.divisor) | |||
## sorting ## | |||
|
|||
issorted(r::UnitRange) = true | |||
issorted(r::Range) = step(r) >= zero(step(r)) | |||
issorted(r::Range) = length(r) <= 1 ? true : step(r) >= zero(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.
I think issorted(r::Range) = length(r) <= 1 || step(r) >= zero(step(r))
would look better.
23d473d
to
32c3342
Compare
@pabloferz agreed |
+1 Looks like this causes a dates test failure? Maybe that test is invalid. |
Yeah. It seems that the test in dates was relying on the previous incorrect behaviour. @gustafsson Seems that you would have to remove that test. |
3273b6a
to
1fba161
Compare
To clarify, this applies to any Range, not just linspace. For instance |
1fba161
to
93accd9
Compare
bump, this still applies in master, any comments? |
linspace of length 1 or 0 causes a step length of NaN which makes "issorted" return false.
I expected the same return value as the flattened data (collect of such a linspace) which has a true "issorted".