def test_torch_complex_format(dim, max_tested_ndim): # Random tensor shape tensor_shape = [random.randint(1, 10) for _ in range(max_tested_ndim)] # Make sure complex dimension has even shape tensor_shape[dim] = 2 * tensor_shape[dim] complex_tensor = torch.randn(tensor_shape) ta_tensor = transforms.to_torch_complex(complex_tensor, dim=dim) tensor_back = transforms.from_torch_complex(ta_tensor, dim=dim) assert_allclose(complex_tensor, tensor_back)
def forward_encoder(self, wav): tf_rep = self.encoder(wav) return to_torch_complex(tf_rep)
def forward_encoder(self, wav): tf_rep = self.encoder(wav) # Remove Nyquist frequency bin return to_torch_complex(tf_rep)[..., :-1, :]
SCM, RTFMVDRBeamformer, SDWMWFBeamformer, GEVBeamformer, stable_cholesky, ) torch_has_complex_support = tuple(map( int, torch.__version__.split(".")[:2])) >= (1, 8) _stft, _istft = make_enc_dec("stft", kernel_size=512, n_filters=512, stride=128) stft = lambda x: tr.to_torch_complex(_stft(x)) istft = lambda x: _istft(tr.from_torch_complex(x)) @pytest.mark.skipif(not torch_has_complex_support, "No complex support ") def _default_beamformer_test(beamformer: Beamformer, n_mics=4, *args, **kwargs): scm = SCM() speech = torch.randn(1, n_mics, 16000 * 6) noise = torch.randn(1, n_mics, 16000 * 6) mix = speech + noise # GeV Beamforming mix_stft = stft(mix)