Skip to content

Match arbitrary number of dimensions “a *b” #369

@PierreGtch

Description

@PierreGtch

Hi, thanks for this awesome library!

At the moment, it is possible to use ... to match an arbitrary number of dimensions

einops.parse_shape(torch.zeros(1,2,3,4), "a ... c”)  # {'a': 2, 'c': 4}

However, we can’t know what was matched by the ...

Suggestion: we could introduce a *b character that would return a list of dimensions.
This way, the pattern "a *b c” would give the following results:

einops.parse_shape(torch.zeros(1,2),     "a *b c")  # {'a': 2, ‘b’: [],    'c': 2}
einops.parse_shape(torch.zeros(1,2,3),   "a *b c")  # {'a': 2, ‘b’: [2],   'c': 3}
einops.parse_shape(torch.zeros(1,2,3,4), "a *b c")  # {'a': 2, ‘b’: [2,3], 'c': 4}

Is it already possible to achieve this with the current API?

CC @bruAristimunha

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions