#369·einops

Match arbitrary number of dimensions `“a *b”`

Author: PierreGtchCreated Mar 7, 2025Updated Mar 7, 2025

Hi, thanks for this awesome library!

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

python
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:

python
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