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

Create generic einops.einop operation to do any of rearrange/reduce/repeat #91

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

MilesCranmer
Copy link
Contributor

As mentioned in #84, the einop operation can be inferred based on pattern alone. This PR adds a function to do this: einops.einop. For example:

Reduction:

import numpy as np
from einops import einop

x = np.random.randn(100, 5, 3)

einop(x, 'i j k -> i j', reduction='sum').shape
>>> (100, 5)

Rearrange:

einop(x, 'i j k -> k i j').shape
>>> (3, 100, 5)

Repeat:

einop(x, 'i j k -> i j k l', l=10).shape
(100, 5, 3, 10)

There are also assertions to catch bugs as mentioned in #84. I also added some tests for these operations: test12 through test14.

Interested to hear what you think.
Cheers!
Miles

einops/einops.py Outdated Show resolved Hide resolved
@genghisun
Copy link

Such a great feature! 👍 Any update on this?

@MilesCranmer
Copy link
Contributor Author

^See #84 for discussion. Currently, the maintainer is against adding this

@cgarciae
Copy link
Contributor

cgarciae commented Mar 7, 2022

I've been waiting for this PR to land for a while, in the meantime I've extracted this functionality into the einop package.

@FrancescoSaverioZuppichini

guys?

@MilesCranmer
Copy link
Contributor Author

I wish we could, but nothing we can do unfortunately. If you have a compelling argument to convince the maintainer, you can add it to #84. In the meantime you can use @cgarciae’s package

@UFO-101
Copy link

UFO-101 commented Jan 8, 2024

@MilesCranmer Thoughts on doing a similar thing to einsum? #84 (comment)

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.

None yet

5 participants