import torch


def horners_method(coeffs,
                   x):
    """
    Horner's method of evaluating a polynomial with coefficients given by coeffs and
    input x.
    z = arr[0] + arr[1]x + arr[2]x^2 + ... + arr[n]x^n
    :param coeffs: List/Tensor of coefficients of polynomial (in standard form)
    :param x: Tensor of input values.
    :return z: Tensor of output values, same shape as x.
    """
    z = torch.empty(x.shape, dtype=x.dtype, device=x.device).fill_(coeffs[0])
    for i in range(1, len(coeffs)):
        z.mul_(x).add_(coeffs[i])
    return z