Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/FftSharp.Tests/VsNumpy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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()
{
Expand Down
21 changes: 15 additions & 6 deletions src/FftSharp/FftOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,21 @@ public static void RFFT_WithoutChecks(Span<System.Numerics.Complex> destination,
{
System.Numerics.Complex[] temp = ArrayPool<System.Numerics.Complex>.Shared.Rent(input.Length);

Span<System.Numerics.Complex> buffer = temp.AsSpan(0, input.Length);

FFT_WithoutChecks(buffer);
buffer.Slice(0, destination.Length).CopyTo(destination);

ArrayPool<System.Numerics.Complex>.Shared.Return(temp);
try
{
Span<System.Numerics.Complex> 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<System.Numerics.Complex>.Shared.Return(temp);
}
}

/// <summary>
Expand Down