@parameterized.parameters((4096, 256, 32, 256, np.float32, 1e-05, 1e-06), (4096, 256, 32, 256, np.float64, 1e-08, 1e-08), (4096, 256, 64, 256, np.float32, 1e-05, 1e-06), (4096, 256, 64, 256, np.float64, 1e-08, 1e-08), (4096, 128, 25, 128, np.float32, 0.001, 1e-06), (4096, 128, 25, 128, np.float64, 0.0005, 1e-08), (4096, 127, 32, 128, np.float32, 0.001, 1e-06), (4096, 127, 32, 128, np.float64, 0.001, 1e-08), (4096, 128, 64, 128, np.float32, 0.4, 1e-06), (4096, 128, 64, 128, np.float64, 0.4, 1e-08))
def test_stft_round_trip(self, signal_length, frame_length, frame_step, fft_length, np_rtype, threshold, corrected_threshold):
    signal = np.random.normal(size=signal_length).astype(np_rtype)
    stft = spectral_ops.stft(signal, frame_length, frame_step, fft_length, pad_end=False)
    inverse_stft = spectral_ops.inverse_stft(stft, frame_length, frame_step, fft_length)
    inverse_stft_corrected = spectral_ops.inverse_stft(stft, frame_length, frame_step, fft_length, window_fn=spectral_ops.inverse_stft_window_fn(frame_step))
    (inverse_stft, inverse_stft_corrected) = self.evaluate([inverse_stft, inverse_stft_corrected])
    signal = signal[:inverse_stft.shape[0]]
    signal = signal[frame_length:(- frame_length)]
    inverse_stft = inverse_stft[frame_length:(- frame_length)]
    inverse_stft_corrected = inverse_stft_corrected[frame_length:(- frame_length)]
    inverse_stft_scaled = (inverse_stft / np.mean(np.abs(inverse_stft)))
    signal_scaled = (signal / np.mean(np.abs(signal)))
    self.assertLess(np.std((inverse_stft_scaled - signal_scaled)), threshold)
    self.assertLess(np.std((inverse_stft_corrected - signal)), corrected_threshold)
@parameterized.parameters((4096, 256, 32, 256, np.float32, 1e-05, 1e-06), (4096, 256, 32, 256, np.float64, 1e-08, 1e-08), (4096, 256, 64, 256, np.float32, 1e-05, 1e-06), (4096, 256, 64, 256, np.float64, 1e-08, 1e-08), (4096, 128, 25, 128, np.float32, 0.001, 1e-06), (4096, 128, 25, 128, np.float64, 0.0005, 1e-08), (4096, 127, 32, 128, np.float32, 0.001, 1e-06), (4096, 127, 32, 128, np.float64, 0.001, 1e-08), (4096, 128, 64, 128, np.float32, 0.4, 1e-06), (4096, 128, 64, 128, np.float64, 0.4, 1e-08))
def test_stft_round_trip(self, signal_length, frame_length, frame_step, fft_length, np_rtype, threshold, corrected_threshold):
    signal = np.random.normal(size=signal_length).astype(np_rtype)
    stft = spectral_ops.stft(signal, frame_length, frame_step, fft_length, pad_end=False)
    inverse_stft = spectral_ops.inverse_stft(stft, frame_length, frame_step, fft_length)
    inverse_stft_corrected = spectral_ops.inverse_stft(stft, frame_length, frame_step, fft_length, window_fn=spectral_ops.inverse_stft_window_fn(frame_step))
    (inverse_stft, inverse_stft_corrected) = self.evaluate([inverse_stft, inverse_stft_corrected])
    signal = signal[:inverse_stft.shape[0]]
    signal = signal[frame_length:(- frame_length)]
    inverse_stft = inverse_stft[frame_length:(- frame_length)]
    inverse_stft_corrected = inverse_stft_corrected[frame_length:(- frame_length)]
    inverse_stft_scaled = (inverse_stft / np.mean(np.abs(inverse_stft)))
    signal_scaled = (signal / np.mean(np.abs(signal)))
    self.assertLess(np.std((inverse_stft_scaled - signal_scaled)), threshold)
    self.assertLess(np.std((inverse_stft_corrected - signal)), corrected_threshold)