def test_fft_float_axis(self): a = np.array(np.random.randn(2,4,8),"float32") b = a.reshape(2,8,4) self.assert_equal(fft.fft(a, axis = 0), np.fft.fft(a,axis = 0)) self.assert_equal(fft.fft(b,axis = 0), np.fft.fft(b, axis = 0)) self.assert_equal(fft.fft(a, axis = 1), np.fft.fft(a,axis = 1)) self.assert_equal(fft.fft(b,axis = 1), np.fft.fft(b, axis = 1))
def test_fft_double_axis(self): a = np.array(np.random.randn(2,4,8),"complex64") b = a.reshape(2,8,4) self.assert_equal(fft.fft(a, axis = 0), np.fft.fft(a,axis = 0)) self.assert_equal(fft.fft(b,axis = 0), np.fft.fft(b, axis = 0)) self.assert_equal(fft.fft(a, axis = 1), np.fft.fft(a,axis = 1)) self.assert_equal(fft.fft(b,axis = 1), np.fft.fft(b, axis = 1))
def test_fft_float(self): a = np.array(np.random.randn(8),"complex64") a0 = a.copy() a_split = a.real.copy(), a.imag.copy() with self.subTest(i = 0): out = fft.ifft(fft.fft(a, split_out = True), split_in = True)/8 self.assert_equal(out, a0) with self.subTest(i = 1): out_split = fft.ifft(fft.fft(a, split_out = True), split_in = True, split_out = True) self.assert_equal(a0.real, out_split[0]/8) self.assert_equal(a_split[1], out_split[1]/8) with self.subTest(i = 2): out_split = fft.ifft(fft.fft(a), split_out = True) self.assert_equal(a_split[0], out_split[0]/8) self.assert_equal(a_split[1], out_split[1]/8) with self.subTest(i = 3): self.assert_equal(fft.ifft(fft.fft(a_split, split_in = True))/8, a) with self.subTest(i = 4): out_split = fft.ifft(fft.fft(a_split, split_in = True),split_out = True) self.assert_equal(a_split[0], out_split[0]/8) self.assert_equal(a_split[1], out_split[1]/8) with self.subTest(i = 5): out_split = fft.ifft(fft.fft(a_split, split_in = True, split_out = True),split_out = True,split_in = True) self.assert_equal(a_split[0], out_split[0]/8) self.assert_equal(a_split[1], out_split[1]/8)
def test_fft_double(self): a = np.array(np.random.randn(2,4,8),"complex128") b = a.reshape(2,8,4) self.assert_equal(fft.fft(a), np.fft.fft(a)) self.assert_equal(fft.fft(b), np.fft.fft(b))
def test_fft(self): for dtype in ("complex64", "complex128"): a0 = np.array(np.random.randn(2,4,8),dtype) f = fft.fft(a0) with self.subTest(i = 0): a = a0.copy() fft.fft(a, overwrite_x = True) self.assert_equal(a,f) with self.subTest(i = 1): real,imag = a0.real.copy(),a0.imag.copy() fr,fi = fft.fft((real, imag), split_in = True, split_out = True) fft.fft((real,imag), overwrite_x = True, split_in = True, split_out = True) self.assert_equal(fr,real) self.assert_equal(fi,imag) with self.subTest(i = 2): a = a0.copy() fft.fft(a, split_out = True, overwrite_x = True) self.assert_equal(a,a0) with self.subTest(i = 3): real,imag = a0.real.copy(),a0.imag.copy() f = fft.fft((real, imag), split_in = True) fft.fft((real,imag), overwrite_x = True, split_in = True) self.assert_equal(real, f.real) self.assert_equal(imag,f.imag)
def test_wrong_fft_shape(self): with self.assertRaises(ValueError): fft.fft([1,2,3])