code: def test_stft_phase(device):
      x = example_y
      stft = STFT(n_fft=2048, hop_length=512).to(device)
      X = stft(
          torch.tensor(x, device=device).unsqueeze(0),
          output_format="Phase",
      )
      X_real, X_imag = torch.cos(X).squeeze(), torch.sin(X).squeeze()
      _, X_librosa = librosa.core.magphase(
          librosa.stft(x, n_fft=2048, hop_length=512)
      )
  
      real_diff, imag_diff = np.mean(
          np.abs(X_real.cpu().numpy() - X_librosa.real)
      ), np.mean(np.abs(X_imag.cpu().numpy() - X_librosa.imag))
  
      # I find that np.allclose is too strict for allowing phase to be similar to librosa.
      # Hence for phase we use average element-wise distance as the test metric.
      assert real_diff < 2e-2 and imag_diff < 2e-2
  
file_path: nnAudio/Installation/tests/test_stft.py
imports: import pytest
  import librosa
  import torch
  from scipy.signal import chirp, sweep_poly
  import sys
  from nnAudio.Spectrogram import *
  from parameters import *
  import warnings
label_desc: Use image node_id 6 for calling a global function with example usage: test_stft_phase(device) without return types