def test_nufft1d_forward(self): fourier_pts = np.random.uniform(-np.pi, np.pi, self.size_1d) sig = np.random.uniform(-1, 1, self.size_1d) + 1j * np.zeros(self.size_1d) py_nufft_obj = py_nufft.factory(self.type) py_nufft_obj.forward1d(sig, fourier_pts, eps=self.eps)[0]
def test_nufft2d_forward(self): fourier_pts_x = np.random.uniform(-np.pi, np.pi, self.size_2d) fourier_pts_y = np.random.uniform(-np.pi, np.pi, self.size_2d) fourier_pts = np.transpose(np.array(zip(fourier_pts_x, fourier_pts_y))) im = np.random.uniform(-1, 1, self.size_2d * self.size_2d).reshape( self.size_2d, self.size_2d) py_nufft_obj = py_nufft.factory(self.type) py_nufft_obj.forward2d(im, fourier_pts, eps=self.eps)[0]
def test_nufft_adjoint_1d(self, n=34, diff=1e-8): ''' :param n: the size of the fft comapres the python nudft1_d results to the fortran run generate fourier points in a constant way :return: ''' fourier_pts = np.random.uniform(-np.pi, np.pi, n) sig_f = np.random.uniform(-1, 1, n) + 1j * np.zeros(n) py_nufft_obj = py_nufft.factory('nufft') fortran_results = py_nufft_obj.adjoint1d(sig_f, fourier_pts)[0] python_results = nudft.anudft1(sig_f, fourier_pts, n) self.assertTrue(np.sum( np.square(np.abs(python_results - fortran_results))) / n < diff)
def test_nudft_gpu_adjoint_3d(self, n=65, diff = 1e-8): fourier_pts_x = np.random.uniform(-np.pi, np.pi, n) fourier_pts_y = np.random.uniform(-np.pi, np.pi, n) fourier_pts_z = np.random.uniform(-np.pi, np.pi, n) fourier_pts = np.array( zip(fourier_pts_x, fourier_pts_y, fourier_pts_z)) vol_f = np.random.uniform(-np.pi, np.pi, n) python_results = nudft.anudft3(vol_f, fourier_pts, n) py_nufft_obj = py_nufft.factory("gpu_dft") res = py_nufft_obj.adjoint3d(vol_f, fourier_pts)[0] self.assertTrue( np.abs(np.sum(np.square(python_results - res))) / (n*n*n) < diff)
def test_nudft_gpu_adjoint_1d(self, n=2049, diff=1e-8): """ :param n: the size of the fft comapres the python nudft3_d results to the fortran run generate fourier points in a constant way :return: """ sig_f = np.random.uniform(-np.pi, np.pi, n) fourier_pts = np.random.uniform(-np.pi, np.pi, n) py_nufft_obj = py_nufft.factory("gpu_dft") res = py_nufft_obj.adjoint1d(fourier_pts, sig_f)[0] self.assertTrue(np.abs(np.sum( np.square(nudft.anudft1(fourier_pts, sig_f, n) - res))) / n < diff)
def test_nufft_forward_2d(self, n=34, diff=1e-8): ''' :param n: the size of the fft comapres the python nudft2_d results to the fortran run generate fourier points in a constant way :return: ''' fourier_pts_x = np.random.uniform(-np.pi, np.pi, n) fourier_pts_y = np.random.uniform(-np.pi, np.pi, n) fourier_pts = np.array(zip(fourier_pts_x, fourier_pts_y)).reshape([2, n], order='F') im = np.random.uniform(-1, 1, n * n).reshape(n, n) py_nufft_obj = py_nufft.factory('nufft') fortran_results = py_nufft_obj.forward2d(im, fourier_pts)[0] python_results = nudft.nudft2(im, fourier_pts) self.assertTrue( np.sum(np.square(np.abs(python_results - fortran_results))) / ( n * n) < diff)
def test_nudft_gpu_adjoint_2d(self, n=65, diff=1e-8): """ :param n: the size of the fft comapres the python nudft3_d results to the fortran run generate fourier points in a constant way :return: """ fourier_pts_x = np.random.uniform(-np.pi, np.pi, n) fourier_pts_y = np.random.uniform(-np.pi, np.pi, n) fourier_pts = np.array(zip(fourier_pts_x, fourier_pts_y)) im_f = np.random.uniform(-np.pi, np.pi, n) python_results = nudft.anudft2(im_f, fourier_pts, n) py_nufft_obj = py_nufft.factory("gpu_dft") res = py_nufft_obj.adjoint2d(im_f, fourier_pts)[0] self.assertTrue(np.abs(np.sum(np.square(python_results - res))) / (n*n) < diff)
def test_nudft_gpu_forward_3d(self, n=65, diff = 1e-8): fourier_pts_x = np.random.uniform(-np.pi, np.pi, n) fourier_pts_y = np.random.uniform(-np.pi, np.pi, n) fourier_pts_z = np.random.uniform(-np.pi, np.pi, n) fourier_pts = np.array( zip(fourier_pts_x, fourier_pts_y, fourier_pts_z)).reshape([3, n], order='F') vol = np.random.uniform(-np.pi, np.pi, n * n * n).reshape([n, n, n]) python_results = nudft.nudft3(vol, fourier_pts) py_nufft_obj = py_nufft.factory("gpu_dft") res = py_nufft_obj.forward3d(vol, fourier_pts)[0] print "+++++++++" print res print "+++++++++" print python_results print "+++++++++" self.assertTrue( np.abs(np.sum(np.square(python_results - res))) / n < diff)