code: def polyval(coef, x) -> torch.Tensor:
      """
      Evaluates the polynomial defined by `coef` at `x`.
  
      For a 1D sequence of coef (length n), evaluate::
  
          y = coef[n-1] + x * (coef[n-2] + ... + x * (coef[1] + x * coef[0]))
  
      Args:
          coef: a sequence of floats representing the coefficients of the polynomial
          x: float or a sequence of floats representing the variable of the polynomial
  
      Returns:
          1D torch tensor
      """
      device = x.device if isinstance(x, torch.Tensor) else None
      coef = torch.as_tensor(coef, dtype=torch.float, device=device)
      if coef.ndim == 0 or (len(coef) < 1):
          return torch.zeros(x.shape)
      x = torch.as_tensor(x, dtype=torch.float, device=device)
      ans = coef[0]
      for c in coef[1:]:
          ans = ans * x + c
      return ans
  
file_path: MONAI/monai/networks/layers/convutils.py
imports: from __future__ import annotations
  from collections.abc import Sequence
  import numpy
  import torch
label_desc: Use image node_id 5 for calling a global function with example usage: polyval(coef, x) and returns: ans, torch