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, but has not received an answer.
The assertion fails because python will turn (3) into simply 3. The shape is a tuple, which means you need the comma in there: assert a.shape == (3,) # works.