code: def diag(values, k=0, like=None):
      """Construct a diagonal tensor from a list of scalars.
  
      Args:
          values (tensor_like or Sequence[scalar]): sequence of numeric values that
              make up the diagonal
          k (int): The diagonal in question. ``k=0`` corresponds to the main diagonal.
              Use ``k>0`` for diagonals above the main diagonal, and ``k<0`` for
              diagonals below the main diagonal.
  
      Returns:
          tensor_like: the 2D diagonal tensor
  
      **Example**
  
      >>> x = [1., 2., tf.Variable(3.)]
      >>> qml.math.diag(x)
      <tf.Tensor: shape=(3, 3), dtype=float32, numpy=
      array([[1., 0., 0.],
             [0., 2., 0.],
             [0., 0., 3.]], dtype=float32)>
      >>> y = tf.Variable([0.65, 0.2, 0.1])
      >>> qml.math.diag(y, k=-1)
      <tf.Tensor: shape=(4, 4), dtype=float32, numpy=
      array([[0.  , 0.  , 0.  , 0.  ],
             [0.65, 0.  , 0.  , 0.  ],
             [0.  , 0.2 , 0.  , 0.  ],
             [0.  , 0.  , 0.1 , 0.  ]], dtype=float32)>
      >>> z = torch.tensor([0.1, 0.2])
      >>> qml.math.diag(z, k=1)
      tensor([[0.0000, 0.1000, 0.0000],
              [0.0000, 0.0000, 0.2000],
              [0.0000, 0.0000, 0.0000]])
      """
      if isinstance(values, (list, tuple)):
          values = np.stack(np.coerce(values, like=like), like=like)
  
      return np.diag(values, k=k, like=like)
  
imports: import functools
  from collections.abc import Sequence
  import autoray
  import numpy
  from autograd.numpy.numpy_boxes import ArrayBox
  from autoray import numpy
  from numpy import ndarray
  from .None import single_dispatch
  from .utils import cast, cast_like, get_interface, requires_grad
label_desc: Use image node_id 7 for calling a global function with example usage: diag(values, k, like) and returns: np