arogozhnikov / arogozhnikov/einops

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

Open
#369 0 comments 5 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
9.6k
Forks
401
Avg merge
33m
Merged PRs (30d)
3

Description

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the parse_shape API and its existing `...` pattern behavior. Determine whether the current API can expose dimensions matched by `...`; if not, assess the proposed `*b` syntax and define tests covering the zero-, one-, and two-dimension examples as the completion criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.