Skip to content
Closed
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
18 changes: 13 additions & 5 deletions aten/src/ATen/native/Linear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ static Tensor sumproduct_pair(const Tensor& left_, const Tensor& right_, IntArra

// finally squeeze summed dimensions if desired
if (! keepdim) {
for (int i = dim-1; i>=0; i--)
if (sum_dims[i])
result.squeeze_(i);
auto sizes = result.sizes().vec();
for (int i = dim-1; i>=0; i--) {
if (sum_dims[i]) {
sizes.erase(sizes.begin() + i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you please add braces here? Braceless nested statements make me nervous 😬

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me, too, even if I'm the one to blame for them in the first place.

}
}
result = result.view(sizes);
}
return result;
}
Expand Down Expand Up @@ -354,8 +358,12 @@ Tensor einsum(std::string eqn, TensorList tensors) {
result = at::native::sumproduct_pair(result, preprocessed_operands[i], sum_dims, true);
}
// finally, we squeeze out all non-result dimensions
for (int64_t dim = num_total_idxes-1; dim >= num_output_dims; dim--)
result.squeeze_(dim);
auto sizes = result.sizes().vec();
for (int64_t dim = num_total_idxes-1; dim >= num_output_dims; dim--) {
sizes.erase(sizes.begin() + dim);
}

result = result.view(sizes);
return result;
}

Expand Down