-
Notifications
You must be signed in to change notification settings - Fork 97
Support of alternative array classes: ndarray-like #305
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
Conversation
@joshmoore do you have thoughts here? 🙂 |
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.
Beyond one minor question on my part (and @jakirkham's about installing typing_extensions
, it looks good. The plan here would be to try to consume it from zarr-developers/zarr-python#934?
I don't have any thing to add to the review, but just wanted to chime in to say I think this is a great feature. Supporting different array-like things is really important for future interoperability of zarr / numcodecs. 👏 |
Anything else we need in this PR? Else, I think it is ready to be merged. |
@joshmoore, @jakirkham anything else we need to do here? I don't think the CI error relates to this PR. |
Regarding CI. Fixing in PR ( #311 ) |
Thanks for working on this Mads! 😄 Also appreciate Ryan and Josh taking the time to look. Would you be able to fix up the merge conflicts, Mads? 🙂 Generally LGTM. Though would be great if someone other than me merged (assuming people have no further questions) |
Sure, it is merged :) |
Thanks Mads! 😀 @joshmoore or @rabernat if you are comfortable with the changes here, please feel free to merge (if not please let us know what is still needed)? Thanks! |
Nothing else from my side. Thoughts on getting this out as either 0.10 or is there a preference for another pre-release? (@MSanKeys963 would likely also ask if a blog post is in order :) If so, text blurbs welcome) |
Happy to write a blog post on this as this focuses on interoperability. @madsbk would you like to help me with the blog post? If yes, I can post a few questions and you can answer them. |
Sure, that sounds great! |
👍 all around. Any thoughts on the release style? |
I think including it in the v0.10 release is good but can we merge it now? It will help me finishing zarr-developers/zarr-python#934. |
Ok with either release style. No strong preferences. This is more internally facing (though would be used by Zarr too) and the same APIs Zarr uses are present. So would expect things to still work Edit: Also sorry for being somewhat quiet here, was out sick most of the week. |
Thanks all! 😄 |
Thanks! |
This reverts commit 9976f06.
Building now as v0.10.0.a3 |
Thanks Josh! 😄 |
* Implement CuPyCPUCompressor and the meta_array argument This is base of <https://github.com/jakirkham/zarr-python/tree/use_array_like> Co-authored-by: John Kirkham <[email protected]> * Adding meta_array to open_group() * CuPyCPUCompressor: clean up and doc * clean up * flake8 * mypy * Use KVStore when checking for in-memory data Checking against MutableMapping categories all BaseStores as in-memory stores. * group: the meta_array argument is now used for new arrays * flake8 * Use empty_like instead of empty Co-authored-by: jakirkham <[email protected]> * More use of NumPy's *_like API Co-authored-by: jakirkham <[email protected]> * Assume that array-like objects that doesn't have a `writeable` flag is writable. * _meta_array: use shape=() Co-authored-by: jakirkham <[email protected]> * use ensure_ndarray_like() and ensure_contiguous_ndarray_like() * CI: use zarr-developers/numcodecs#305 * Removed unused code Co-authored-by: Tobias Kölling <[email protected]> * CI: changed minimal NumPy version to v1.20 * CI: use numpy>=1.21.* for `mypy` check * Revert "CI: use zarr-developers/numcodecs#305" This reverts commit 9976f06. * fix merge mistake * CI: remove manual numpy install * pickle: use kwargs * moved CuPyCPUCompressor to the test suite * doc-meta_array: changed to versionadded:: 2.13 * test_cupy: assert meta_array * test_cupy: test when CuPy isn't available * renamed: test_cupy.py -> test_meta_array.py * removed ensure_cls() * Added "# pragma: no cover" to the CuPyCPUCompressor test class Co-authored-by: John Kirkham <[email protected]> Co-authored-by: Josh Moore <[email protected]> Co-authored-by: Tobias Kölling <[email protected]> Co-authored-by: Gregory Lee <[email protected]>
* Implement CuPyCPUCompressor and the meta_array argument This is base of <https://github.com/jakirkham/zarr-python/tree/use_array_like> Co-authored-by: John Kirkham <[email protected]> * Adding meta_array to open_group() * CuPyCPUCompressor: clean up and doc * clean up * flake8 * mypy * Use KVStore when checking for in-memory data Checking against MutableMapping categories all BaseStores as in-memory stores. * group: the meta_array argument is now used for new arrays * flake8 * Use empty_like instead of empty Co-authored-by: jakirkham <[email protected]> * More use of NumPy's *_like API Co-authored-by: jakirkham <[email protected]> * Assume that array-like objects that doesn't have a `writeable` flag is writable. * _meta_array: use shape=() Co-authored-by: jakirkham <[email protected]> * use ensure_ndarray_like() and ensure_contiguous_ndarray_like() * CI: use zarr-developers/numcodecs#305 * Removed unused code Co-authored-by: Tobias Kölling <[email protected]> * CI: changed minimal NumPy version to v1.20 * CI: use numpy>=1.21.* for `mypy` check * Revert "CI: use zarr-developers/numcodecs#305" This reverts commit 9976f067a42c99b37e2c1a57ef7377b0b34f9318. * fix merge mistake * CI: remove manual numpy install * pickle: use kwargs * moved CuPyCPUCompressor to the test suite * doc-meta_array: changed to versionadded:: 2.13 * test_cupy: assert meta_array * test_cupy: test when CuPy isn't available * renamed: test_cupy.py -> test_meta_array.py * removed ensure_cls() * Added "# pragma: no cover" to the CuPyCPUCompressor test class Co-authored-by: John Kirkham <[email protected]> Co-authored-by: Josh Moore <[email protected]> Co-authored-by: Tobias Kölling <[email protected]> Co-authored-by: Gregory Lee <[email protected]>
This PR implements support of alternative array types (other than NumPy arrays) by introducing the concept ndarray-like.
The idea is to differentiate between the need of a
numpy.ndarray
and an array that behaves like a NumPy array, such as a CuPy array. Calling the old compat functions will still return regular NumPy arrays but two new compat functions now accept any NumPy array-like arrays:NumPy array like
I suggest that we use Python3.8's
typing.Protocol
to define what we consider ndarray-like:This requires Python v3.8. If this is a problem, we can use the
typing_extensions
module as a fallback:Motivation
This is the first step towards support of CuPy arrays in Zarr.
TODO:
bytes
inensure_text
#213tox -e py39
passes locallytox -e docs
passes locallycc. @jakirkham