Commit 8a2e12d3 authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Migrate torch.norm to torch.linalg.vector_norm (#3522)

Summary:
torch.norm is now deprecated.
The usages in torchaudio seems to be vector norm, so replacing them with torch.linalg.vector_norm

Resolves https://github.com/pytorch/audio/issues/3484

Pull Request resolved: https://github.com/pytorch/audio/pull/3522

Reviewed By: huangruizhe

Differential Revision: D47926659

Pulled By: mthrok

fbshipit-source-id: f7428cf0168109a3d340b8784adc99bb5f781084
parent 84b12306
......@@ -35,7 +35,7 @@ class Pipeline(torch.nn.Module):
rir, _ = torchaudio.sox_effects.apply_effects_tensor(
self.rir, self.rir_sample_rate, effects=[["rate", str(sample_rate)]]
)
rir = rir / torch.norm(rir, p=2)
rir = rir / torch.linalg.vector_norm(rir, ord=2)
rir = torch.flip(rir, [1])
# 4. Apply RIR filter
......
......@@ -170,7 +170,7 @@ Audio(rir_raw, rate=sample_rate)
#
rir = rir_raw[:, int(sample_rate * 1.01) : int(sample_rate * 1.3)]
rir = rir / torch.norm(rir, p=2)
rir = rir / torch.linalg.vector_norm(rir, ord=2)
plot_waveform(rir, sample_rate, title="Room Impulse Response")
......
......@@ -472,8 +472,9 @@ class TransformsTestBase(TestBaseMixin):
self.assertFalse(False in torch.eq(f_axis_mean[f_axis_mean != 0], 1))
# Test if iid_masks gives different masking results for different spectrograms across the 0th dimension.
print(torch.norm(spec_masked[0] - spec_masked[1]).item())
diff = torch.linalg.vector_norm(spec_masked[0] - spec_masked[1]).item()
print(diff)
if iid_masks is True:
self.assertTrue(torch.norm(spec_masked[0] - spec_masked[1]).item() > 0)
self.assertTrue(diff > 0)
else:
self.assertTrue(torch.norm(spec_masked[0] - spec_masked[1]).item() == 0)
self.assertTrue(diff == 0)
......@@ -1046,8 +1046,8 @@ def _compute_nccf(waveform: Tensor, sample_rate: int, frame_time: float, freq_lo
output_frames = (
(s1 * s2).sum(-1)
/ (EPSILON + torch.norm(s1, p=2, dim=-1)).pow(2)
/ (EPSILON + torch.norm(s2, p=2, dim=-1)).pow(2)
/ (EPSILON + torch.linalg.vector_norm(s1, ord=2, dim=-1)).pow(2)
/ (EPSILON + torch.linalg.vector_norm(s2, ord=2, dim=-1)).pow(2)
)
output_lag.append(output_frames.unsqueeze(-1))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment