code: def diagflat(
      x: paddle.Tensor,
      /,
      *,
      offset: Optional[int] = 0,
      padding_value: Optional[float] = 0,
      align: Optional[str] = "RIGHT_LEFT",
      num_rows: Optional[int] = None,
      num_cols: Optional[int] = None,
      out: Optional[paddle.Tensor] = None,
  ):
      diag = paddle.diag(
          x.flatten(), padding_value=padding_value, offset=offset
      )
      num_rows = num_rows if num_rows is not None else diag.shape[0]
      num_cols = num_cols if num_cols is not None else diag.shape[1]
  
      if num_rows < diag.shape[0]:
          diag = diag[:num_rows, :]
      if num_cols < diag.shape[1]:
          diag = diag[:, :num_cols]
  
      if diag.shape == [num_rows, num_cols]:
          return diag
      else:
          return paddle.nn.Pad2D(
              padding=(
                  0,
                  num_rows - diag.shape[0],
                  0,
                  num_cols - diag.shape[1],
              ),
              mode="constant",
              value=padding_value,
          )(diag)
  
file_path: ivy/ivy/functional/backends/paddle/experimental/linear_algebra.py
imports: import paddle
  from typing import Optional, Tuple, Union, Any
  from ivy.functional.ivy.experimental.linear_algebra import _check_valid_dimension_size
  from ivy.func_wrapper import with_unsupported_device_and_dtypes, with_supported_device_and_dtypes
  from ivy.utils.exceptions import IvyNotImplementedException
  from ..None import backend_version
label_desc: Use image node_id 1 for calling a global function with example usage: diagflat() and returns: diag, paddle