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.

FFT output dtype mismatches with NumPy's

See original GitHub issue

This 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:

  1. why pocketfft chose to promote the dtype
  2. 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…

cc: @emcastillo @grlee77 @peterbell10

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
leofangcommented, Jul 14, 2020

I am being stupid again — I can close this myself 😂

1reaction
leofangcommented, Jul 14, 2020

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

FFT functions of NumPy alway return numpy.ndarray which type is numpy.complex128 or numpy.float64. CuPy functions do not follow the behavior, they will return numpy.complex64 or numpy.float32 if the type of the input is numpy.float16, numpy.float32, or numpy.complex64.

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…😞

Read more comments on GitHub >

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

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