import torch


def optimal_symmetric_circulant_precond_column(
    col_toeplitz: torch.Tensor,
) -> torch.Tensor:
    """
    compute the first column of the circulant matrix closest to
    the Toeplitz matrix with provided first column in terms of the
    Froebenius norm
    """
    n = col_toeplitz.shape[-1]
    b = torch.arange(1, n, device=col_toeplitz.device) / float(n)
    w = col_toeplitz[..., 1:] * b.flip(dims=(-1,))
    col_circ = torch.cat((col_toeplitz[..., :1], w + w.flip(dims=(-1,))), dim=-1)
    return col_circ