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

Space handling in equation parameter of tf.einsum #19980

Merged
merged 2 commits into from
Jun 13, 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: 2 additions & 0 deletions tensorflow/python/ops/special_math_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def einsum(equation, *inputs, **kwargs):
indices in its subscript, or
- the input shapes are inconsistent along a particular axis.
"""
equation = equation.replace(" ", "")

name = kwargs.pop('name', None)
if kwargs:
raise TypeError('invalid keyword arguments for this function: ' + ', '.join(
Expand Down
10 changes: 9 additions & 1 deletion tensorflow/python/ops/special_math_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ class EinsumTest(test.TestCase):
'iJ,Jk->ik',
'iJ,Ki->JK',
'iJk,Jklm->Jk'
'ij, jk, kl -> il',
'a, ab, abc -> abc',
'ab, ab, cd, cd, ef, ef -> ',
'abc, bac',
'iJ, Ki -> JK',
'iJk, Jklm -> Jk'
]

long_cases = [
Expand All @@ -231,6 +237,8 @@ class EinsumTest(test.TestCase):
'ea,fb,gc,hd,abcd->efgh',
'ea,fb,abcd,gc,hd->efgh',
'abhe,hidj,jgba,hiab,gab',
'efc, dbc, acf, fd -> abe',
'abhe, hidj, jgba, hiab, gab',
]

invalid_cases = [
Expand Down Expand Up @@ -301,7 +309,7 @@ def run_test(self, axes):
input_axes, _, _ = axes.partition('->')

for idx in input_axes.split(','):
shape = [all_axes[ax] for ax in idx]
shape = [all_axes[ax] for ax in idx if ax.isalpha()]
input_vals.append(np.random.random(shape))

input_tensors = [constant_op.constant(val) for val in input_vals]
Expand Down