code: def idct(x, dim=-1):
      """
      Inverse discrete cosine transform of type II, scaled to be orthonormal.
  
      This is the inverse of :func:`dct_ii` , and is equivalent to
      :func:`scipy.fftpack.idct` with ``norm="ortho"``.
  
      :param Tensor x: The input signal.
      :param int dim: Dimension along which to compute DCT.
      :rtype: Tensor
      """
      if dim >= 0:
          dim -= x.dim()
      if dim != -1:
          y = x.reshape(x.shape[: dim + 1] + (-1,)).transpose(-1, -2)
          return idct(y).transpose(-1, -2).reshape(x.shape)
  
      N = x.size(-1)
      scale = torch.cat(
          [
              x.new_tensor([math.sqrt(N)]),
              x.new_full((N - 1,), math.sqrt(0.5 * N)),
          ]
      )
      x = x * scale
      # Step 1, solve X = cos(k) * Yr + sin(k) * Yi
      # We know that Y[1:] is conjugate to Y[:0:-1], hence
      # X[:0:-1] = sin(k) * Yr[1:] + cos(k) * Yi[1:]
      # So Yr[1:] = cos(k) * X[1:] + sin(k) * X[:0:-1]
      # and Yi[1:] = sin(k) * X[1:] - cos(k) * X[:0:-1]
      # In addition, Yi[0] = 0, Yr[0] = X[0]
      # In other words, Y = complex_mul(e^ik, X - i[0, X[:0:-1]])
      M = N // 2 + 1  # half size
      xi = torch.nn.functional.pad(-x[..., N - M + 1 :], (0, 1)).flip(
          -1
      )
      X = torch.stack([x[..., :M], xi], dim=-1)
      coef_real = torch.cos(
          torch.linspace(
              0, 0.5 * math.pi, N + 1, dtype=x.dtype, device=x.device
          )
      )
      coef = torch.stack(
          [coef_real[:M], coef_real[-M:].flip(-1)], dim=-1
      )
      Y = as_complex(coef) * as_complex(X)
      # Step 2
      y = irfft(Y, n=N)
      # Step 3
      return torch.stack([y, y.flip(-1)], axis=-1).reshape(
          x.shape[:-1] + (-1,)
      )[..., :N]
  
imports: import math
  import torch
  from torch.fft import irfft, rfft
  from ..None import settings
label_desc: Use image node_id 12 for calling a global function with example usage: idct(x, dim) and returns: torch, idct