Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl<T: Float + FromPrimitive + fmt::Debug> StftConfig<T> {
window: WindowType,
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() {

return Err(ConfigError::InvalidFftSize);
}
if hop_size == 0 || hop_size > fft_size {
Expand Down
2 changes: 2 additions & 0 deletions tests/config_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn test_config_invalid_ola() {
assert!(config.is_err())
}

#[cfg(not(feature = "rustfft-backend"))]
#[test]
#[allow(deprecated)]
fn test_config_invalid_fft_size() {
Expand Down Expand Up @@ -89,6 +90,7 @@ fn test_builder_missing_hop_size() {
assert!(config.is_err());
}

#[cfg(not(feature = "rustfft-backend"))]
#[test]
fn test_builder_invalid_fft_size() {
let config = StftConfig::<f32>::builder()
Expand Down