-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: np.arange()
with int dtype can return inprecisely-sized arrays
#20226
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
Labels
Comments
@pearu noted that the problem is indeed likely due to the use of true division in numpy/numpy/core/src/multiarray/ctors.c Line 3054 in d5f6618
|
This is very similar to #18881. |
We can use integer-devide instead of number-devide
|
there is number-devide(__truediv__), we can change it to integer-devide(__floordiv__) |
old code (python ver.)
new code (python ver.)
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Describe the issue:
Given a distance
stop - start
which very largely outsizesstep
,np.arange()
can produce an arrayx
which hasx.size
as 1 off the expected size. My guess is that internally, the non-integer result of distance divided by the step(stop - start) / step
becomes represented as an "integer" with floating-point representation, and thus does not indicate that one more array element should be generated.Notably
np.arange()
with float arguments has a great many related issues—it looks like the inprecision in those scenarios seems to be considered "acceptable behaviour" and has been noted in the docs as such. However as in #18881, because the dtype is specified as an integer, people might have different thoughts. cc @asmeurerI found this via a Hypothesis-powered test method I wrote for the Array API test suite.
Reproduce the code example:
NumPy/Python version information:
The text was updated successfully, but these errors were encountered: