@pytest.mark.parametrize('n_fft', [1000])
@pytest.mark.parametrize('hop_length', [None, 256])
@pytest.mark.parametrize('n_ch', [1, 2, 6])
@pytest.mark.parametrize('data_format', ['default', 'channels_first', 'channels_last'])
def test_spectrogram_correctness(n_fft, hop_length, n_ch, data_format):

    def _get_stft_model(following_layer=None):
        stft_model = tensorflow.keras.models.Sequential()
        stft_model.add(STFT(n_fft=n_fft, win_length=win_length, hop_length=hop_length, window_fn=None, pad_end=False, input_data_format=data_format, output_data_format=data_format, input_shape=input_shape, name='stft'))
        if (following_layer is not None):
            stft_model.add(following_layer)
        return stft_model
    (src_mono, batch_src, input_shape) = get_audio(data_format=data_format, n_ch=n_ch)
    win_length = n_fft
    S_ref = librosa.core.stft(src_mono, n_fft=n_fft, hop_length=hop_length, win_length=win_length, center=False).T
    S_ref = np.expand_dims(S_ref, axis=2)
    S_ref = np.tile(S_ref, [1, 1, n_ch])
    if (data_format == 'channels_first'):
        S_ref = np.transpose(S_ref, (2, 0, 1))
    stft_model = _get_stft_model()
    S_complex = stft_model.predict(batch_src)[0]
    allclose_complex_numbers(S_ref, S_complex)
    stft_mag_model = _get_stft_model(Magnitude())
    S = stft_mag_model.predict(batch_src)[0]
    np.testing.assert_allclose(np.abs(S_ref), S, atol=0.0002)
    stft_phase_model = _get_stft_model(Phase())
    S = stft_phase_model.predict(batch_src)[0]
    allclose_phase(np.angle(S_complex), S)
@pytest.mark.parametrize('n_fft', [1000])
@pytest.mark.parametrize('hop_length', [None, 256])
@pytest.mark.parametrize('n_ch', [1, 2, 6])
@pytest.mark.parametrize('data_format', ['default', 'channels_first', 'channels_last'])
def test_spectrogram_correctness(n_fft, hop_length, n_ch, data_format):

    def _get_stft_model(following_layer=None):
        stft_model = tensorflow.keras.models.Sequential()
        stft_model.add(STFT(n_fft=n_fft, win_length=win_length, hop_length=hop_length, window_fn=None, pad_end=False, input_data_format=data_format, output_data_format=data_format, input_shape=input_shape, name='stft'))
        if (following_layer is not None):
            stft_model.add(following_layer)
        return stft_model
    (src_mono, batch_src, input_shape) = get_audio(data_format=data_format, n_ch=n_ch)
    win_length = n_fft
    S_ref = librosa.core.stft(src_mono, n_fft=n_fft, hop_length=hop_length, win_length=win_length, center=False).T
    S_ref = np.expand_dims(S_ref, axis=2)
    S_ref = np.tile(S_ref, [1, 1, n_ch])
    if (data_format == 'channels_first'):
        S_ref = np.transpose(S_ref, (2, 0, 1))
    stft_model = _get_stft_model()
    S_complex = stft_model.predict(batch_src)[0]
    allclose_complex_numbers(S_ref, S_complex)
    stft_mag_model = _get_stft_model(Magnitude())
    S = stft_mag_model.predict(batch_src)[0]
    np.testing.assert_allclose(np.abs(S_ref), S, atol=0.0002)
    stft_phase_model = _get_stft_model(Phase())
    S = stft_phase_model.predict(batch_src)[0]
    allclose_phase(np.angle(S_complex), S)