def tcr_loss(z: Tensor, eps: float) -> Tensor:
    """Computes the Total Coding Rate (TCR) loss.

    Args:
        z:
            Patch embeddings.
        eps:
            Epsilon value for numerical stability.

    Returns:
        TCR loss.
    """
    _, batch_size, dim = z.shape
    diag = torch.eye(dim, device=z.device).unsqueeze(0)
    # Matrix multiplication over the batch dimension
    einsum = torch.einsum("vbd,vbe->vde", z, z)

    # Calculate the log determinant
    logdet = torch.logdet(diag + dim / (batch_size * eps) * einsum)

    return 0.5 * logdet.mean()
Computes the Total Coding Rate (TCR) loss.

    Args:
        z:
            Patch embeddings.
        eps:
            Epsilon value for numerical stability.

    Returns:
        TCR loss.
    
lightly/loss/emp_ssl_loss.py