I have a tensor X with size (N, R) and a tensor Y with size (M, T).
I need to combine these tensors such that I get a new tensor of size (N x M, R+T) where I have concatenated dim=1 and combined dim = 0.
So for example
X = tensor([ [1,2,3], [4,5,6] ]) Y = tensor([ [7, 8], [9, 10] ] ) # where result would be # tensor([ [1,2,3,7, 8], [1,2,3,9,10], [4,5,6,7,8], [4,5,6,9,10] ]) # also this is a special case where N == M. But I need to be able to do this with arbitrarily N and M.
I can do this with a loop but I am looking for an efficient operation to do this.
Also, X and Y are results from a neural network (nn.Module). I don’t want to break the computation graph because I need to compute the loss with result. Would creating a new tensor, looping through X and Y and simply appending the concatenations break the computation graph?