def test_ifft(self): for libname in ("numpy","scipy"): set_fftlib(libname) a = np.random.randn(4) fft = np.fft.fft(a) a = np.fft.ifft(fft) out = _ifft(fft) self.assertTrue(np.allclose(a, out))
def _cross_sum_rfft(x, y, t, length, dummy, out): out_length = len(dummy) tmp1 = np.zeros((length * 2), y.dtype) _fill_data(x, t, tmp1) x = _fft(tmp1, overwrite_x=True) np.multiply(x, y, out=x) _out = _ifft(x, overwrite_x=True) out[:] += _out[:out_length].real out[1:] = out[1:] + _out[-1:-out_length:-1].real
def _auto_corr_fft(x, t, length, dummy, out): out_length = len(dummy) tmp = np.zeros((length * 2), x.dtype) _fill_data(x, t, tmp) #tmp[list(t)] = x x = _fft(tmp, overwrite_x=True) y = np.conj(x) np.multiply(x, y, out=x) _out = _ifft(x, overwrite_x=True) out[:] += _out[:out_length].real
def _auto_corr_fft_regular(x, dummy, out): out_length = len(dummy) length = len(x) tmp = np.empty((length * 2), x.dtype) tmp[0:length] = x tmp[length:] = 0. x = _fft(tmp, overwrite_x=True) x = x * np.conj(x) _out = _ifft(x, overwrite_x=True) out[:] += _out[:out_length].real
def _cross_corr_fft(x, y, t1, t2, length, dummy, out): out_length = len(dummy) tmp1 = np.zeros((length * 2), x.dtype) _fill_data(x, t1, tmp1) #tmp1[list(t1)] = x tmp2 = np.zeros((length * 2), y.dtype) _fill_data(y, t2, tmp2) #tmp2[list(t2)] = y x = _fft(tmp1, overwrite_x=True) y = _fft(tmp2, overwrite_x=True) np.conj(y, out=y) np.multiply(x, y, out=x) _out = _ifft(x, overwrite_x=True) out[:] += _out[:out_length].real out[1:] += _out[-1:-out_length:-1].real
def _cross_corr_fft_regular(x, y, dummy, out): out_length = len(dummy) length = len(x) tmp1 = np.empty((length * 2), x.dtype) tmp1[0:length] = x tmp1[length:] = 0. tmp2 = np.empty((length * 2), y.dtype) tmp2[0:length] = y tmp2[length:] = 0. x = _fft(tmp1, overwrite_x=True) y = _fft(tmp2, overwrite_x=True) x = x * np.conj(y) _out = _ifft(x, overwrite_x=True) out[:] += _out[:out_length].real out[1:] += _out[-1:-out_length:-1].real