}
// fold the batch into the first dimension
- Tensor t1 = tensor1.expect_contiguous()->view({-1, size1[size1.size() - 1]});
+ // Why not tensor1.view(-1, size1[size1.size() -1])?
+ // If the last dim is 0, then view(-1, 0) won't work because the -1 becomes ambiguous.
+ // This can happen in e.g. [3, 5, 0] @ [0, 0].
+ // So we manually compute the folding as a result.
+ const auto dim1_size = c10::multiply_integers(size1.begin(), size1.end() - 1);
+ auto t1 = tensor1.expect_contiguous()->view({dim1_size, size1[size1.size() - 1]});
Tensor output = has_out ? at::_unsafe_view(at::mm_out(out, t1, t2), output_size)
: at::_unsafe_view(t1.mm(t2), output_size);
return has_out ? out.set_(output) : output;
((S, M), (M,)),
((M,), (M, S)),
((S, M), (M, S)),
+ ((S, 0), (0, M)),
((S, S, M), (M,)),
((S, S, M), (M, S)),
+ ((S, S, 0), (0, S)),
((M,), (S, M, S)),
((S, M), (S, M, S)),
+ ((0, 0), (S, 0, 0)),
((S, S, M, M), (S, S, M, S)),
((S, S, M, M), (M,)),
((M,), (S, S, M, S)))