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

Adds example of inferring dimensions. #116

Closed
wants to merge 1 commit into from

Conversation

zimonitrome
Copy link

This feature is a nugget that might be obvious to some but is hidden in any documentation that I am able to find.

My edit might be on the nose of the readme but I otherwise suggest to include some other example to showcase inference of dimensions, e.g.:

image_sample = torch.rand([3, 256, 256])
image_batch = torch.rand([10, 3, 256, 256])

def make_grayscale(t):
    return reduce(t, "... c h w -> ... h w", "mean")

image_sample_gray = make_grayscale(image_sample)
image_batch_gray = make_grayscale(image_batch)

print(image_sample_gray.shape)
print(image_batch_gray.shape)

> [256, 256]
> [10, 256, 256]

@vmichals
Copy link

I assumed that this existed and should've guessed that the correct syntax is '...', but didn't! Luckily I saw your PR! Thanks!
I agree this is a very useful example for the documentation!

@charlesjhill
Copy link

^ I found one example of using ... as a catch-all in the docs, at https://einops.rocks/pytorch-examples.html:

if combine == 'add':
    # ShuffleUnit Figure 2b
    self.left = Rearrange('...->...') # identity
    depthwise_stride = 1

An example like in the PR or something more explicit out ala

data_bthwc = np.random.random([2, 10, 100, 110, 3])
data_btchw = rearrange(data_bthwc, "... h w c -> ... c h w")
data.shape  # (2, 10, 3, 100, 110)

would have saved me some time on a recent project.

@arogozhnikov arogozhnikov deleted the branch arogozhnikov:master September 15, 2024 14:23
@arogozhnikov
Copy link
Owner

all PRs were auto-closed because of switching master -> main, hopefully I'll have some time to update documentation, and include ellipsis with enough context to prevent lazy usage.

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

Successfully merging this pull request may close these issues.

4 participants