def test_resample(num_samps, resample_num_samps, window): cpu_time = np.linspace(0, 10, num_samps, endpoint=False) cpu_sig = np.cos(-cpu_time**2 / 6.0) gpu_sig = cp.asarray(cpu_sig) cpu_resample = signal.resample(cpu_sig, resample_num_samps, window=window) gpu_resample = cp.asnumpy( cusignal.resample(cpu_sig, resample_num_samps, window=window)) assert array_equal(cpu_resample, gpu_resample)
def test_resample(self, linspace_data_gen, num_samps, resample_num_samps, window): cpu_sig, gpu_sig = linspace_data_gen(0, 10, num_samps, endpoint=False) cpu_resample = signal.resample(cpu_sig, resample_num_samps, window=window) gpu_resample = cp.asnumpy( cusignal.resample(gpu_sig, resample_num_samps, window=window)) assert array_equal(cpu_resample, gpu_resample)
def __call__(self, signal: Signals, device): signal.to(device) if self.old is None: self.old = signal.sps if self.new is None: self.new = signal.sps_in_fiber if device == 'cuda': from cusignal import resample_poly as resample signal.samples_in_fiber = resample(signal.samples, int(self.new / self.old), 1, axis=1) else: from resampy import resample signal.samples_in_fiber = resample(signal.samples, self.old, self.new) if self.is_quantize: assert self.clipping_ratio is not None and self.resoultion_bits is not None self.quantize(signal, device) return signal
def gpu_version(self, sig, resample_num_samps, window): with cp.cuda.Stream.null: out = cusignal.resample(sig, resample_num_samps, window=window) cp.cuda.Stream.null.synchronize() return out