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

[FR] Optional channels #49

Closed
ehknight opened this issue Jun 8, 2020 · 5 comments
Closed

[FR] Optional channels #49

ehknight opened this issue Jun 8, 2020 · 5 comments

Comments

@ehknight
Copy link

ehknight commented Jun 8, 2020

Sometimes, I find myself working lists of tensors in which one tensor has a shape (b, c) (for c classes) and another tensor has shape (b,) (for a single class). My current approach is to pad the tensors that have only one class with an additional channel dimension, use rearrange on the list, and then squeeze the dimensions that need to be squeezed.

A great alternative to this would be supporting optional channels. Perhaps you could notate them with a question mark: rearrange(x, "b c? -> (b c?)").

@arogozhnikov
Copy link
Owner

@ehknight thanks for coming up with suggestion.

I've been previously considering this feature, however it is quite difficult to generalize beyond a single optional dimension.
The way your example should be implemented in existing einops syntax is:

rearrange(x, "b ... -> (b ...)")

where ellipsis can be 0 or 1 dimensions (or more). However, right now that's not yet supported and is subject of #43

@arogozhnikov arogozhnikov added this to the 0.3 milestone Aug 23, 2020
@arogozhnikov
Copy link
Owner

@ehknight that's implemented now and will become a part of the next release

@shoyer
Copy link

shoyer commented Aug 24, 2020

It looks like transformations like "b ... -> (b ...)" work currently, but not "(b ...) -> b ..."?

@arogozhnikov
Copy link
Owner

arogozhnikov commented Aug 24, 2020

@shoyer that's right, those expressions are disallowed.

Let's analyze your example:

(b ...) 

left part implies there is one dimension which should be decomposed in b and undefined number of dimensions.
To make this a valid operation one needs to provide number of dimensions in ... and their sizes.
In this scenario user can write ... as separate axes like (b b1 b2) -> b b1 b2.

@arogozhnikov
Copy link
Owner

Ellipsis collapsing is now available as a part of einops 0.3 release.

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