


x=torch.empty(5,3,4,1)
y=torch.empty(  3,1,1)
   # x and y are broadcastable.
   # 1st trailing dimension: both have size 1
   # 2nd trailing dimension: y has size 1
   # 3rd trailing dimension: x size == y size
   # 4th trailing dimension: y dimension doesn't exist



# but:



x=torch.empty(5,2,4,1)
y=torch.empty(  3,1,1)
   # x and y are not broadcastable, because in the 3rd trailing dimension 2 != 3



If two tensors "x", "y" are "broadcastable", the resulting tensor size
is calculated as follows:


If the number of dimensions of "x" and "y" are not equal, prepend 1
  to the dimensions of the tensor with fewer dimensions to make them
  equal length.


Then, for each dimension size, the resulting dimension size is the
  max of the sizes of "x" and "y" along that dimension.


For Example:
# can line up trailing dimensions to make reading easier



x=torch.empty(5,1,4,1)
y=torch.empty(  3,1,1)
(x+y).size()
   torch.Size([5, 3, 4, 1])



# but not necessary: