@pytest.mark.parametrize('data_format', ['default', 'channels_first', 'channels_last'])
def test_mag_phase(data_format):
    n_ch = 1
    (n_fft, hop_length, win_length) = (512, 256, 512)
    (src_mono, batch_src, input_shape) = get_audio(data_format=data_format, n_ch=n_ch)
    mag_phase_layer = get_stft_mag_phase(input_shape=input_shape, n_fft=n_fft, win_length=win_length, hop_length=hop_length, input_data_format=data_format, output_data_format=data_format)
    model = tensorflow.keras.models.Sequential()
    model.add(mag_phase_layer)
    mag_phase_kapre = model(batch_src)[0]
    ch_axis = (0 if (data_format == 'channels_first') else 2)
    mag_phase_ref = np.stack(librosa.magphase(librosa.stft(src_mono, n_fft=n_fft, hop_length=hop_length, win_length=win_length, center=False).T), axis=ch_axis)
    np.testing.assert_equal(mag_phase_kapre.shape, mag_phase_ref.shape)
    np.testing.assert_allclose(np.take(mag_phase_kapre, [0], axis=ch_axis), np.take(mag_phase_ref, [0], axis=ch_axis), atol=0.0002)
@pytest.mark.parametrize('data_format', ['default', 'channels_first', 'channels_last'])
def test_mag_phase(data_format):
    n_ch = 1
    (n_fft, hop_length, win_length) = (512, 256, 512)
    (src_mono, batch_src, input_shape) = get_audio(data_format=data_format, n_ch=n_ch)
    mag_phase_layer = get_stft_mag_phase(input_shape=input_shape, n_fft=n_fft, win_length=win_length, hop_length=hop_length, input_data_format=data_format, output_data_format=data_format)
    model = tensorflow.keras.models.Sequential()
    model.add(mag_phase_layer)
    mag_phase_kapre = model(batch_src)[0]
    ch_axis = (0 if (data_format == 'channels_first') else 2)
    mag_phase_ref = np.stack(librosa.magphase(librosa.stft(src_mono, n_fft=n_fft, hop_length=hop_length, win_length=win_length, center=False).T), axis=ch_axis)
    np.testing.assert_equal(mag_phase_kapre.shape, mag_phase_ref.shape)
    np.testing.assert_allclose(np.take(mag_phase_kapre, [0], axis=ch_axis), np.take(mag_phase_ref, [0], axis=ch_axis), atol=0.0002)