Skip to content
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

Alias ellipsis to a star for rearrange #314

Open
knyazer opened this issue Apr 9, 2024 · 3 comments
Open

Alias ellipsis to a star for rearrange #314

knyazer opened this issue Apr 9, 2024 · 3 comments

Comments

@knyazer
Copy link

knyazer commented Apr 9, 2024

Hey, guys, the library is great!

But, there is a small non-intuitive thing that I consistently stumble upon (I mean, twice is consistent, right?). It is that for rearrange one have to use the ellipsis instead of a star to select the rest of dimensions. It seems a bit nicer to have an alias of ellipsis to a star, e.g.

rearrange('batch_dim_1 batch_dim_2 ... -> batch_dim_2 batch_dim_1 ...')
# proposal: rearrange('batch_dim_1 batch_dim_2 * -> batch_dim_2 batch_dim_1 *')

Probably I find the star notation more sensible, since I use jaxtyping a lot, and it uses the star notation for this. If you have a good argument for why the star should not be equivalent to the ellipsis, I am happy to just alias this in jaxtyping, so that the dimension selection convention is the same between the two: I guess many people use both of the libraries at the same time (at least I do :) )

P.S. I am new-ish with einops, so I might not know that this problem was already discussed a million times. In this case, just point me to the relevant discussion 😄

@arogozhnikov
Copy link
Owner

arogozhnikov commented Apr 10, 2024

Hi @knyazer

this problem was already discussed a million times

you'll be surprised, but it is the first time it is discussed in repo :)

First, how did we end up in where we are (that's how I reconstruct history) in chronological order

  • f(*x) for passing multiple args
  • ellipsis (...) used in numpy indexing x[..., 0]
  • numpy.einsum decided to use ... for a group of unnamed axes
  • python3 introduces star into unpacking multiple arguments [a, *b] = f(x)
  • einops follows einsum with using ellipsis in rearrange
  • einops uses * in unpack to designate special position for one-or-many axes
  • jaxtyping uses * to designate named or unnamed group of axes

so multiple axes historically was always ellipsis, but introduction of star-unpacking makes it tempting to use star and align with less array-specific part of python.

Two considerations:

cc: @patrick-kidger

@knyazer

This comment has been minimized.

@patrick-kidger
Copy link

patrick-kidger commented Apr 10, 2024

Hey folks!

So I think we have one baked-in inconsistency already. In einops, ... is (IIUC) a "named" group of dimensions: it must be the same on both sides. In jaxtyping, it is an anything-goes, and in particular can represent different groups of axes across its different usages. So if consistency was a goal then I think we'd both have to recommend avoiding ... entirely.

We'd then find some way of both libraries using * in compatible ways? FWIW a plain * on its own is not currently valid notation in jaxtyping, so we have an opportunity there. I'm not sure how important consistency really is between each other, but I'd be happy to tweak things if it's possible!

Frankly this inconsistency is my mistake. when I came up with the notation for jaxtyping, I completely forgot to check what notation einops was already using... 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants