What is the canonical way to assert that a given tensor has the correct shape, i.e. if it is known beforehand what shape it should have? Currently, I use assertions in the following way, which adds a lot of clutter to the code:
assert x.shape == torch.Size([dim1, dim2])

A similar question about IDE based tensor-shape checking has been asked here 34, but has not received an answer.