def test_lombscargle(num_in_samps, num_out_samps, precenter, normalize, use_numba): A = 2.0 w = 1.0 phi = 0.5 * np.pi frac_points = 0.9 # Fraction of points to select r = np.random.rand(num_in_samps) x = np.linspace(0.01, 10 * np.pi, num_in_samps) x = x[r >= frac_points] y = A * np.cos(w * x + phi) f = np.linspace(0.01, 10, num_out_samps) cpu_lombscargle = signal.lombscargle(x, y, f, precenter, normalize) d_x = cp.asarray(x) d_y = cp.asarray(y) d_f = cp.asarray(f) gpu_lombscargle = cp.asnumpy( cusignal.lombscargle( d_x, d_y, d_f, precenter, normalize, use_numba=use_numba, )) assert array_equal(cpu_lombscargle, gpu_lombscargle)
def bench_stft_gpu(self, rand_data_gen, benchmark, num_samps, fs, nperseg): cpu_sig, gpu_sig = rand_data_gen(num_samps) _, _, output = benchmark(cusignal.stft, gpu_sig, fs, nperseg=nperseg) _, _, key = self.cpu_version(cpu_sig, fs, nperseg) assert array_equal(cp.asnumpy(output), key)
def test_quadratic_gpu(self, gpubenchmark, rand_data_gen, x): cpu_sig, gpu_sig = rand_data_gen(x) output = gpubenchmark(self.gpu_version, gpu_sig) key = self.cpu_version(cpu_sig) assert array_equal(cp.asnumpy(output), key)
def test_wiener(num_samps): cpu_sig = np.random.rand(num_samps) gpu_sig = cp.asarray(cpu_sig) cpu_wfilt = signal.wiener(cpu_sig) gpu_wfilt = cp.asnumpy(cusignal.wiener(gpu_sig)) assert array_equal(cpu_wfilt, gpu_wfilt)
def bench_exponential_gpu(self, benchmark, num_samps, tau): output = benchmark( cusignal.windows.exponential, num_samps, tau=tau ) key = self.cpu_version(num_samps, tau) assert array_equal(cp.asnumpy(output), key)
def test_gauss_spline_gpu(self, gpubenchmark, rand_data_gen, x, n): cpu_sig, gpu_sig = rand_data_gen(x) output = gpubenchmark(self.gpu_version, gpu_sig, n) key = self.cpu_version(cpu_sig, n) assert array_equal(cp.asnumpy(output), key)
def bench_kaiser_gpu(self, benchmark, num_samps, beta): output = benchmark( cusignal.windows.kaiser, num_samps, beta, sym=True ) key = self.cpu_version(num_samps, beta) assert array_equal(cp.asnumpy(output), key)
def bench_general_gaussian_gpu(self, benchmark, num_samps, p, std): output = benchmark( cusignal.windows.general_gaussian, num_samps, p, std ) key = self.cpu_version(num_samps, p, std) assert array_equal(cp.asnumpy(output), key)
def test_freq_shift_gpu(self, rand_data_gen, gpubenchmark, dtype, num_samps, freq, fs): cpu_sig, gpu_sig = rand_data_gen(num_samps, 1, dtype) output = gpubenchmark(self.gpu_version, gpu_sig, freq, fs) key = self.cpu_version(cpu_sig, freq, fs) assert array_equal(cp.asnumpy(output), key)
def bench_general_hamming_gpu(self, benchmark, num_samps, alpha): output = benchmark( cusignal.windows.general_hamming, num_samps, alpha, sym=True ) key = self.cpu_version(num_samps, alpha) assert array_equal(cp.asnumpy(output), key)
def test_detrend_gpu(self, linspace_data_gen, gpubenchmark, num_samps): cpu_sig, gpu_sig = linspace_data_gen(0, 10, num_samps) output = gpubenchmark(cusignal.detrend, gpu_sig) key = self.cpu_version(cpu_sig) assert array_equal(cp.asnumpy(output), key)
def test_wiener_gpu(self, rand_data_gen, gpubenchmark, num_samps): cpu_sig, gpu_sig = rand_data_gen(num_samps) output = gpubenchmark(self.gpu_version, gpu_sig) key = self.cpu_version(cpu_sig) assert array_equal(cp.asnumpy(output), key)
def test_lombscargle( self, lombscargle_gen, num_in_samps, num_out_samps, precenter, normalize, use_numba, ): cpu_x, cpu_y, cpu_f, gpu_x, gpu_y, gpu_f = lombscargle_gen( num_in_samps, num_out_samps) cpu_lombscargle = signal.lombscargle(cpu_x, cpu_y, cpu_f, precenter, normalize) gpu_lombscargle = cp.asnumpy( cusignal.lombscargle( gpu_x, gpu_y, gpu_f, precenter, normalize, use_numba=use_numba, )) assert array_equal(cpu_lombscargle, gpu_lombscargle)
def test_general_cosine_gpu(self, gpubenchmark, num_samps): HFT90D = [1, 1.942604, 1.340318, 0.440811, 0.043097] output = gpubenchmark(self.cpu_version, num_samps, HFT90D) key = self.cpu_version(num_samps, HFT90D) assert array_equal(cp.asnumpy(output), key)
def test_hilbert2(num_samps): cpu_sig = np.random.rand(num_samps, num_samps) gpu_sig = cp.asarray(cpu_sig) cpu_hilbert2 = signal.hilbert2(cpu_sig) gpu_hilbert2 = cp.asnumpy(cusignal.hilbert2(gpu_sig)) assert array_equal(cpu_hilbert2, gpu_hilbert2)
def bench_square_gpu(self, time_data_gen, benchmark, num_samps, duty): cpu_sig, gpu_sig = time_data_gen(0, 10, num_samps) output = benchmark(cusignal.square, gpu_sig, duty) key = self.cpu_version(cpu_sig, duty) assert array_equal(cp.asnumpy(output), key)
def test_chirp(num_samps, f0, t1, f1, method): cpu_time = np.linspace(0, 10, num_samps) gpu_time = cp.asarray(cpu_time) cpu_chirp = signal.chirp(cpu_time, f0, t1, f1, method) gpu_chirp = cp.asnumpy(cusignal.chirp(gpu_time, f0, t1, f1, method)) assert array_equal(cpu_chirp, gpu_chirp)
def bench_firwin_gpu(self, benchmark, num_samps, f1, f2): output = benchmark(cusignal.firwin, num_samps, [f1, f2], pass_zero=False) key = self.cpu_version(num_samps, f1, f2) assert array_equal(cp.asnumpy(output), key)
def test_square(num_samps, duty): cpu_time = np.linspace(0, 10, num_samps) gpu_time = cp.asarray(cpu_time) cpu_pwm = signal.square(cpu_time, duty) gpu_pwm = cp.asnumpy(cusignal.square(gpu_time, duty)) assert array_equal(cpu_pwm, gpu_pwm)
def test_fftconvolve_gpu(self, rand_data_gen, gpubenchmark, num_samps, mode): cpu_sig, gpu_sig = rand_data_gen(num_samps) output = gpubenchmark(self.gpu_version, gpu_sig, mode) key = self.cpu_version(cpu_sig, mode) assert array_equal(cp.asnumpy(output), key)
def test_stft_gpu(self, rand_data_gen, gpubenchmark, dtype, num_samps, fs, nperseg): cpu_sig, gpu_sig = rand_data_gen(num_samps, 1, dtype) _, _, output = gpubenchmark(self.gpu_version, gpu_sig, fs, nperseg) _, _, key = self.cpu_version(cpu_sig, fs, nperseg) assert array_equal(cp.asnumpy(output), key)
def test_fftconvolve(self, num_samps, mode="full"): cpu_sig = np.random.rand(num_samps) gpu_sig = cp.asarray(cpu_sig) cpu_autocorr = signal.fftconvolve(cpu_sig, cpu_sig[::-1], mode=mode) gpu_autocorr = cp.asnumpy( cusignal.fftconvolve(gpu_sig, gpu_sig[::-1], mode=mode)) assert array_equal(cpu_autocorr, gpu_autocorr)
def test_channelizepoly_gpu( self, gpubenchmark, rand_data_gen, dtype, num_samps, filt_samps, n_chan, ): cpu_sig, gpu_sig = rand_data_gen(num_samps, 1, dtype) cpu_filt, gpu_filt = rand_data_gen(filt_samps, 1, dtype) output = gpubenchmark(self.gpu_version, gpu_sig, gpu_filt, n_chan) key = self.cpu_version(cpu_sig, cpu_filt, n_chan) array_equal(output, key)
def test_real_cepstrum_gpu(self, rand_data_gen, gpubenchmark, num_samps, n): cpu_sig, gpu_sig = rand_data_gen(num_samps) output = gpubenchmark(self.gpu_version, gpu_sig, n) key = self.cpu_version(cpu_sig, n) assert array_equal(cp.asnumpy(output), key)
def test_periodogram_gpu( self, rand_data_gen, gpubenchmark, dtype, num_samps, fs, window, scaling, ): cpu_sig, gpu_sig = rand_data_gen(num_samps, 1, dtype) output = gpubenchmark(self.gpu_version, gpu_sig, fs, window, scaling) key = self.cpu_version(cpu_sig, fs, window, scaling) array_equal(output, key)
def test_gausspulse_gpu(self, time_data_gen, gpubenchmark, num_samps, fc): cpu_sig, gpu_sig = time_data_gen(0, 10, num_samps) _, _, output = gpubenchmark(self.gpu_version, gpu_sig, fc) _, _, key = self.cpu_version(cpu_sig, fc) assert array_equal(cp.asnumpy(output), key)
def test_square_gpu(self, time_data_gen, gpubenchmark, num_samps, duty): cpu_sig, gpu_sig = time_data_gen(0, 10, num_samps) output = gpubenchmark(self.gpu_version, gpu_sig, duty) key = self.cpu_version(cpu_sig, duty) assert array_equal(cp.asnumpy(output), key)
def test_gausspulse(self, time_data_gen, num_samps, fc): cpu_time, gpu_time = time_data_gen(0, 10, num_samps) cpu_pwm = signal.gausspulse(cpu_time, fc, retquad=True, retenv=True) gpu_pwm = cp.asnumpy( cusignal.gausspulse(gpu_time, fc, retquad=True, retenv=True)) assert array_equal(cpu_pwm, gpu_pwm)
def bench_chirp_gpu(self, time_data_gen, benchmark, num_samps, f0, t1, f1, method): cpu_sig, gpu_sig = time_data_gen(0, 10, num_samps) output = benchmark(cusignal.chirp, gpu_sig, f0, t1, f1, method) key = self.cpu_version(cpu_sig, f0, t1, f1, method) assert array_equal(cp.asnumpy(output), key)
def test_correlate(num_samps, num_taps, mode='same'): cpu_sig = np.random.rand(num_samps) gpu_sig = cp.asarray(cpu_sig) cpu_corr = signal.correlate(cpu_sig, np.ones(num_taps), mode=mode) gpu_corr = cp.asnumpy( cusignal.correlate(gpu_sig, cp.ones(num_taps), mode=mode)) assert array_equal(cpu_corr, gpu_corr)