code: def diag(
      diagonal,
      /,
      k=0,
      *,
      num_rows=None,
      num_cols=None,
      padding_value=0,
      align="RIGHT_LEFT",
      name="diag",
  ):
      # TODO: Implement ivy.matrix_diag in ivy API
      diagonal = ivy.array(diagonal)
      shape = list(diagonal.shape)
      shape[-1] += abs(k)
  
      output = ivy.full(shape + [shape[-1]], padding_value)
      if k > 0:
          for i in range(shape[-1]):
              try:
                  output[..., i, i + k] = diagonal[..., i]
              except IndexError:
                  break
  
      else:
          for i in range(shape[-1]):
              try:
                  output[..., i + abs(k), i] = diagonal[..., i]
              except IndexError:
                  break
  
      size = 1
      for dim in output.shape:
          size *= dim
      if (num_cols and num_rows) and (size == (num_cols * num_rows)):
          output = ivy.reshape(output, (num_rows, num_cols))
      return ivy.astype(output, ivy.dtype(diagonal))
  
imports: import ivy
  from ivy.functional.frontends.tensorflow import check_tensorflow_casting
  from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
  from ivy.functional.frontends.tensorflow.func_wrapper import to_ivy_arrays_and_back, handle_tf_dtype
  import ivy.functional.frontends.tensorflow
label_desc: Use image node_id 7 for calling a global function with example usage: diag(k) and returns: ivy