code: def test_get_rtf(ch, mode):
      if not is_torch_1_9_plus and mode == "evd":
          # torch 1.9.0+ is required for "evd" mode
          return
      if mode == "evd":
          complex_wrapper = torch.complex
          complex_module = torch
      else:
          complex_wrapper = ComplexTensor
          complex_module = FC
      stft = Stft(
          n_fft=8,
          win_length=None,
          hop_length=2,
          center=True,
          window="hann",
          normalized=False,
          onesided=True,
      )
      torch.random.manual_seed(0)
      x = random_speech[..., :ch]
      ilens = torch.LongTensor([16, 12])
      # (B, T, C, F) -> (B, F, C, T)
      X = complex_wrapper(
          *torch.unbind(stft(x, ilens)[0], dim=-1)
      ).transpose(-1, -3)
      # (B, F, C, C)
      Phi_X = complex_module.einsum("...ct,...et->...ce", [X, X.conj()])
  
      is_singular = True
      while is_singular:
          N = complex_wrapper(
              torch.randn_like(X.real), torch.randn_like(X.imag)
          )
          Phi_N = complex_module.einsum(
              "...ct,...et->...ce", [N, N.conj()]
          )
          is_singular = not np.all(
              np.linalg.matrix_rank(Phi_N.numpy()) == ch
          )
  
      # (B, F, C, 1)
      rtf = get_rtf(
          Phi_X, Phi_N, mode=mode, reference_vector=0, iterations=20
      )
      if is_torch_1_1_plus:
          rtf = rtf / (
              rtf.abs().max(dim=-2, keepdim=True).values + 1e-15
          )
      else:
          rtf = rtf / (rtf.abs().max(dim=-2, keepdim=True)[0] + 1e-15)
      # rtf \approx Phi_N MaxEigVec(Phi_N^-1 @ Phi_X)
      if is_torch_1_1_plus:
          # torch.solve is required, which is only available after pytorch 1.1.0+
          mat = solve(Phi_X, Phi_N)[0]
          max_eigenvec = solve(rtf, Phi_N)[0]
      else:
          mat = complex_module.matmul(Phi_N.inverse2(), Phi_X)
          max_eigenvec = complex_module.matmul(Phi_N.inverse2(), rtf)
      factor = complex_module.matmul(mat, max_eigenvec)
      assert complex_module.allclose(
          complex_module.matmul(max_eigenvec, factor.transpose(-1, -2)),
          complex_module.matmul(factor, max_eigenvec.transpose(-1, -2)),
      )
  
file_path: espnet/test/espnet2/enh/layers/test_enh_layers.py
imports: import numpy
  import pytest
  import torch
  import torch_complex.functional
  from packaging.version import parse
  from torch_complex.tensor import ComplexTensor
  from espnet2.enh.layers.beamformer import generalized_eigenvalue_decomposition, get_rtf, gev_phase_correction, signal_framing
  from espnet2.enh.layers.complex_utils import solve
  from espnet2.layers.stft import Stft
label_desc: Use image node_id 1 for calling a global function with example usage: test_get_rtf(ch, mode) without return types