-
Notifications
You must be signed in to change notification settings - Fork 132
Fix einsum
failing with repeated inputs
#1260
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
Fix einsum
failing with repeated inputs
#1260
Conversation
Hello maintainers, My pull request seems to fail 2 tests even though these aren't directly linked to any changes I have made. This is my first time contributing, I would appreciate any help |
It's unrelated and will be patched by a0d9ecf |
pytensor/tensor/einsum.py
Outdated
for i in range(len(elements)): | ||
for j in range(i + 1, len(elements)): | ||
if elements[i] == elements[j]: | ||
elements[j] = elements[j].copy() | ||
return elements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small optimization. Don't assume a list is passed and reduce list access. Also is
should be better than ==
.
for i in range(len(elements)): | |
for j in range(i + 1, len(elements)): | |
if elements[i] == elements[j]: | |
elements[j] = elements[j].copy() | |
return elements | |
elements = list(elements) | |
n_elem = len(elements) | |
for i, elem1 in enumerate(elements[:-1]): | |
for j, elem2 in enumerate(elements[i + 1:], start=i+1): | |
if elem1 is elem2: | |
elements[j] = elem1.copy() | |
return elements |
Can you add a regression test? |
Failing test should go away with a rebase from main |
Co-authored-by: Ricardo Vieira <[email protected]>
You seem to have pushed a |
@ricardoV94 I have deleted that file, thank you for noticing that |
Still needs a regression test |
Just to clarify, does this mean I need to add a test to the |
Yes, a test that would fail before this PR. Try to make it a simple as possible |
Co-authored-by: Ricardo Vieira <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1260 +/- ##
==========================================
- Coverage 81.99% 81.99% -0.01%
==========================================
Files 188 188
Lines 48553 48582 +29
Branches 8673 8688 +15
==========================================
+ Hits 39812 39833 +21
- Misses 6579 6585 +6
- Partials 2162 2164 +2
🚀 New features to boost your workflow:
|
Thanks @Abhinav-Khot |
einsum
failing with repeated inputs
Description
Fixed the issue where passing the same tensor multiple times as arguments to the einsum function would raise a ValueError. Implemented a function that internally converts duplicate objects into copies using
copy()
.Related Issue
Checklist
Type of change
📚 Documentation preview 📚: https://pytensor--1260.org.readthedocs.build/en/1260/