swharden/FftSharp

FftOperations.RFFT_WithoutChecks doesn't use input

Closed this issue · 2 comments

RFFT_WithoutChecks(Span<System.Numerics.Complex> destination, Span<System.Numerics.Complex> input) only uses the length of the input parameter, and not the data inside. The ForwardReal method calling this method apparently isn't tested.

I am curious about the ForwardReal methods. Are they supposed to be identical in output to the corresponding numpy methods? I ask because the the numpy.fft.rfft method states "If the input a contains an imaginary part, it is silently discarded." Secondly, the purpose of rfft seems to be increased efficiency, because it uses a different algorithm to avoid calculating the portion thrown out.

Hi @FrankHileman, thanks for raising this issue!

Let's take a closer look at the code under discussion:

/// <summary>
/// Calculate FFT of the input and return just the real component
/// Input array length must be a power of two. This length is NOT validated.
/// Running on an array with an invalid length may throw an invalid index exception.
/// </summary>
public static void RFFT_WithoutChecks(Span<System.Numerics.Complex> destination, Span<System.Numerics.Complex> input)
{
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);
}

The ForwardReal method calling this method apparently isn't tested.

Thanks for pointing that out! I'll start by adding this test now, then follow-up.

The ForwardReal method calling this method apparently isn't tested.

It turns out one overload was tested but not the other. I added testing to both and fixed the issue in #78. I'm merging now and will release an updated package in the next few hours.

Thanks again for reporting this! I'm happy it has been fixed 🚀