but not necessary:



x=torch.empty(1)
y=torch.empty(3,1,7)
(x+y).size()
   torch.Size([3, 1, 7])
x=torch.empty(5,2,4,1)
y=torch.empty(3,1,1)
(x+y).size()
   RuntimeError: The size of tensor a (2) must match the size of tensor b (3) at non-singleton dimension 1



In-place semantics
One complication is that in-place operations do not allow the in-place
tensor to change shape as a result of the broadcast.
For Example:



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



# but:



x=torch.empty(1,3,1)
y=torch.empty(3,1,7)
(x.add_(y)).size()
   RuntimeError: The expanded size of the tensor (1) must match the existing size (7) at non-singleton dimension 2.



Backwards compatibility
Prior versions of PyTorch allowed certain pointwise functions to
execute on tensors with different shapes, as long as the number of