def test_dct_backend(self, xp, dtype): backend = 'scipy' if xp is np else cp_fft with scipy_fft.set_backend(backend): fft_func = getattr(scipy_fft, self.function) r = xp.logspace(-2, 2, 10) dln = xp.log(r[1]/r[0]) return fft_func(r, dln, mu=0.5)
def preprocess(data,scale_min=-1,scale_max=1,training_min=None, training_max=None, sigma=(0,2,2), eps=0.01,ST_method='DCT',cpus_to_use =-1,inverse=False,**kwargs): """ Pre-processing for data sets. Each data set (train, val, pred) Must be processed separately. To avoid bias, only training set must be used to estimate training parameters """ if ST_method == 'DCT': ST = ST_ndim_DCT elif ST_method == 'FFT': ST = ST_ndim_FFT with set_backend(pyfftw.interfaces.scipy_fft), pyfftw.interfaces.scipy_fft.set_workers(cpus_to_use): #faster if we enable cache using pyfftw pyfftw.interfaces.cache.enable() # perform standardizing transform using frequency method of your choice data = ST(data,sigma,eps,inverse) if (training_min is None) or (training_max is None): # Assumes training set training_min, training_max = data.min(), data.max() data = scale(data,scale_min,scale_max,training_min,training_max,inverse) return data, training_min, training_max else: # Appropriate for val/test set data = scale(data,scale_min,scale_max,training_min,training_max,inverse) return data
def test_backend_call(func, np_func, mock): x = np.arange(20).reshape((10, 2)) answer = np_func(x) assert_allclose(func(x), answer, atol=1e-10) with set_backend(mock_backend, only=True): mock.number_calls = 0 y = func(x) assert_equal(y, mock.return_value) assert_equal(mock.number_calls, 1) assert_allclose(func(x), answer, atol=1e-10)
def test_backend_plan(func, mock): x = np.arange(20).reshape((10, 2)) with pytest.raises(NotImplementedError, match='precomputed plan'): func(x, plan='foo') with set_backend(mock_backend, only=True): mock.number_calls = 0 y = func(x, plan='foo') assert_equal(y, mock.return_value) assert_equal(mock.number_calls, 1) assert_equal(mock.last_args[1]['plan'], 'foo')
def test_dct_backend(self, xp, dtype): backend = 'scipy' if xp is np else cp_fft with scipy_fft.set_backend(backend): fft_func = getattr(scipy_fft, self.function) return self._run_transform(fft_func, xp, dtype)