diff --git a/src/FftSharp.Tests/VsNumpy.cs b/src/FftSharp.Tests/VsNumpy.cs index 73c940c..fb139e8 100644 --- a/src/FftSharp.Tests/VsNumpy.cs +++ b/src/FftSharp.Tests/VsNumpy.cs @@ -58,7 +58,7 @@ public void Test_VsNumpy_Fft_SystemNumericsComplex() } [Test] - public void Test_VsNumpy_Rfft() + public void Test_VsNumpy_ForwardRealDoubles() { System.Numerics.Complex[] rfft = FftSharp.FFT.ForwardReal(values); System.Numerics.Complex[] numpyRfft = LoadData.Complex("fftReal.txt"); @@ -72,6 +72,22 @@ public void Test_VsNumpy_Rfft() } } + [Test] + public void Test_VsNumpy_ForwardRealComplex() + { + System.Numerics.Complex[] complexValues = values.Select(value => new System.Numerics.Complex(real: value, imaginary: 0)).ToArray(); + System.Numerics.Complex[] rfft = FftSharp.FFT.ForwardReal(complexValues); + System.Numerics.Complex[] numpyRfft = LoadData.Complex("fftReal.txt"); + + Assert.AreEqual(numpyRfft.Length, rfft.Length); + + for (int i = 0; i < rfft.Length; i++) + { + Assert.AreEqual(numpyRfft[i].Real, rfft[i].Real, 1e-10); + Assert.AreEqual(numpyRfft[i].Imaginary, rfft[i].Imaginary, 1e-10); + } + } + [Test] public void Test_VsNumpy_FftMag() { diff --git a/src/FftSharp/FftOperations.cs b/src/FftSharp/FftOperations.cs index 3c5ee1c..676b469 100644 --- a/src/FftSharp/FftOperations.cs +++ b/src/FftSharp/FftOperations.cs @@ -92,12 +92,21 @@ public static void RFFT_WithoutChecks(Span destination, { System.Numerics.Complex[] temp = ArrayPool.Shared.Rent(input.Length); - Span buffer = temp.AsSpan(0, input.Length); - - FFT_WithoutChecks(buffer); - buffer.Slice(0, destination.Length).CopyTo(destination); - - ArrayPool.Shared.Return(temp); + try + { + Span buffer = temp.AsSpan(0, input.Length); + input.CopyTo(buffer); + FFT.Forward(buffer); + buffer.Slice(0, destination.Length).CopyTo(destination); + } + catch (Exception ex) + { + throw new Exception("Could not calculate RFFT", ex); + } + finally + { + ArrayPool.Shared.Return(temp); + } } ///