-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: support no-copy pickling for any array that can be transposed to a C-contiguous array #26878
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
That seems like an improvement. It would need a release note since you would fix that pickle roundtripping retains order (i.e. Other than that, it seems fine to just do it, there is a EDIT: It occured to me that it may be possible to unpickle via |
@yangdong02 is busy, I will try to implement this. |
Closed by #28105 |
Proposed new feature or change:
Following #11161 and related PR, we can support no-copy pickling for C-contiguous and Fortran-contiguous numpy arrays. However, if we have a 3D C-contiguous array, then transpose its first two axis (e.g.
np.random.rand(2,3,4).transpose((1,0,2))
), it will be neither C-contiguous nor Fortran-contiguous, therefore won't enjoy no-copy pickling. To address this, can we generalize no-copy pickling further to any numpy arrays that can be transposed to a C-contiguous arrays?Implementing this should be simple. In fact, Fortran-contiguous numpy arrays is supported via transposing to C-contiguous array during serialization, then transpose back during deserialization (see below code). We can generalize this idea:
I can implement this feature and create a PR if you think this enhancement makes sense :)
numpy/numpy/_core/src/multiarray/methods.c
Lines 1877 to 1885 in b77d2c6
numpy/numpy/_core/numeric.py
Lines 1914 to 1915 in b77d2c6
The text was updated successfully, but these errors were encountered: