Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FftOperations.RFFT_WithoutChecks doesn't use input #73

Closed
FrankHileman opened this issue Aug 9, 2023 · 2 comments · Fixed by #78
Closed

FftOperations.RFFT_WithoutChecks doesn't use input #73

FrankHileman opened this issue Aug 9, 2023 · 2 comments · Fixed by #78

Comments

@FrankHileman
Copy link

FrankHileman commented Aug 9, 2023

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.

@swharden
Copy link
Owner

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.

swharden added a commit that referenced this issue Aug 21, 2023
swharden added a commit that referenced this issue Aug 21, 2023
@swharden
Copy link
Owner

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 🚀

swharden added a commit that referenced this issue Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants