def _inverse_effective_gram(ops, gram_L, B_L):
    """Inverse of the effective Gram matrix."""
    # gram_L: [OUT_DIM, N, N]
    # B_L: [OUT_DIM, N, N]
    eye = ops.eye(ops.shape(gram_L)[-1], dtype=gram_L.dtype)
    InvL = ops.matrix_triangular_solve(gram_L, eye)
    # InvG: [OUT_DIM, N, N]
    InvG = ops.matrix_triangular_solve(gram_L, InvL, adjoint=True)
    if B_L is not None:
        InvB_InvL = ops.cholesky_solve(B_L, InvL)
        InvL_InvB_InvL = ops.matrix_triangular_solve(gram_L, InvB_InvL, adjoint=True)
        InvG = InvG - InvL_InvB_InvL
    return InvG