-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
resampy: more accurate and dynamic TypeVar #15926
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
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,17 @@ | ||||||||||||||||||||||||||||||||||
| from collections.abc import Callable | ||||||||||||||||||||||||||||||||||
| from typing import Any, TypeAlias, TypeVar | ||||||||||||||||||||||||||||||||||
| from typing import Any, TypeAlias, TypeVar, overload | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| __all__ = ["resample", "resample_nu"] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # np.floating[Any] because precision is not important | ||||||||||||||||||||||||||||||||||
| _FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating[Any]]]) | ||||||||||||||||||||||||||||||||||
| _Floating = TypeVar("_Floating", bound=np.floating[Any]) | ||||||||||||||||||||||||||||||||||
| _Shape = TypeVar("_Shape", bound=tuple[int, ...]) | ||||||||||||||||||||||||||||||||||
| _FilterType: TypeAlias = str | Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @overload | ||||||||||||||||||||||||||||||||||
| def resample( | ||||||||||||||||||||||||||||||||||
| x: _FloatArray, | ||||||||||||||||||||||||||||||||||
| x: np.ndarray[_Shape, np.dtype[np.integer[Any]]], | ||||||||||||||||||||||||||||||||||
|
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. To avoid writing an explanatory comment for
Suggested change
|
||||||||||||||||||||||||||||||||||
| sr_orig: float, | ||||||||||||||||||||||||||||||||||
| sr_new: float, | ||||||||||||||||||||||||||||||||||
| axis: int = -1, | ||||||||||||||||||||||||||||||||||
|
|
@@ -20,16 +21,70 @@ def resample( | |||||||||||||||||||||||||||||||||
| num_zeros: int = 64, | ||||||||||||||||||||||||||||||||||
| precision: int = 9, | ||||||||||||||||||||||||||||||||||
| rolloff: float = 0.945, | ||||||||||||||||||||||||||||||||||
| ) -> _FloatArray: ... | ||||||||||||||||||||||||||||||||||
| ) -> np.ndarray[_Shape, np.dtype[np.float32]]: ... | ||||||||||||||||||||||||||||||||||
| @overload | ||||||||||||||||||||||||||||||||||
| def resample( | ||||||||||||||||||||||||||||||||||
| x: np.ndarray[_Shape, np.dtype[_Floating]], | ||||||||||||||||||||||||||||||||||
| sr_orig: float, | ||||||||||||||||||||||||||||||||||
| sr_new: float, | ||||||||||||||||||||||||||||||||||
| axis: int = -1, | ||||||||||||||||||||||||||||||||||
| filter: _FilterType = "kaiser_best", | ||||||||||||||||||||||||||||||||||
| parallel: bool = False, | ||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||
| num_zeros: int = 64, | ||||||||||||||||||||||||||||||||||
| precision: int = 9, | ||||||||||||||||||||||||||||||||||
| rolloff: float = 0.945, | ||||||||||||||||||||||||||||||||||
| ) -> np.ndarray[_Shape, np.dtype[_Floating]]: ... | ||||||||||||||||||||||||||||||||||
| @overload | ||||||||||||||||||||||||||||||||||
| def resample( | ||||||||||||||||||||||||||||||||||
| x: np.ndarray[_Shape, np.dtype[np.integer[Any]]] | np.ndarray[_Shape, np.dtype[_Floating]], | ||||||||||||||||||||||||||||||||||
| sr_orig: float, | ||||||||||||||||||||||||||||||||||
| sr_new: float, | ||||||||||||||||||||||||||||||||||
| axis: int = -1, | ||||||||||||||||||||||||||||||||||
| filter: _FilterType = "kaiser_best", | ||||||||||||||||||||||||||||||||||
| parallel: bool = False, | ||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||
| num_zeros: int = 64, | ||||||||||||||||||||||||||||||||||
| precision: int = 9, | ||||||||||||||||||||||||||||||||||
| rolloff: float = 0.945, | ||||||||||||||||||||||||||||||||||
| ) -> np.ndarray[_Shape, np.dtype[np.float32]] | np.ndarray[_Shape, np.dtype[_Floating]]: ... | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+50
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. I'm not sure we need the third overload here, since it seems to be already covered by the first two.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @overload | ||||||||||||||||||||||||||||||||||
| def resample_nu( | ||||||||||||||||||||||||||||||||||
| x: np.ndarray[_Shape, np.dtype[np.integer[Any]]], | ||||||||||||||||||||||||||||||||||
|
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
|
||||||||||||||||||||||||||||||||||
| sr_orig: float, | ||||||||||||||||||||||||||||||||||
| t_out: np.ndarray[_Shape, np.dtype[np.float32]], | ||||||||||||||||||||||||||||||||||
| axis: int = -1, | ||||||||||||||||||||||||||||||||||
| filter: _FilterType = "kaiser_best", | ||||||||||||||||||||||||||||||||||
| parallel: bool = False, | ||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||
| num_zeros: int = 64, | ||||||||||||||||||||||||||||||||||
| precision: int = 9, | ||||||||||||||||||||||||||||||||||
| rolloff: float = 0.945, | ||||||||||||||||||||||||||||||||||
| ) -> np.ndarray[_Shape, np.dtype[np.float32]]: ... | ||||||||||||||||||||||||||||||||||
| @overload | ||||||||||||||||||||||||||||||||||
| def resample_nu( | ||||||||||||||||||||||||||||||||||
| x: np.ndarray[_Shape, np.dtype[_Floating]], | ||||||||||||||||||||||||||||||||||
| sr_orig: float, | ||||||||||||||||||||||||||||||||||
| t_out: np.ndarray[_Shape, np.dtype[_Floating]], | ||||||||||||||||||||||||||||||||||
| axis: int = -1, | ||||||||||||||||||||||||||||||||||
| filter: _FilterType = "kaiser_best", | ||||||||||||||||||||||||||||||||||
| parallel: bool = False, | ||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||
| num_zeros: int = 64, | ||||||||||||||||||||||||||||||||||
| precision: int = 9, | ||||||||||||||||||||||||||||||||||
| rolloff: float = 0.945, | ||||||||||||||||||||||||||||||||||
| ) -> np.ndarray[_Shape, np.dtype[_Floating]]: ... | ||||||||||||||||||||||||||||||||||
| @overload | ||||||||||||||||||||||||||||||||||
| def resample_nu( | ||||||||||||||||||||||||||||||||||
| x: _FloatArray, | ||||||||||||||||||||||||||||||||||
| x: np.ndarray[_Shape, np.dtype[np.integer[Any]]] | np.ndarray[_Shape, np.dtype[_Floating]], | ||||||||||||||||||||||||||||||||||
| sr_orig: float, | ||||||||||||||||||||||||||||||||||
| t_out: _FloatArray, | ||||||||||||||||||||||||||||||||||
| t_out: np.ndarray[_Shape, np.dtype[np.float32]] | np.ndarray[_Shape, np.dtype[_Floating]], | ||||||||||||||||||||||||||||||||||
| axis: int = -1, | ||||||||||||||||||||||||||||||||||
| filter: _FilterType = "kaiser_best", | ||||||||||||||||||||||||||||||||||
| parallel: bool = False, | ||||||||||||||||||||||||||||||||||
| *, | ||||||||||||||||||||||||||||||||||
| num_zeros: int = 64, | ||||||||||||||||||||||||||||||||||
| precision: int = 9, | ||||||||||||||||||||||||||||||||||
| rolloff: float = 0.945, | ||||||||||||||||||||||||||||||||||
| ) -> _FloatArray: ... | ||||||||||||||||||||||||||||||||||
| ) -> np.ndarray[_Shape, np.dtype[np.float32]] | np.ndarray[_Shape, np.dtype[_Floating]]: ... | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+78
to
+90
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
|
||||||||||||||||||||||||||||||||||
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.
The comment is still relevant