Skip to content

Only check whether fft is power of two when not using rustfft-backend#19

Merged
wizenink merged 2 commits intowizenink:masterfrom
danny900714:bugfix/fft-size-check
Dec 21, 2025
Merged

Only check whether fft is power of two when not using rustfft-backend#19
wizenink merged 2 commits intowizenink:masterfrom
danny900714:bugfix/fft-size-check

Conversation

@danny900714
Copy link
Contributor

Resolves #18

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @danny900714, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the flexibility of the StftConfig by making the fft_size validation conditional. Specifically, the requirement for fft_size to be a power of two is now bypassed when the rustfft-backend feature is enabled, accommodating backends that can handle arbitrary FFT sizes. This change improves compatibility and usability for different backend implementations.

Highlights

  • Conditional FFT Size Validation: The StftConfig constructor now only enforces that the fft_size must be a power of two when the rustfft-backend feature is not enabled. This change allows for non-power-of-two FFT sizes when utilizing the rustfft-backend.
  • Test Suite Adaptation: Existing unit tests that specifically validate the power-of-two constraint for fft_size have been updated to be conditionally compiled. These tests will now only run when the rustfft-backend feature is not active, aligning with the new conditional validation logic in the core library.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly updates the FFT size validation to be conditional based on the rustfft-backend feature. The power-of-two check for fft_size is now correctly skipped when rustfft-backend is enabled, as that backend supports non-power-of-two sizes. The associated tests have also been updated with the appropriate cfg attribute to run only when this check is active. The changes are logical and well-implemented. I have one suggestion to improve the readability of the conditional logic in src/lib.rs.

reconstruction_mode: ReconstructionMode,
) -> Result<Self, ConfigError<T>> {
if fft_size == 0 || !fft_size.is_power_of_two() {
if fft_size == 0 || !(cfg!(feature = "rustfft-backend") || fft_size.is_power_of_two()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While logically correct, this condition can be made more readable. By applying De Morgan's law, you can express the logic without negating a grouped expression, which is often easier to reason about. The rewritten form !cfg!(feature = "rustfft-backend") && !fft_size.is_power_of_two() makes it immediately clear that the power-of-two constraint applies only when not using the rustfft-backend.

Suggested change
if fft_size == 0 || !(cfg!(feature = "rustfft-backend") || fft_size.is_power_of_two()) {
if fft_size == 0 || !cfg!(feature = "rustfft-backend") && !fft_size.is_power_of_two() {

@danny900714 danny900714 changed the title Only check fft is power of two when not using rustfft-backend Only check whether fft is power of two when not using rustfft-backend Dec 21, 2025
@wizenink wizenink added the bug Something isn't working label Dec 21, 2025
@wizenink wizenink added this to the 0.5.2 milestone Dec 21, 2025
@wizenink
Copy link
Owner

wizenink commented Dec 21, 2025

Added a few tests for checking invalid fft size on other backends. Other than that, this seems perfect. Thank you very much for this contribution. This should be released in the next version, along with your other issue :)

@wizenink wizenink merged commit 184c8f5 into wizenink:master Dec 21, 2025
3 checks passed
@wizenink wizenink modified the milestones: 0.5.2, 0.5.1 Dec 21, 2025
@danny900714 danny900714 deleted the bugfix/fft-size-check branch December 21, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Building StftConfig returns ConfigError::InvalidFftSize when fft size is not power of two

2 participants

Comments