-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Add initial implementation of resampy library #15341
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
base: main
Are you sure you want to change the base?
Conversation
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
| @@ -0,0 +1,3 @@ | |||
| version = "0.4.*" | |||
| upstream_repository = "https://github.com/bmcfee/resampy" | |||
| requires = ["numba", "numpy"] | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numpyshipspy.typedfile since version1.20numbais not needed here, we can get rid of it (see below)
| requires = ["numba", "numpy"] | |
| # Requires a version of numpy with a `py.typed` file | |
| requires = ["numpy>=1.20"] |
| short_version: str | ||
| version: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add Final here:
| short_version: str | |
| version: str | |
| from typing import Final | |
| short_version: Final[str] | |
| version: Final[str] |
| @@ -0,0 +1,2 @@ | |||
| from . import filters as filters | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also reflect the __version__ since it is also imported:
| from . import filters as filters | |
| from .version import version as __version__ | |
| from . import filters as filters |
| FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]] = {} | ||
|
|
||
| # List of filter functions available | ||
| FILTER_FUNCTIONS: list[str] = ["sinc_window"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to specify a default value for variables:
| FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]] = {} | |
| # List of filter functions available | |
| FILTER_FUNCTIONS: list[str] = ["sinc_window"] | |
| FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]] | |
| # List of filter functions available | |
| FILTER_FUNCTIONS: list[str] |
| import numba | ||
| import numpy as np | ||
| from numba import guvectorize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import numba | |
| import numpy as np | |
| from numba import guvectorize | |
| import numpy as np |
| @guvectorize( | ||
| ( | ||
| numba.float32[:, :, :], | ||
| numba.float32[:, :], | ||
| numba.float32[:], | ||
| numba.float32[:], | ||
| numba.int32, | ||
| numba.float32, | ||
| numba.float32[:, :], | ||
| ), | ||
| "(n),(m),(p),(p),(),()->(m)", | ||
| nopython=True, | ||
| ) | ||
| def resample_f_p( | ||
| x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| num_table: int, | ||
| scale: float, | ||
| y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| ) -> None: ... | ||
| @guvectorize( | ||
| ( | ||
| numba.float32[:, :, :], | ||
| numba.float32[:, :], | ||
| numba.float32[:], | ||
| numba.float32[:], | ||
| numba.int32, | ||
| numba.float32, | ||
| numba.float32[:, :], | ||
| ), | ||
| "(n),(m),(p),(p),(),()->(m)", | ||
| nopython=True, | ||
| ) | ||
| def resample_f_s( | ||
| x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| num_table: int, | ||
| scale: float, | ||
| y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | ||
| ) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a decorator does not affect the function signature, there is no need to use it. In cases where the runtime signature differs from the stub signature, we can either ignore it or add it manually as needed.
| @guvectorize( | |
| ( | |
| numba.float32[:, :, :], | |
| numba.float32[:, :], | |
| numba.float32[:], | |
| numba.float32[:], | |
| numba.int32, | |
| numba.float32, | |
| numba.float32[:, :], | |
| ), | |
| "(n),(m),(p),(p),(),()->(m)", | |
| nopython=True, | |
| ) | |
| def resample_f_p( | |
| x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| num_table: int, | |
| scale: float, | |
| y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| ) -> None: ... | |
| @guvectorize( | |
| ( | |
| numba.float32[:, :, :], | |
| numba.float32[:, :], | |
| numba.float32[:], | |
| numba.float32[:], | |
| numba.int32, | |
| numba.float32, | |
| numba.float32[:, :], | |
| ), | |
| "(n),(m),(p),(p),(),()->(m)", | |
| nopython=True, | |
| ) | |
| def resample_f_s( | |
| x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| num_table: int, | |
| scale: float, | |
| y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| ) -> None: ... | |
| def resample_f_p( | |
| x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| num_table: int, | |
| scale: float, | |
| y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| ) -> None: ... | |
| def resample_f_s( | |
| x: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| t_out: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| interp_win: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| interp_delta: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| num_table: int, | |
| scale: float, | |
| y: np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], | |
| ) -> None: ... |
Introduce core functionality and metadata for the resampy library, including initial stubs for resampling methods and filter functions. Update metadata to specify dependencies.
See also #15338.