FFT output dtype mismatches with NumPy's
See original GitHub issueThis relates to the test failures we saw in #3587.
Reproducer:
import numpy as np
import cupy as cp
dtypes = [np.int8, np.int16, np.int32, np.int64,
np.uint8, np.uint16, np.uint32, np.uint64,
np.float16, np.float32, np.float64,
np.complex64, np.complex128]
for dtype in dtypes:
a_np = np.random.random(100).astype(dtype)
a_cp = cp.asarray(a_np)
b_np = np.fft.fft(a_np)
b_cp = cp.fft.fft(a_cp)
if b_np.dtype != b_cp.dtype:
print(f"in_dtype {a_np.dtype}: NumPy out_dtype {b_np.dtype}; CuPy out_dtype {b_cp.dtype}")
Output:
in_dtype float16: NumPy out_dtype complex128; CuPy out_dtype complex64
in_dtype float32: NumPy out_dtype complex128; CuPy out_dtype complex64
in_dtype complex64: NumPy out_dtype complex128; CuPy out_dtype complex64
I think CuPy is actually making sense and I don’t understand:
- why pocketfft chose to promote the dtype
- why our tests did not discover this
We’ll also need to discuss if we want to enforce a strict compliance for this issue, as our current implementation clearly has performance advantage…
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
BUG: FFT does not give the result shown in the manual. I am ...
My input data is below - it represents a 1kHz sign wave recorded at 44100 samples per second. When I perform an FFT...
Read more >skcuda.fft not the same as numpy.fft.rfft? - Stack Overflow
The output of an FFT has an error that is relative to the magnitude of the input values. Each output element is computed...
Read more >numpy.fft.fft — NumPy v1.24 Manual
This function computes the one-dimensional n-point discrete Fourier Transform (DFT) with the efficient Fast Fourier Transform (FFT) algorithm [CT]. Parameters:.
Read more >ONNX and FFT — Python Runtime for ONNX
if a.dtype in (numpy.complex64, numpy.complex128): dtype = numpy.float64 if ... try: fft2d_cus = fft2d(rnd, fft_length) except Exception as e: print(e) ...
Read more >NumPy User Guide
ndarray.dtype an object describing the type of the elements in the array. ... When you print an array, NumPy displays it in a...
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 Free
Top 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
I am being stupid again — I can close this myself 😂
Sorry, this is largely due to my stupidity — I should have recalled it before filing an issue. This behavior is well documented here: https://docs.cupy.dev/en/stable/reference/fft.html#code-compatibility-features
It’s been the case since the beginning of CuPy (#477), and in the tests we do work around this issue. @kmaehashi Could you close this please? Sorry for the noise…😞