`overwrite_x=True` in cupyx.scipy.fft* doesn't do in-place transform for contiguous views
See original GitHub issueReproducer:
>>> import cupy as cp
>>> import cupyx.scipy.fftpack as cufft # can also use cupyx.scipy.fft
>>> a = cp.random.random((64, 128, 128))+1j*cp.random.random((64, 128, 128))
>>> a.data.ptr
140130136358912
>>> b = a[:16, ...] # create a C-contiguous view
>>> b.flags
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : False
>>> b.data.ptr # this is the same as a's
140130136358912
>>> b = cufft.fftn(b, overwrite_x=True)
>>> b.data.ptr # expected to unchanged
140130041987072
This behavior is not expected, since the FFT of a contiguous view should (and can) be done in-place. (BTW, it doesn’t matter whether a precomputed plan is used or not.) The underlying reason for the unexpected behavior is, curiously, the same for #3033:
This is due to an internal copy of the view that does not respected contiguity
This behavior is also against what we suggested in the doc (in a loose sense): https://github.com/cupy/cupy/blob/016e4ce34723d44a7af613a76acf0baba53b6d3d/docs/source/reference/fftpack.rst#L36 So we fix either the doc or the code. My preference is the latter, as it doesn’t seem to be hard at first glance.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Discrete Fourier transforms (cupyx.scipy.fft) — CuPy 11.4.0 ...
fft : when it is set to True , the input array x can (not will) be overwritten arbitrarily. For this reason, when...
Read more >CuPy Documentation - Read the Docs
Discrete Fourier Transforms (cupyx.scipy.fft. ... If we do copy the array in this situation, you can use cupy.array() with copy=True.
Read more >scipy.fft.fft — SciPy v1.9.3 Manual
This function computes the 1-D n-point discrete Fourier Transform (DFT) with the efficient Fast Fourier Transform (FFT) algorithm [1]. Parameters. xarray_like.
Read more >cuML API Reference — cuml 22.10.00 documentation
Transform X using one-hot encoding. Parameters. Xcudf.DataFrame or cupy.ndarray. The data to encode. Returns.
Read more >Understanding why scipy.fft.fft (fast Fourier transform) doesn't ...
If your signal is real, you should look at the real ... Scipy's fft does only give you the bin height, not their...
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
It’s probably a good practice to align undocumented details with SciPy. For the in-place FFT, however, I would recommend
if I were sure that
x[...] = x
has negligible cost in CuPy. The document ofscipy.fft.fft
saysAfter #3034, the topic I’m interested in is
x[...] = x
, oroverwrite_x
in SciPy.Ah, thanks for your thoughts @toslunar. The recommended usage
was introduced in #2035. I think the original discussion was in #1988. Given our internal implementation, I think this does lead to an in-place FFT when possible.
b[...] = b
is just an overkill for this case.But you’re right that in SciPy
overwrite_x=True
does not guarantee in-place transforms. I think in the past someone (me? don’t remember…) did raise this point and proposed adding a new flag likein_place=True
, but my (likely inexact) impression was that there was a strong pushback. If you think a relaxation for the alignment of function signatures is acceptable, I would definitely appreciate it 🙏