import torch


def absolute(t, dim=0):
    """Complex absolute value, complex dimension is dim.

    Args:
        t (tensor): A tensor where dimension dim is the complex dimension.
        dim (int, default=0): An integer indicating the complex dimension.

    Returns:
        tensor: The absolute value of t.
    """
    assert t.shape[dim] == 2

    abst = torch.sqrt(
        t.select(dim, 0) ** 2 +
        t.select(dim, 1) ** 2
    ).unsqueeze(dim)

    return abst