-
-
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?
Changes from all commits
0fb9f63
547b4c4
c910ff9
4f8383c
3b0c8f8
2801ee4
541d8e8
52b6063
a6ecd3c
d0405af
e1c3fd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| resampy.interpn.resample_f_p | ||
| resampy.interpn.resample_f_s | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| version = "0.4.*" | ||
| upstream_repository = "https://github.com/bmcfee/resampy" | ||
| # Requires a version of numpy with a `py.typed` file | ||
| requires = ["numpy>=1.20"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| from . import filters as filters | ||
hunterhogan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from .core import * | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||||||||||||||
| from collections.abc import Callable | ||||||||||||||||||||||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||||||||||||||||||||||
| from typing_extensions import TypeAlias, TypeVar | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| __all__ = ["resample", "resample_nu"] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| _FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]]) | ||||||||||||||||||||||||||||||||||||||||||
| _FilterType: TypeAlias = str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]] | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type passed to generic
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def resample( | ||||||||||||||||||||||||||||||||||||||||||
| x: _FloatArray, | ||||||||||||||||||||||||||||||||||||||||||
| sr_orig: float, | ||||||||||||||||||||||||||||||||||||||||||
| sr_new: float, | ||||||||||||||||||||||||||||||||||||||||||
| axis: int = -1, | ||||||||||||||||||||||||||||||||||||||||||
| filter: _FilterType = "kaiser_best", | ||||||||||||||||||||||||||||||||||||||||||
| parallel: bool = False, | ||||||||||||||||||||||||||||||||||||||||||
| **kwargs: Any, | ||||||||||||||||||||||||||||||||||||||||||
| ) -> _FloatArray: ... | ||||||||||||||||||||||||||||||||||||||||||
| def resample_nu( | ||||||||||||||||||||||||||||||||||||||||||
| x: _FloatArray, | ||||||||||||||||||||||||||||||||||||||||||
| sr_orig: float, | ||||||||||||||||||||||||||||||||||||||||||
| t_out: _FloatArray, | ||||||||||||||||||||||||||||||||||||||||||
| axis: int = -1, | ||||||||||||||||||||||||||||||||||||||||||
| filter: _FilterType = "kaiser_best", | ||||||||||||||||||||||||||||||||||||||||||
| parallel: bool = False, | ||||||||||||||||||||||||||||||||||||||||||
| **kwargs: Any, | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typeshed expects that
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| ) -> _FloatArray: ... | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from collections.abc import Callable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __all__ = ["get_filter", "clear_cache", "sinc_window"] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Dictionary to cache loaded filters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FILTER_CACHE: dict[str, tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # List of filter functions available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FILTER_FUNCTIONS: list[str] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def sinc_window( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| num_zeros: int = 64, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| precision: int = 9, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window: Callable[..., np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]]] | None = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rolloff: float = 0.945, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_filter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name_or_function: str | Callable[..., tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| **kwargs: Any, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def load_filter(filter_name: str) -> tuple[np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]], int, float]: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def clear_cache() -> None: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _resample_loop( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # JIT-compiled parallel version of _resample_loop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _resample_loop_p = ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # JIT-compiled sequential version of _resample_loop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _resample_loop_s = ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like internal API, so I suggest removing it, especially if you don't add types to it (this may also apply to
Suggested change
or if you are sure about types and consider it necessary, you can specify them something like this:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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: ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| from typing import Final | ||
|
|
||
| short_version: Final[str] | ||
| version: Final[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.
Could you add an explanatory comment to these entries?
I don’t claim to fully understand how this works in practice, but from what I’ve seen in the calls to these functions within the library, it seems the following: