Suppose I have two feature maps F1 of shape [K, C, H, W] and F2 of shape [M, C, H, W].
Furthermore, let’s suppose F1 is a collection of K feature maps, each of dimension [C, H, W] and F2 is a collection of M feature maps, each of dimension [C, H, W].
Here is the task: For each feature map 1 <= i <= K of F1, I want to concatenate i with every feature map 1 <= j <= M of F2 to obtain MK feature maps of dimensions [2C, H, W].
In other words, I need to obtain [M, K, 2C, H, W].
What are some efficient ways to do this?
One way I can think of is the following:
F1 = F1.unsquueze(0).repeat(M, 1, 1, 1, 1)      ([M, K, C, H, W])
F2 = F2.unsqueeze(1).repeat(1, K, 1, 1, 1)      (M, K ,C, H, W])
Fcat = torch.cat([F1, F2], dim=2)  ([M, K, 2C, H, W])
Is this a correct  and an efficient way to do this?