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

ENH: uarray support for scipy.signal #101

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
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 .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Build base Docker image
runs-on: ubuntu-latest
environment: scipy-dev
if: "github.repository_owner == 'scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
if: "github.repository_owner == 'rgommers' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
steps:
- name: Clone repository
uses: actions/checkout@v2
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ on:

jobs:
build:
name: Build Gitpod Docker image
name: Build Gitpod Docker image
runs-on: ubuntu-latest
environment: scipy-dev
if: "github.repository_owner == 'scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
if: "github.repository_owner == 'rgommers' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Lint Docker
- name: Lint Docker
uses: brpaz/[email protected]
with:
with:
dockerfile: ./tools/docker_dev/gitpod.Dockerfile
- name: Get refs
shell: bash
Expand Down Expand Up @@ -49,6 +49,6 @@ jobs:
cache-to: type=local,dest=/tmp/.buildx-cache
tags: |
scipy/scipy-gitpod:${{ steps.getrefs.outputs.date }}-${{ steps.getrefs.outputs.branch}}-${{ steps.getrefs.outputs.sha8 }}, scipy/scipy-gitpod:latest
- name: Image digest
- name: Image digest
# Return details of the image build: sha and shell
run: echo ${{ steps.docker_build.outputs.digest }}
4 changes: 2 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
jobs:
Python-38-dbg:
name: Python 3.8-dbg
if: "github.repository == 'scipy/scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
if: "github.repository == 'rgommers/scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:

test_numpy_main:
name: NumPy main
if: "github.repository == 'scipy/scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]') && !contains(github.ref, 'maintenance/') && !contains(github.base_ref, 'maintenance/')"
if: "github.repository == 'rgommers/scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]') && !contains(github.ref, 'maintenance/') && !contains(github.base_ref, 'maintenance/')"
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
jobs:
test_macos:
name: macOS Test Matrix
if: "github.repository == 'scipy/scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
if: "github.repository == 'rgommers/scipy' && !contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, '[skip github]')"
runs-on: macos-latest
strategy:
max-parallel: 3
Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ ignore_errors = True
[mypy-scipy._build_utils.tempita]
ignore_errors = True

[mypy-scipy.signal._api]
ignore_errors = True

[mypy-scipy.signal.tests.test_signaltools]
ignore_errors = True

Expand Down
6 changes: 2 additions & 4 deletions scipy/signal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,24 +307,22 @@

"""
from . import _sigtools, windows
from ._waveforms import *
from ._max_len_seq import max_len_seq
from ._upfirdn import upfirdn
from ._multimethods import *

from ._spline import ( # noqa: F401
cspline2d,
qspline2d,
sepfir2d,
symiirorder1,
symiirorder2,
)

from ._backend import *
from ._bsplines import *
from ._filter_design import *
from ._fir_filter_design import *
from ._ltisys import *
from ._lti_conversion import *
from ._signaltools import *
from ._savitzky_golay import savgol_coeffs, savgol_filter
from ._spectral_py import *
from ._wavelets import *
Expand Down
4 changes: 4 additions & 0 deletions scipy/signal/_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from ._upfirdn import upfirdn
from ._spline import sepfir2d
from ._signaltools import *
from ._waveforms import *
112 changes: 112 additions & 0 deletions scipy/signal/_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import scipy._lib.uarray as ua
from scipy.signal import _api
import numpy as np

__all__ = [
'register_backend', 'set_backend',
'set_global_backend', 'skip_backend'
]


class scalar_or_array:
"""
Special case argument that can be either a scalar or array
for __ua_convert__.
"""
pass


class tuple_str_array:
"""
Special case argument that can be either a string, tuple or array
for __ua_convert__.
"""
pass

Smit-create marked this conversation as resolved.
Show resolved Hide resolved

class _ScipySignalBackend:
__ua_domain__ = "numpy.scipy.signal"


@staticmethod
def __ua_function__(method, args, kwargs):
fn = getattr(_api, method.__name__, None)

if fn is None:
return NotImplemented

return fn(*args, **kwargs)


@ua.wrap_single_convertor
def __ua_convert__(value, dispatch_type, coerce):
if value is None:
return None

if dispatch_type is np.ndarray:
if not coerce and not isinstance(value, np.ndarray):
return NotImplemented

return np.asarray(value)

elif dispatch_type is np.dtype:
return np.dtype(value)

elif dispatch_type is scalar_or_array:
if np.isscalar(value):
return value
elif not coerce and not isinstance(value, np.ndarray):
return NotImplemented

return np.asarray(value)

elif dispatch_type is tuple_str_array:
if np.isscalar(value) or isinstance(value, (str, tuple)):
return value
elif not coerce and not isinstance(value, np.ndarray):
return NotImplemented

return np.asarray(value)

return value


_named_backends = {
'scipy': _ScipySignalBackend,
}


def _backend_from_arg(backend):
if isinstance(backend, str):
try:
backend = _named_backends[backend]
except KeyError as e:
raise ValueError('Unknown backend {}'.format(backend)) from e

if backend.__ua_domain__ != 'numpy.scipy.signal':
raise ValueError('Backend does not implement "numpy.scipy.signal"')

return backend


def set_global_backend(backend, coerce=False, only=False, try_last=False):
backend = _backend_from_arg(backend)
ua.set_global_backend(backend, coerce=coerce, only=only, try_last=try_last)


def register_backend(backend):
backend = _backend_from_arg(backend)
ua.register_backend(backend)


def set_backend(backend, coerce=True, only=False):
backend = _backend_from_arg(backend)
return ua.set_backend(backend, coerce=coerce, only=only)


def skip_backend(backend):
backend = _backend_from_arg(backend)
return ua.skip_backend(backend)


set_global_backend('scipy', coerce=True, try_last=True)
Loading