Unverified Commit 3549c57b authored by Vincent QB's avatar Vincent QB Committed by GitHub
Browse files

remove custom gcd command since python2.7 is deprecated. testing resample. (#441)

parent 4d58bc46
......@@ -321,10 +321,10 @@ class Tester(unittest.TestCase):
def test_scriptmodule_Resample(self):
tensor = torch.rand((2, 1000))
sample_rate = 100
sample_rate_2 = 50
sample_rate = 100.
sample_rate_2 = 50.
_test_script_module(transforms.Spectrogram, tensor, sample_rate, sample_rate_2)
_test_script_module(transforms.Resample, tensor, sample_rate, sample_rate_2)
def test_batch_Resample(self):
waveform = torch.randn(2, 2786)
......
......@@ -32,22 +32,6 @@ BLACKMAN = 'blackman'
WINDOWS = [HAMMING, HANNING, POVEY, RECTANGULAR, BLACKMAN]
def gcd(a, b):
# type: (int, int) -> int
"""Calculate the Greatest Common Divisor of a and b.
Unless b==0, the result will have the same sign as b (so that when
b is divided by it, the result comes out positive).
"""
try:
return math.gcd(a, b)
except AttributeError:
while b:
a, b = b, a % b
return a
def _next_power_of_2(x):
r"""Returns the smallest power of 2 that is greater than x
"""
......@@ -749,7 +733,7 @@ def _get_LR_indices_and_weights(orig_freq, new_freq, output_samples_in_unit, win
def _lcm(a, b):
# type: (int, int) -> int
return abs(a * b) // gcd(a, b)
return abs(a * b) // math.gcd(a, b)
def _get_num_LR_output_samples(input_num_samp, samp_rate_in, samp_rate_out):
......@@ -826,7 +810,7 @@ def resample_waveform(waveform, orig_freq, new_freq, lowpass_filter_width=6):
assert lowpass_cutoff * 2 <= min_freq
base_freq = gcd(int(orig_freq), int(new_freq))
base_freq = math.gcd(int(orig_freq), int(new_freq))
input_samples_in_unit = int(orig_freq) // base_freq
output_samples_in_unit = int(new_freq) // base_freq
......
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