code: def dct(
      x: torch.Tensor,
      /,
      *,
      type: Literal[1, 2, 3, 4] = 2,
      n: Optional[int] = None,
      axis: int = -1,
      norm: Optional[Literal["ortho"]] = None,
      out: Optional[torch.Tensor] = None,
  ) -> torch.tensor:
      if norm not in (None, "ortho"):
          raise ValueError("Norm must be either None or 'ortho'")
      if axis < 0:
          axis = axis + len(x.shape)
      if n is not None:
          signal_len = x.shape[axis]
          if n <= signal_len:
              local_idx = [slice(None)] * len(x.shape)
              local_idx[axis] = slice(None, n)
              x = x[local_idx]
          else:
              pad_idx = [0] * 2 * len(x.shape)
              pad_idx[(len(pad_idx) - 1) - (2 * axis)] = n - signal_len
              x = torch.nn.functional.pad(x, pad_idx)
      real_zero = torch.tensor(0.0, dtype=x.dtype)
      axis_dim = x.shape[axis]
      axis_dim_float = torch.tensor(axis_dim, dtype=x.dtype)
  
      if type == 1:
          if norm:
              raise ValueError(
                  "Normalization not supported for type-I DCT"
              )
          axis_idx = [slice(None)] * len(x.shape)
          axis_idx[axis] = slice(1, -1)
          x = torch.concat([x, x.flip(axis)[axis_idx]], dim=axis)
          dct_out = torch.real(torch.fft.rfft(x, dim=axis))
          return dct_out
  
      elif type == 2:
          scale_dims = [1] * len(x.shape)
          scale_dims[axis] = axis_dim
          complex_part = (
              torch.arange(axis_dim_float)
              * math.pi
              * 0.5
              / axis_dim_float
          )
          scale = 2.0 * torch.exp(
              torch.complex(
                  real_zero,
                  -complex_part.type(real_zero.type()),
              )
          ).view(scale_dims)
  
          axis_idx = [slice(None)] * len(x.shape)
          axis_idx[axis] = slice(None, axis_dim)
          dct_out = torch.real(
              torch.fft.rfft(x, n=2 * axis_dim, axis=axis)[axis_idx]
              * scale
          )
          if norm == "ortho":
              n1 = 0.5 * torch.rsqrt(axis_dim_float)
              n2 = n1 * math.sqrt(2.0)
              sf = torch.nn.functional.pad(
                  n1.unsqueeze(0), (0, axis_dim - 1), value=n2
              )
              dct_out = sf.view(scale_dims) * dct_out
          return dct_out
  
      elif type == 3:
          scale_dims = [1] * len(x.shape)
          scale_dims[axis] = axis_dim
          complex_part = (
              torch.arange(axis_dim_float)
              * math.pi
              * 0.5
              / axis_dim_float
          )
          scale = 2.0 * torch.exp(
              torch.complex(
                  real_zero, complex_part.type(real_zero.type())
              )
          ).view(scale_dims)
          if norm == "ortho":
              n1 = torch.sqrt(axis_dim_float)
              n2 = n1 * math.sqrt(0.5)
              scale_dims = [1] * len(x.shape)
              scale_dims[axis] = axis_dim
              sf = torch.nn.functional.pad(
                  n1.unsqueeze(0), (0, axis_dim - 1), value=n2
              )
              x = x * sf.view(scale_dims)
          else:
              x = x * axis_dim_float
  
          axis_idx = [slice(None)] * len(x.shape)
          axis_idx[axis] = slice(None, axis_dim)
          dct_out = torch.real(
              torch.fft.irfft(
                  scale * torch.complex(x, real_zero),
                  n=2 * axis_dim,
                  axis=axis,
              )
          )[axis_idx]
          return dct_out
  
      elif type == 4:
          dct_2 = dct(x, type=2, n=2 * axis_dim, axis=axis, norm=None)
          axis_idx = [slice(None)] * len(x.shape)
          axis_idx[axis] = slice(1, None, 2)
          dct_out = dct_2[axis_idx]
          if norm == "ortho":
              dct_out *= math.sqrt(0.5) * torch.rsqrt(axis_dim_float)
          return dct_out
  
imports: from typing import Optional, Union, Tuple, List, Literal, Sequence, Callable
  import torch
  import math
  import ivy
  from ivy.func_wrapper import with_unsupported_dtypes, with_supported_dtypes
  from .None import backend_version
  from ivy.functional.ivy.layers import _handle_padding, _get_num_padded_values, _validate_max_pool_params, _depth_max_pooling_helper
  from ivy.functional.ivy.experimental.layers import _padding_ceil_mode, _broadcast_pooling_helper
label_desc: Use image node_id 11 for calling a global function with example usage: dct() and returns: dct_out, dct_out, dct_out, dct_out