Repository navigation
Conversation
permute_dims reused the input chunks, which contain 0 for zero-size arrays and are rejected by blosc2.empty. Return an empty result directly instead.
Required by the 2024.12 Array API standard. Implemented on top of permute_dims. Refs Blosc#466
andyrochi
marked this pull request as ready for review
November 18, 2026 00:06
FrancescAlted
requested changes
Nov 23, 2026
FrancescAlted
left a comment
Member
There was a problem hiding this comment.
Thanks for the PR and for catching the zero-size permute_dims bug as well! The implementation looks clean overall. Before merging, could you address a couple of minor items?
- Fix
pre-commit.ci/ Ruff check:- In
src/blosc2/linalg.py(_normalize_moveaxis_axes),isinstance(axes, (int, np.integer))violates RuffUP038— please useisinstance(axes, int | np.integer)and runruff check/ruff format(orpre-commit run) across the modified files sopre-commit.cipasses.
- In
- Validate integer elements in axis sequences:
_normalize_moveaxis_axescurrently doesn't check element types whenaxesis a sequence, so e.g.moveaxis(a, (0.0,), (1,))silently succeeds andmoveaxis(a, (0.5,), (0,))raises aValueErrorinsidepermute_dimsinstead ofTypeError. Coercing each element withoperator.index(ax)handles this cleanly across NumPy 1.26 and 2.x.
- Additional test cases (nice to have):
- A zero-size
moveaxiscase (e.g. shape(2, 0, 3)), a 0-D case (shape=(), source=(), destination=()), a**kwargspass-through check (e.g.chunksorurlpath), and a non-integer sequence element ((0.5,)) raisingTypeError.
- A zero-size
Regarding your questions:
linalg.pyvsndarray.py: Keepingmoveaxisinlinalg.pyright next topermute_dimsandmatrix_transpose(and re-exporting at top-levelblosc2.moveaxis) fits the existing layout well.utils.linalg_funcs(lazy expressions): Leaving it out of this PR to keep it minimal is totally fine. If added in a follow-up, it will also needutils.linalg_shapeandexpression_graph.py(_SHAPESand_KEYWORDSforsource/destinationin safe mode).
Non-integer axes raised ValueError deep inside permute_dims or were silently accepted for 1-D input. Coerce each axis with operator.index so they raise TypeError, as in NumPy.
Add the blank line ruff format expects after the imports. This was already failing pre-commit.ci on main.
Author
|
Hi @FrancescAlted, thanks! I made the following changes according to your feedback:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #466
Adds
blosc2.moveaxis, which the 2024.12 Array API standard requires (blosc2 declares__array_api_version__ = "2024.12"). It's on the list of missing functions in this comment on #466, whichtest_has_nameschecks for. It computes the new axis order the same waynp.moveaxisdoes, then delegates topermute_dims. It accepts the same**kwargsaspermute_dims(e.g.urlpath).Note: like
permute_dims,moveaxisreturns a copy. A view would need axis-reordering views (#442).This PR also fixes a bug in
permute_dimson arrays with a zero-length dimension.moveaxisdepends on it.permute_dimsreused the input's chunks, which contain0for these arrays, andblosc2.emptyrejects those. Reproduce this onmain:Array API conformance
Run with array-api-tests (
ARRAY_API_TESTS_VERSION=2024.12):maintest_manipulation_functions.py::test_permute_dimstest_manipulation_functions.py::test_moveaxismoveaxisis not defined)test_has_names.py(moveaxis)Questions
moveaxisinlinalg.pyfor now sincepermute_dimslives there and this is just a wrapper for that. Butndarray.pyalso seems like a reasonable place for it to live, since the Array API groupsmoveaxiswith the manipulation functions (expand_dims,squeeze,concat, …). Let me know if it's better to move this tondarray.py.moveaxisalso be added toutils.linalg_funcsso it works in lazy-expression strings? I left it out to keep this PR minimal.AI disclosure: After understanding the requirements, I used AI agents to plan and implement the changes. I reviewed every step and ran the test suite and the array-api conformance checks myself.