I have the following problem: given two tensors X of shape (T,n,d) and Y of shape (R,m,d), I want to compute the tensor D of shape (T,R,n,m,d) such that, for all 0 <= t < T, 1 <= r < R, 1 <= i < n, 1 <= j < m,
D[t,r,i,j] = X[t,i] - Y[r,j]
Can we compute D with Pytorch without using any loop?
I know that when given two tensors X of shape (n,d) and Y of shape (m,d) we can compute the tensor D of shape (n,m,d) such that, for all 1 <= i < n, 1 <= j < m, D[i,j] = X[i] - Y[j] using
x.unsqueeze(1) - y
What I am looking for is a similar trick for the initial problem.