def nplr(measure, n, rank=1, dtype=torch.float):
    """
    Return w, p, q, v, b such that
    (w - p q^*, b) is unitarily equivalent to the original HiPPO a, b by the matrix v
    i.e. a = v[w - p q^*]v^*, b = v b
    Args:
        measure (str): the type of measure
            legt - Legendre (translated)
            legs - Legendre (scaled)
            glagt - generalized Laguerre (translated)
            lagt, tlagt - previous versions of (tilted) Laguerre with slightly different normalization
        n (int): dimension
        rank (int): rank
        dtype (str): data type
    """
    a, b = transition(measure, n)
    a = torch.as_tensor(a, dtype=dtype)  # (n, n)
    b = torch.as_tensor(b, dtype=dtype)[:, 0]  # (n,)

    p = rank_correction(measure, n, rank=rank, dtype=dtype)
    ap = a + torch.sum(p.unsqueeze(-2)*p.unsqueeze(-1), dim=-3)
    w, v = torch.linalg.eig(ap)  # (..., n) (..., n, n)
    # v w v^{-1} = A

    # Only keep one of the conjugate pairs
    w = w[..., 0::2].contiguous()
    v = v[..., 0::2].contiguous()

    v_inv = v.conj().transpose(-1, -2)

    b = contract('ij, j -> i', v_inv, b.to(v))  # v^* b
    p = contract('ij, ...j -> ...i', v_inv, p.to(v))  # v^* p

    return w, p, p, b, v
Return w, p, q, v, b such that
(w - p q^*, b) is unitarily equivalent to the original HiPPO a, b by the matrix v
i.e. a = v[w - p q^*]v^*, b = v b
Args:
measure (str): the type of measure
legt - Legendre (translated)
legs - Legendre (scaled)
glagt - generalized Laguerre (translated)
lagt, tlagt - previous versions of (tilted) Laguerre with slightly different normalization
n (int): dimension
rank (int): rank
dtype (str): data type
towhee/models/vis4mer/utils.py