-
Notifications
You must be signed in to change notification settings - Fork 24.2k
[FR] multidim squeeze and flatten #30702
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
I agree that it makes sense for squeeze and flatten to have these APIs. I would be happy to review PRs that enable this. |
another instance of real-world
|
I recently had a practical usecase for unsqueeze_multiple, had to implement it like this: |
Oh, so for unsqueeze_multiple, it is just inserting multiple dims at the same location, right? @vadimkantorov |
Yup! Maybe this version better called unsqueeze_repeated. It was useful for forcing a tensor to have a given number of dimensions e.g. 4d |
A recent related example: #94750 The code in that example is impl of mutlidim squeeze: x.squeeze(dim = (d1, d2, ...)) |
squeeze
Previous FR for multidim squeeze: #1951
A PR (#4692) that attempted to implement #1951 was closed because
I would argue against that point, particularly for
squeeze
.For
squeeze
, multidim is perfectly intuitive and defined, i.e., just squeezing the current dimensions the tuple refers. In fact, using a chain of squeeze (as suggested by the comment of #4692) is rather unintuitive.If one has a tensor that has size
1
at dims2
and3
, which they want to squeeze, it is far more intuitive to writethan to write
Negative indices does not add to complexity or confusion either.
flatten
Similarly, to merge the dims
1&2
and dims3&4
, it is far more intuitive to writethan
The text was updated successfully, but these errors were encountered: