-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
linspace with int dtype sometimes doesn't include endpoints #18881
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
Comments
It is going through float64, which has insufficient precision.
Also
|
This looks like a clear bug, integer input should not use any floating-point intermediate values. |
|
Use |
I've always saw it as "use |
Well, what people want and what people can have when numerical airthmetic is concerned are often disjoint sets. :-) Sometimes, the limitations of floating point arithmetic force us to recast what we want (something that usually makes perfect sense with real-number arithmetic like "increments from 0 to 1, inclusive, by steps of 0.1") into something that we can actually compute reliably ( Fundamentally, I don't think we should have two different paths for |
That may be correct, but
then this is the problem. A On the other hand, there does seem to be a separate complex path:
So there's no real reason for there not to be a separate integer path, where if start/stop/step are integers it would use integer division to calculate step size. There's probably no reasonable way to change it anymore at this point, but either implementing an integer path or disallowing it would have been better. Like, e.g., this:
|
I doubt calculating a step size with integer division would be desirable - I find it unlikely someone using |
Yes, and if I had seen that change come across when it happened, I'd have complained then, too. |
Hmmm, I guess the argument does make sense for |
I'm not necessarily arguing that there can't be a separate integer path. But what would be needed to get the requested behaviors is a separate path depending on the precise values of It seems like there are three different expectations about what ought to happen when Because of this variety of expectations, I'd actually lean towards deprecating |
That I agree with, very much undesirable. My expectation would be to apply casting rules to all inputs; if they're all integer then just use integer division (i.e.
Yes, that seems like the best option indeed. |
Removing the |
(notice that the last digit has been changed from a 3 to a 2)
It's not clear to me if this should be considered a bug, or if this is expected from the way linspace inherently has to do rounding.
I found #16813 which seems related.
The text was updated successfully, but these errors were encountered: