Comments (8)
Hi Francis,
Yes, numpy and mpi4py-fft should give the same result. But you are using rfftn/irfftn for mpi4py-fft and fftn/ifftn for numpy. Normally that's not a problem, but you have to do it correctly, and for that you have to know what is going on under the hood. When a real array X is transformed (with rfftn) you get a complex array Y with Hermitian symmetry. See, e.g., here. For this transformed array item Y[N/2+1] will be real. Problem is that when you multiply this same array with k1j, then Y[N/2+1] will become complex and not real. And when you do irfftn(1jk*rfftn(x)), then irfftn assumes that it is transforming a complex array with Hermitian symmetry and assumes item N/2+1 is real. Since it is actually now complex it is treated as zero and that is why you get a difference between irfftn and ifftn (not mpi4py-fft and numpy). If you do numpy with rfftn/irfftn as well, then you should get the same results.
from mpi4py-fft.
Hello Mikael,
Ah, that makes sense. Thanks! I can confirm that when I use rfftn in numpy I do get the same result.
One last question, with this issue I hope, does that mean to maintain the symmetry we should multiply the last entry by k1 instead of k1j, to keep it real?
from mpi4py-fft.
No. You should set it to 0, but only for N even. For N odd you don't have to do anything. Takes a while to explain, but you could search for Fourier interpolator. Trefethen's 'spectral methods for matlab' has a decent explanation and so does most textbooks on spectral methods.
from mpi4py-fft.
Thanks. I tried playing with that and didn't have success but will keep at it. I know Trefethen's book quite well from my doctoral days but clearly need to brush up on it. Thanks for the reference.
On a related note, when I comment out the PFFT line and uncomment this, which I think uses the fftn and ifftn, I still get the same results. I still have that the transformed arrays are not square. How should I change the syntax to get the c2c transforms?
`r2c = PFFT(MPI.COMM_WORLD, N, axes=(0, 1), dtype=np.float,
grid=(-1,), transforms={(0,1): (rfftn, irfftn)} )`
from mpi4py-fft.
Use 'dtype=np.complex'
from mpi4py-fft.
That makes sense, and I did try that but then it seems I have to define the wavenmbers differently. I guess the get_local_wavenumbermesh assumes it's going to be using r2c. Does that make sense?
Traceback (most recent call last): File "example2.py", line 124, in <module> main() File "example2.py", line 61, in main K = get_local_wavenumbermesh(r2c, L) File "example2.py", line 33, in get_local_wavenumbermesh return [np.broadcast_to(k, FFT.shape(True)) for k in Ks] File "example2.py", line 33, in <listcomp> return [np.broadcast_to(k, FFT.shape(True)) for k in Ks] File "<__array_function__ internals>", line 5, in broadcast_to File "/home/fpoulin/software/anaconda3/envs/mpi4py-fft/lib/python3.8/site-packages/numpy/lib/stride_tricks.py", line 182, in broadcast_to return _broadcast_to(array, shape, subok=subok, readonly=True) File "/home/fpoulin/software/anaconda3/envs/mpi4py-fft/lib/python3.8/site-packages/numpy/lib/stride_tricks.py", line 125, in _broadcast_to it = np.nditer( ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (1,5) and requested shape (8,8)
from mpi4py-fft.
Yes, that is correct. Use fftfreq for both directions.
from mpi4py-fft.
Thanks! I simply changed the rfft to fft and I can confirm that it does yield the correct answer.
I will try and get the rfft working as that is the better way to go but I am happy to say that I am getting agreement.
I will close this issue.
From,
k.append(np.fft.rfftfreq(N[-1], 1./N[-1]).astype(int))
to,
k.append(np.fft.fftfreq(N[-1], 1./N[-1]).astype(int))
from mpi4py-fft.
Related Issues (20)
- switching to real to real transforms HOT 6
- ttest2D_cr0.h5 fails trying to append to file which does not yet exist HOT 2
- fftw_threads symbols HOT 3
- Use mpi4py-fft with CuPy arrays? HOT 24
- RuntimeError: Failure creating FFTW plan HOT 7
- install FFTW with conda
- How to apply to already distributed array? HOT 3
- incorrect link on pypi
- AssertionError on dtype mismatch in pencil.py for small arrays
- AssertionError for number of processors equals array dimension
- setup.py and docs still reference bitbucket repo HOT 1
- How to load array from the disk, such as in the format of '.npy' ? HOT 1
- mpi4py-fft with Apple Silicon M1/M2? HOT 4
- using PFFT is causing error, not sure why! HOT 3
- How to redistribute an already declared array? HOT 1
- How to fill a distributed array with function values? HOT 2
- pip installation error HOT 9
- Example reproduction error HOT 1
- doing multiple transforms together HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mpi4py-fft.