import torch


def to_torch(tensor):
    """Converts an array-like object (either numpy or pytorch) into a pytorch tensor."""


    if tensor is None:
        return None

    elif isinstance(tensor, torch.Tensor):
        return tensor

    torch_tensor = torch.from_numpy(tensor)

    if torch_tensor.dtype == torch.float64:
        torch_tensor = torch_tensor.type(torch.float32)

    return torch_tensor