8000 TST/MAINT: signal.symiirorder2: r, omega, precision are floats; use default dtypes by crusaderky · Pull Request #22783 · scipy/scipy · GitHub
[go: up one dir, main page]

Skip to content

TST/MAINT: signal.symiirorder2: r, omega, precision are floats; use default dtypes #22783

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

Merged
merged 3 commits into from
Apr 3, 2025

Conversation

crusaderky
Copy link
Contributor
@crusaderky crusaderky commented Apr 2, 2025
  • The parameters r, omega, and precision of scipy.signal.symiirorder2 are floats, as per the documentation.
    This PR undoes an improper wrapping in xp.asarray in the test.
    This fixes a regression vs. array-api-strict git tip, which has started crashing on __mul__ and other ops vs. np.float64 types, on the line a2 = 2 * r * np.cos(omega) because r was an array_api_strict.Array.
  • When the torch default dtype is float32, symiirorder1 and symiirorder2 now return float32 when fed with int inputs, accordingly to the general xp_promote policy.
  • Re-enabled several tests on CuPy
  • Cosmetic enhancement of the code.

@github-actions github-actions bot added scipy.signal maintenance Items related to regular maintenance tasks labels Apr 2, 2025
@lucascolley lucascolley changed the title TST: signal: symiirorder2 r, omega, precision are floats TST: signal.symiirorder2: r, omega, precision are floats Apr 2, 2025
rsq = r * r
a2 = 2 * r * np.cos(omega)
a2 = 2 * r * math.cos(omega)
Copy link
Member

Choose a reason for hiding this comment

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

Despite what the docs say, I wouldn't be surprised if historic usage allows 0D arrays or np.float64s. This part of the codebase is straight from the multipack era. Let's see if tests complain.

@crusaderky crusaderky changed the title TST: signal.symiirorder2: r, omega, precision are floats TST/MAINT: signal: .symiirorder2: r, omega, precision are floats; use default dtypes Apr 2, 2025
@crusaderky
Copy link
Contributor Author

I've slightly extended the scope of this PR; see updated initial post

@crusaderky crusaderky changed the title TST/MAINT: signal: .symiirorder2: r, omega, precision are floats; use default dtypes TST/MAINT: signal.symiirorder2: r, omega, precision are floats; use default dtypes Apr 2, 2025
@pytest.mark.parametrize('dtyp', ['float32', 'float64'])
def test_symiir2_values(self, dtyp, xp):
rng = np.random.RandomState(1234)
s = rng.uniform(size=16).astype(dtyp)
s = xp.asarray(s)
dtyp = getattr(xp, dtyp)

# cupy returns f64 for f32 inputs
Copy link
Member

Choose a reason for hiding this comment

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

This one is a bit funny: I'm pretty sure CuPy's version was made to follow SciPy's, and now we're adjusting SciPy's to match CuPy's :-).

Copy link
Member
@ev-br ev-br left a comment

Choose a reason for hiding this comment

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

LGTM. Changes look reasonable, the resulting code is cleaner, and the test coverage has expanded. Looks like wins all around. Thanks Guido!

@ev-br ev-br merged commit 25ca572 into scipy:main Apr 3, 2025
40 of 41 checks passed
@ev-br ev-br added this to the 1.16.0 milestone Apr 3, 2025
@crusaderky crusaderky deleted the symiirorder2 branch April 3, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Items related to regular maintenance tasks scipy.signal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0