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

[backport] Fix regex in einsum to match empty input subscript #1186

Merged
merged 1 commit into from Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cupy/linalg/einsum.py
Expand Up @@ -266,7 +266,7 @@ def einsum(*operands):
raise ValueError('einstein sum subscripts string contains a \'.\' that'
'is not part of an ellipsis (\'...\')')

match = re.match('^([a-zA-Z@,]+)(->[a-zA-Z@]*)?$', subscripts)
match = re.match('^([a-zA-Z@,]*)(->[a-zA-Z@]*)?$', subscripts)
if not match:
raise ValueError('einstein sum subscript string does not contain '
'proper \'->\' output specified')
Expand Down
3 changes: 3 additions & 0 deletions tests/cupy_tests/linalg_tests/test_einsum.py
Expand Up @@ -150,6 +150,9 @@ def test_invalid_arrow4(self, xp):
{'shape_a': (2, 3), 'subscripts': 'ij->...ij'}, # do nothing
{'shape_a': (2, 3), 'subscripts': 'ij...->ij'}, # do nothing
{'shape_a': (2, 3), 'subscripts': 'i...j->ij'}, # do nothing

{'shape_a': (), 'subscripts': ''}, # do nothing
{'shape_a': (), 'subscripts': '->'}, # do nothing
)
class TestEinSumUnaryOperation(unittest.TestCase):
# Avoid overflow
Expand Down