Torch::fft::rfft and fftw library disagree

Torch implementation

torch::fft::rfft(tensor).abs().pow(2.0);

Rough FFTW implementaton

fftwf_plan plan = fftwf_plan_dft_r2c_2d(N0, N1, input, output, FFTW_ESTIMATE);

for (int i = 0; i < N0; ++i) {
        for (int j = 0; j < N1 / 2 + 1; ++j) {
            float real_part = output[i * (N1 / 2 + 1) + j][0];
            float imag_part = output[i * (N1 / 2 + 1) + j][1];
            power.index({ i,j }) = real_part * real_part + imag_part * imag_part;
        }
    }

return power