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

squeeze accepts axis=None? #62

Open
mdhaber opened this issue Sep 20, 2024 · 1 comment
Open

squeeze accepts axis=None? #62

mdhaber opened this issue Sep 20, 2024 · 1 comment
Labels
blocked by upstream A feature that requires better upstream support Medium Priority

Comments

@mdhaber
Copy link

mdhaber commented Sep 20, 2024

It looks like axis=None is not in the standard for squeeze, yet it is accepted by array_api_strict.

import array_api_strict as xp
x = xp.reshape(xp.arange(12), (3, 4))[..., xp.newaxis]
xp.squeeze(x, axis=None)
# Array([[ 0,  1,  2,  3],
#        [ 4,  5,  6,  7],
#        [ 8,  9, 10, 11]], dtype=array_api_strict.int64)
@ev-br
Copy link
Contributor

ev-br commented Feb 4, 2025

I suspect it's an omission in the standard. ISTM all array libraries allow axis=None with the meaning of "remove all singleton dimensions":

In [17]: t = torch.empty((1, 2, 1, 3, 4, 1))

In [18]: torch.squeeze(t).shape
Out[18]: torch.Size([2, 3, 4])

torch does not allow squeeze(t, dim=None) which is fairly typical for torch's implementations of optional arguments, so will need to be worked around in the array-api-compat layer.

cross-ref data-apis/array-api#892

@ev-br ev-br added the blocked by upstream A feature that requires better upstream support label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked by upstream A feature that requires better upstream support Medium Priority
Projects
None yet
Development

No branches or pull requests

3 participants