incorrect FFT results for Fortran-order arrays?
See original GitHub issue- Conditions (from
python -c 'import cupy; cupy.show_config()'
)
Tested in two environments with different CuPy versions:
CuPy Version : 4.4.1
CUDA Root : /usr/local/cuda
CUDA Build Version : 9010
CUDA Driver Version : 9010
CUDA Runtime Version : 9010
cuDNN Build Version : 7102
cuDNN Version : 7102
NCCL Build Version : 2115
and (this CuPy is built from the latest master branch)
CuPy Version : 6.0.0b1
CUDA Root : /usr/local/cuda
CUDA Build Version : 9010
CUDA Driver Version : 9010
CUDA Runtime Version : 9010
cuDNN Build Version : None
cuDNN Version : None
NCCL Build Version : None
- Code to reproduce
import numpy as np
import cupy as cp
AXES=[(0,), (1,), (2,), (0,1), (1,2), (0,2), (0,1,2)]
a_np = np.random.random((3,4,5))+1j*np.random.random((3,4,5))
print("In C order:")
a_np = np.ascontiguousarray(a_np)
a_cp = cp.asarray(a_np)
a_cp = cp.ascontiguousarray(a_cp)
assert np.allclose(cp.asnumpy(a_cp), a_np)
for axes in AXES:
result_np = np.fft.fftn(a_np, axes=axes)
result_cp = cp.fft.fftn(a_cp, axes=axes)
print(axes, ":", np.allclose(cp.asnumpy(result_cp), result_np))
print("\nIn F order:")
a_np = np.asfortranarray(a_np)
a_cp = cp.asarray(a_np)
a_cp = cp.asfortranarray(a_cp)
assert np.allclose(cp.asnumpy(a_cp), a_np)
for axes in AXES:
result_np = np.fft.fftn(a_np, axes=axes)
result_cp = cp.fft.fftn(a_cp, axes=axes)
print(axes, ":", np.allclose(cp.asnumpy(result_cp), result_np))
- Error messages, stack traces, or logs
The outputs from both environments are identical:
In C order:
(0,) : True
(1,) : True
(2,) : True
(0, 1) : True
(1, 2) : True
(0, 2) : True
(0, 1, 2) : True
In F order:
(0,) : False
(1,) : True
(2,) : False
(0, 1) : True
(1, 2) : False
(0, 2) : False
(0, 1, 2) : True
But it’s expected to be True
for all of the axes choices. It seems to me the bug is not introduced by the recent changes in adding support for cuFFT plans (#1669, #1745, #1746) but by something much older. For now I have not yet tracked down the problem, will update here if I find it. I hope I didn’t do something stupid in the test…
Thanks.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (7 by maintainers)
Top Results From Across the Web
FFT2 incorrect results for Fortran ordered 3D data #12460
FFT2 produces incorrect results for Fortran ordered 3D data Example ... incorrect FFT results for Fortran-order arrays? cupy/cupy#1934.
Read more >Python numpy.fft changes strides - Stack Overflow
One of the two arrays was a newly generated boolean grid (C order) and the other one (FORTRAN order) came from the 3D...
Read more >Tutorial - FFTW
The first thing we do is to create a plan, which is an object that contains all the data that FFTW needs to...
Read more >FFT not working on DSPIC33EP512MU810
Sampling is running well data stored in arrays, rounding done. So how to solve this problem? // code snippets from my software
Read more >numpy.asfortranarray — NumPy v1.24 Manual
Return an array (ndim >= 1) laid out in Fortran order in memory. ... Reference object to allow the creation of arrays which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@leofang I’m very sorry that I did not write that my second comment is executed in the
master
-branch environment. I edited my comment.Okay, that makes sense. conda’s default channel replaces numpy’s fftpack with
mklfft
which had a bug with Fortran-ordered input that was only recently fixed: https://github.com/IntelPython/mkl_fft/pull/30 numpy recently expanded their tests to check for this as well: https://github.com/numpy/numpy/pull/12702