I'm doing N-body calculations using pyopencl and I need to have my data to be 1D array as input and as output of some kernel. So if I have 2D problem, I do something like this: 1D_arr=numpy.reshape(3D_arr,(LxLy)), where LxLy number of all particles. How to perform a fast fourier transform(fft) of 1D array(If it is possible!), which corresponds to fft of 3D array (and ifft after)? These 2 arrays are connected by reshape transformation in real space.
import numpy as np
from scipy.fftpack import fftn, fft
Lx = 10
Ly = 9
Lz = 1
L = Lx * Ly * Lz
Lspec = (2 * Lx - 1) * (2 * Ly - 1) * (2 * Lz - 1)
M1 = np.zeros(L).astype(np.float32)
for i in range(L):
M1[i] = np.random.random()
M3 = np.zeros((Lx, Ly, Lz))
for z in range(Lz):
for y in range(Ly):
for x in range(Lx):
i = x + Lx * y
M3[x, y, z] = i
M1[i] = i
print(M3[x,y,z], M1[i])
print("________________________")
FM3 = fftn(M3)
FM1 = fftn(M1)
for z in range(Lz):
for y in range(Ly):
for x in range(Lx):
i = x + Lx * y
i2 = y + Ly * x
print(FM3[x,y,z], FM1[i2])
I expect to see all ellements of FM1 and FM3 equal, but I don't know how to manage it.