Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions tensorflow/python/ops/special_math_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,6 @@ def einsum(equation, *inputs, **kwargs):
output_axis_labels = ''.join(
sorted(ax for ax in indices if counts[ax] == 1))

for a in axis_labels:
for input_labels in input_axis_labels:
if input_labels.count(a) > 1:
raise ValueError(
'Subscript not supported: an axis appears more than once: %s' %
input_labels)

for a in axis_labels:
input_count = sum(1 for s in input_axis_labels if a in s)
Expand All @@ -267,7 +261,12 @@ def einsum(equation, *inputs, **kwargs):
i for i, a in enumerate(temp_axis_labels)
if a not in output_axis_labels
]
temp = math_ops.reduce_sum(temp, axis=axis)
for a in axis_labels:
for input_labels in input_axis_labels:
if input_labels.count(a) == 2:
temp = math_ops.trace(temp)
else:
temp = math_ops.reduce_sum(temp, axis=axis)
temp_axis_labels = ''.join(
a for a in temp_axis_labels if a in output_axis_labels)

Expand Down