Hi,
Yes, you can use view() safely here, or reshape.


See this for the differences between view and reshape

View is quick to perform but will fails on non-contiguous tensors.
Reshape always works. When possible, the returned tensor will be a view of input. Otherwise, it will be a copy.
But I don’t think it’s possible for 1D tensor to be non-contiguous, so you should not have to care about that here.


The broadcasting is performed starting from last dimension, therefor you need B to get the shape (C, 1, 1) before the multiplication.
So basically, torch.einsum("ijkl,j->ijkl", A, B) should be equivalent to A*(B.view(-1, 1, 1)) and equivalent to A*(B.unsqueeze(-1).unsqueeze(-1)).
I would tend to use A*(B.view(-1, 1, 1)) here which is short, clear, and efficient.