Skip to content

Conversation

ev-br
Copy link
Member

@ev-br ev-br commented Dec 20, 2024

Model the structure on scipy.ndimage:

  • add _delegators.py with *_signature functions
  • add _signal_api.py to collect "bare" imports from _private modules
  • add _support_alternative_backends.py to decorate "bare" functions
  • in __init__.py, import decorated names from _support_alternative_backends.py

This is still WIP for: no longer WIP

  • only decorate functions, exclude lti classes, BadCoefficients etc
  • double-check the namespace content for missing / extra items
  • double-check, exclude the .windows subpackage
  • make sure python dev.py -b all works without errors

model the structure on scipy.ndimage:

- add `_delegators.py` with *_signature functions
- add _signal_api.py to collect "bare" imports from _private modules
- add _support_alternative_backends.py to decorate "bare" functions
- in __init__.py, import decorated names from _support_alternative_backends.py
@ev-br ev-br added scipy.signal array types Items related to array API support and input array validation (see gh-18286) labels Dec 20, 2024
@ev-br ev-br requested review from larsoner and ilayn as code owners December 20, 2024 09:54
@github-actions github-actions bot added Meson Items related to the introduction of Meson as the new build system for SciPy enhancement A new feature or improvement labels Dec 20, 2024
@ev-br ev-br changed the title WIP/ENH: signal: add CuPy/JAX delegation to scipy.signal ENH: signal: add CuPy/JAX delegation to scipy.signal Dec 20, 2024
@ev-br
Copy link
Member Author

ev-br commented Dec 20, 2024

This is ready from my side, now that the delegation machinery skips classes, mypy noise is suppressed, and dev.py -s signal -b all seems to be working.

This PR, strictly speaking, does not bring anything new. It only streamlines the foundation for further array api work in scipy.signal. So it'd be most convenient to land this before other ones (gh-22122, gh-22008, gh-21783 will need to be rebased after this one lands).

EDIT: this PR actually does bring a blanket delegation to CuPy for all of scipy.signal namespace:

In [7]: import cupy as cp

In [8]: from scipy.signal import upfirdn
   ...: upfirdn(cp.asarray([1, 1, 1]), cp.asarray([1, 1, 1])).__class__
Out[8]: cupy.ndarray

In [9]: from scipy.signal import upfirdn
   ...: upfirdn([1, 1, 1], [1, 1, 1]).__class__
Out[9]: numpy.ndarray

the .windows namespace is separate (gh-21783), support for other backends is incomplete and will be taken care of in follow-up PRs. Support for lti/dlti and other classes will also be worked on in a follow-up. But all functions from scipy.signal delegate to their cupyx.scipy.signal analogs.

Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! I'll run GPU tests before merging

Copy link
Member

@lucascolley lucascolley left a comment

Choose a reason for hiding this comment

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

pixi run test-cuda -s signal is all green, thanks Evgeni!

@lucascolley lucascolley merged commit 7f7f04c into scipy:main Dec 30, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
array types Items related to array API support and input array validation (see gh-18286) enhancement A new feature or improvement Meson Items related to the introduction of Meson as the new build system for SciPy scipy.signal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants