Skip to content
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

ENH: add split, swapaxes #97

Open
ev-br opened this issue Jan 16, 2025 · 5 comments
Open

ENH: add split, swapaxes #97

ev-br opened this issue Jan 16, 2025 · 5 comments
Labels
enhancement New feature or request new function

Comments

@ev-br
Copy link
Contributor

ev-br commented Jan 16, 2025

A discussion and a crude implementation of part of np.split and np.swapaxes is at scipy/scipy#22122 (comment)

@lucascolley lucascolley changed the title Add (a part of numpy.split) ENH: add split, swapaxes Jan 16, 2025
@lucascolley lucascolley added enhancement New feature or request new function labels Jan 16, 2025
@kgryte
Copy link

kgryte commented Jan 18, 2025

@ev-br
Copy link
Contributor Author

ev-br commented Jan 18, 2025

@kgryte yes. swapaxes may be implemented either with moveaxis or via permute_dims as in https://github.com/scipy/scipy/pull/22122/files#r1916726566. Or may stay a private utility in scipy/signal/_signaltools.

@kgryte
Copy link

kgryte commented Jan 18, 2025

I suppose my question is why is swapaxes necessary when there is moveaxis?

@ev-br
Copy link
Contributor Author

ev-br commented Jan 18, 2025

It's pure convenience indeed, not a necessity. Esp when converting legacy code which predates moveaxis in numpy. A single call to swapaxes vs two calls to moveaxis, and since swapaxis semantics is confusing, so is replicating it with moveaxis. New code is indeed way better off using moveaxis.

@lucascolley
Copy link
Member

two calls to moveaxis

FWIW it is just one call, swapaxes(x, y, z) == moveaxis(x, (y, z), (z, y)). I'm indifferent to adding that alias to array-api-extra, or just using xp.moveaxis directly in SciPy, but both are better than leaving a private helper in the codebase for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new function
Projects
None yet
Development

No branches or pull requests

3 participants