code: def diagflat(
      x: Union[ivy.Array, ivy.NativeArray],
      /,
      *,
      offset: int = 0,
      padding_value: float = 0,
      align: str = "RIGHT_LEFT",
      num_rows: int = -1,
      num_cols: int = -1,
      out: Optional[Union[ivy.Array, ivy.NativeArray]] = None,
  ) -> ivy.Array:
      """Return a two-dimensional array with the flattened input as a diagonal.
  
      Parameters
      ----------
      x
          Input data, which is flattened and set as the k-th diagonal of the output.
      k
          Diagonal to set.
          Positive value means superdiagonal,
          0 refers to the main diagonal,
          and negative value means subdiagonal.
      out
          optional output array, for writing the result to. It must have a shape that the
          inputs broadcast to.
  
      Returns
      -------
      ret
          The 2-D output array.
  
      Examples
      --------
      With :class:`ivy.Array` inputs:
  
      >>> x = ivy.array([[1,2], [3,4]])
      >>> ivy.diagflat(x)
      ivy.array([[1, 0, 0, 0],
                 [0, 2, 0, 0],
                 [0, 0, 3, 0],
                 [0, 0, 0, 4]])
  
      >>> x = ivy.array([1,2])
      >>> ivy.diagflat(x, k=1)
      ivy.array([[0, 1, 0],
                 [0, 0, 2],
                 [0, 0, 0]])
      """
      return current_backend(x).diagflat(
          x,
          offset=offset,
          padding_value=padding_value,
          align=align,
          num_rows=num_rows,
          num_cols=num_cols,
          out=out,
      )
  
imports: import logging
  from typing import Union, Optional, Tuple, List, Sequence, Literal
  import ivy
  from ivy.utils.backend import current_backend
  from ivy.func_wrapper import to_native_arrays_and_back, handle_out_argument, handle_nestable, handle_array_like_without_promotion, handle_array_function, handle_device, inputs_to_ivy_arrays, handle_backend_invalid
  from ivy.utils.exceptions import handle_exceptions
label_desc: Use image node_id 3 for calling a global function with example usage: diagflat() and returns: current_backend