-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: astype(copy=False)
and asarray
deep-copy the buffer when changing signedness
#27509
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
Thanks for the report! I believe this is working as intended: import numpy as np
x = np.arange(4, dtype='int64')
x2 = x.view('uint64') |
Just to add to @jakevdp's com
B1C2
ment - |
We have the ability to implement a cast as "just a view" now. But we didn't do that here to not change behavior (astype doesn't matter, but |
Describe the issue:
When
ndarray.astype(..., copy=False)
converts between two dtypes with same word size that exclusively differ in signedness, it deep-copies the buffer but there's no reason for it to do so, as the two formats exclusively differ by the meaning attributed to the most-significant bit.This issue also affects
np.asarray(..., dtype=...)
which I presume internally callsndarray.astype(..., copy=False)
.Expected behaviour
An array with dtype=uintX could and should be a view of another array with dtype=intX, and vice versa.
Related
astype
that would raise in case of overflow #25396Reproduce the code example:
Error message:
No response
Python and NumPy Versions:
python 3.12, numpy 2.1.1,
Runtime Environment:
conda linux x86_64
Context for the issue:
No response
The text was updated successfully, but these errors were encountered: