def batch_2x2_ellipse(m: Tensor) -> Tuple[Tensor, Tensor]:
    """Returns Eigenvalues and Eigenvectors of batch of 2x2 matrices."""
    am = m[..., 0, 0]
    bm = m[..., 0, 1]
    cm = m[..., 1, 0]
    dm = m[..., 1, 1]

    a = am**2 + bm**2
    b = am * cm + bm * dm
    d = cm**2 + dm**2

    trh = (a + d) / 2
    # det = a * d - b * c
    sqrtdisc = torch.sqrt(((a - d) / 2) ** 2 + b**2)

    eigenvals = torch.stack([trh + sqrtdisc, trh - sqrtdisc], dim=-1).clamp(min=0)
    dens = eigenvals - a.unsqueeze(-1)
    dens[torch.abs(dens) < 1e-6] = 1e-6
    eigenvecs = torch.stack([b.unsqueeze(-1) / dens, torch.ones_like(dens)], dim=-2)
    eigenvecs = eigenvecs / torch.norm(eigenvecs, dim=-2, keepdim=True)

    # err = eigenvecs @ torch.diag_embed(eigenvals) @ eigenvecs.transpose(-2, -1) - q
    return eigenvals, eigenvecs
Returns Eigenvalues and Eigenvectors of batch of 2x2 matrices.
kornia/feature/adalam/utils.py