Skip to content

[FR] multidim squeeze and flatten #30702

Open
@ssnl

Description

@ssnl

squeeze

Previous FR for multidim squeeze: #1951

A PR (#4692) that attempted to implement #1951 was closed because

The behavior of this feature is very non-trivial, e.g., when negative and positive indices are mixed. I'm not sure it solves more problems that it adds anymore.

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 dims 2 and 3, which they want to squeeze, it is far more intuitive to write

t.squeeze((2, 3))

than to write

t.squeeze(2).squeeze(2)

Negative indices does not add to complexity or confusion either.

flatten

Similarly, to merge the dims 1&2 and dims 3&4, it is far more intuitive to write

t.flatten([(1, 2), (3, 4)])

than

t.flatten(1,2).flatten(2,3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    function requestA request for a new function or the addition of new arguments/modes to an existing function.module: viewing and reshapingtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions