def test_contiguity(order, shape, axis): x = np.zeros(shape, dtype=np.float, order=order) sr_orig = 1 sr_new = 2 y = resamcupy.resample(x, sr_orig, sr_new, axis=axis) assert x.flags['C_CONTIGUOUS'] == y.flags['C_CONTIGUOUS'] assert x.flags['F_CONTIGUOUS'] == y.flags['F_CONTIGUOUS']
def test_shape(axis): sr_orig = 100 sr_new = sr_orig // 2 X = np.random.randn(sr_orig, sr_orig, sr_orig) Y = resamcupy.resample(X, sr_orig, sr_new, axis=axis) target_shape = list(X.shape) target_shape[axis] = target_shape[axis] * sr_new // sr_orig assert target_shape == list(Y.shape)
def test_good_window(): sr_orig = 100 sr_new = 200 x = np.random.randn(500) y = resamcupy.resample(x, sr_orig, sr_new, filter='sinc_window', window=scipy.signal.blackman) assert len(y) == 2 * len(x)
def test_quality_sweep(sr_orig, sr_new, fil, rms): FREQ = 8192 DURATION = 5.0 x = make_sweep(FREQ, sr_orig, DURATION) y = make_sweep(FREQ, sr_new, DURATION) y_pred = resamcupy.resample(x, sr_orig, sr_new, filter=fil) idx = slice(sr_new // 2, -sr_new // 2) err = np.mean(np.abs(y[idx] - y_pred[idx])) assert err <= rms, '{:g} > {:g}'.format(err, rms)
def test_quality_sine(sr_orig, sr_new, fil, rms): FREQ = 512.0 DURATION = 2.0 x = make_tone(FREQ, sr_orig, DURATION) y = make_tone(FREQ, sr_new, DURATION) y_pred = resamcupy.resample(x, sr_orig, sr_new, filter=fil) idx = slice(sr_new // 2, -sr_new // 2) err = cp.mean(cp.abs(y[idx] - y_pred[idx])) assert err <= rms #, '{:g} > {:g}'.format(err, rms)
def test_short_signal(): x = np.zeros(2) resamcupy.resample(x, 4, 1)
def test_bad_window(): x = np.zeros(100) resamcupy.resample(x, 100, 200, filter='sinc_window', window=np.ones(50))
def test_dtype(dtype): x = np.random.randn(100).astype(dtype) y = resamcupy.resample(x, 100, 200) assert x.dtype == y.dtype
def test_bad_num_zeros(): x = np.zeros(100) resamcupy.resample(x, 100, 50, filter='sinc_window', num_zeros=0)
def test_bad_precision(): x = np.zeros(100) resamcupy.resample(x, 100, 50, filter='sinc_window', precision=-1)
def test_bad_rolloff(rolloff): x = np.zeros(100) resamcupy.resample(x, 100, 50, filter='sinc_window', rolloff=rolloff)
def test_bad_sr(sr_orig, sr_new): x = np.zeros(100) resamcupy.resample(x, sr_orig, sr_new)