Given tensors x
and y
, each with shape (num_batches, d)
, how can I use PyTorch to compute the sum of every combination of x
and y
within a batch?
This is similar to outer product, except we don't want to multiply, but sum. (This implies that I could solve this by exponentiating, outer product, and taking the log, but of course that has numerical and performance disadvantages).
It could be done via cartesian product and then summing each of the combinations.
Essentially, I'd like osum[b, i, j] == x[b, i] + y[b, j]
. Can PyTorch do this in tensors, without loops?