Hi,
I was wondering why torch rfft doesn’t match the one of scipy:
import torch
import numpy as np

from scipy.fftpack import fft


@torch.no_grad()
def _fix_shape(x, n, axis):
    """ Internal auxiliary function for _raw_fft, _raw_fftnd."""
    s = list(x.shape)

    index = [slice(None)] * len(s)
    index[axis] = slice(0, s[axis])
    s[axis] = n
    z = torch.zeros(s, dtype=x.dtype, device=x.device)
    z[tuple(index)] = x
    return z


N_FFT = 512
cuda = torch.rand(1, 44000, device='cuda:0')
tensor = cuda.cpu()
numpy = tensor.clone().numpy()
cuda_fft = torch.rfft(cuda, signal_ndim=1, onesided=False)[0, :, 0]

tensor_fft = torch.rfft(tensor, signal_ndim=1, onesided=False)[0, :, 0].numpy()
numpy_fft = np.real(fft(numpy, axis=1, n=None))[0]
print(f'Tensor type:{tensor_fft.dtype}\n'
      f'Numpy array type: {numpy_fft.dtype}'
      )
print(f'CPU-CUDA: {np.abs(tensor_fft - cuda_fft).sum()}')
print(f'CPU-NP: {np.abs(tensor_fft - numpy_fft).sum()}')
print(f'CUDA-NP: {np.abs(cuda_fft - numpy_fft).sum()}')

The error is not extremely big but big enough not to allow to use them indifferently.
Tensor type:float32
Numpy array type: float32
0.32703477144241333