import torch


def tolist(x):
    """Convert x to a Python list. x can be a Torch size tensor, a list, tuple
    or scalar
    """
    if isinstance(x, torch.Size):
      return [z for z in x]
    elif isinstance(x, (list,tuple)):
      return [z for z in x]
    else:
      return [x]