def bproj(M, P):
    """Project batched marices using P^T M P

    Args:
        M (torch.tensor): batched matrices size (..., N, M)
        P (torch.tensor): Porjectors size (..., N, M)

    Returns:
        torch.tensor: Projected matrices
    """
    return P.transpose(1, 2) @ M @ P