import torch


def ensure_tensor(v) -> torch.Tensor:
    """convert the input to `torch.Tensor` if necessary."""
    if isinstance(v, torch.Tensor):
        return v
    else:
        return torch.tensor(v)