question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
fiarabbitcommented, Jan 15, 2019

@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.

1reaction
grlee77commented, Jan 12, 2019

I think I spotted the inconsistency among our outputs. The reason is that I was using NumPy v1.14.2 from conda

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found