diff --git a/stubs/resampy/@tests/stubtest_allowlist.txt b/stubs/resampy/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..0f1a287ded50 --- /dev/null +++ b/stubs/resampy/@tests/stubtest_allowlist.txt @@ -0,0 +1,3 @@ +# The functions are part of the internal API. +resampy.interpn.resample_f_p +resampy.interpn.resample_f_s diff --git a/stubs/resampy/METADATA.toml b/stubs/resampy/METADATA.toml new file mode 100644 index 000000000000..fc703115ffa8 --- /dev/null +++ b/stubs/resampy/METADATA.toml @@ -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"] diff --git a/stubs/resampy/resampy/__init__.pyi b/stubs/resampy/resampy/__init__.pyi new file mode 100644 index 000000000000..92d287f8a8fb --- /dev/null +++ b/stubs/resampy/resampy/__init__.pyi @@ -0,0 +1,2 @@ +from . import filters as filters +from .core import * diff --git a/stubs/resampy/resampy/core.pyi b/stubs/resampy/resampy/core.pyi new file mode 100644 index 000000000000..5d13c9ba241c --- /dev/null +++ b/stubs/resampy/resampy/core.pyi @@ -0,0 +1,36 @@ +from collections.abc import Callable +from typing import TypedDict, type_check_only +from typing_extensions import TypeAlias, TypeVar, Unpack + +import numpy as np + +__all__ = ["resample", "resample_nu"] + +_FloatArray = TypeVar("_FloatArray", bound=np.ndarray[tuple[int, ...], np.dtype[np.floating]]) + +_FilterType: TypeAlias = str | Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]] + +@type_check_only +class _FilterKwArgs(TypedDict, total=False): + num_zeros: int + precision: int + rolloff: float + +def resample( + x: _FloatArray, + sr_orig: float, + sr_new: float, + axis: int = -1, + filter: _FilterType = "kaiser_best", + parallel: bool = False, + **kwargs: Unpack[_FilterKwArgs], +) -> _FloatArray: ... +def resample_nu( + x: _FloatArray, + sr_orig: float, + t_out: _FloatArray, + axis: int = -1, + filter: _FilterType = "kaiser_best", + parallel: bool = False, + **kwargs: Unpack[_FilterKwArgs], +) -> _FloatArray: ... diff --git a/stubs/resampy/resampy/filters.pyi b/stubs/resampy/resampy/filters.pyi new file mode 100644 index 000000000000..fc391dd0054a --- /dev/null +++ b/stubs/resampy/resampy/filters.pyi @@ -0,0 +1,33 @@ +from collections.abc import Callable +from typing import TypedDict, type_check_only +from typing_extensions import TypeAlias, Unpack + +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.float64]], int, float]] + +# List of filter functions available +FILTER_FUNCTIONS: list[str] + +_FilterType: TypeAlias = str | Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]] + +@type_check_only +class _FilterKwArgs(TypedDict, total=False): + num_zeros: int + precision: int + rolloff: float + +def sinc_window( + num_zeros: int = 64, + precision: int = 9, + window: Callable[[int], np.ndarray[tuple[int], np.dtype[np.float64]]] | None = None, + rolloff: float = 0.945, +) -> tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]: ... +def get_filter( + name_or_function: _FilterType, **kwargs: Unpack[_FilterKwArgs] +) -> tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]: ... +def load_filter(filter_name: str) -> tuple[np.ndarray[tuple[int], np.dtype[np.float64]], int, float]: ... +def clear_cache() -> None: ... diff --git a/stubs/resampy/resampy/interpn.pyi b/stubs/resampy/resampy/interpn.pyi new file mode 100644 index 000000000000..37c2f6a9c89a --- /dev/null +++ b/stubs/resampy/resampy/interpn.pyi @@ -0,0 +1 @@ +# [This page intentionally left blank.] diff --git a/stubs/resampy/resampy/version.pyi b/stubs/resampy/resampy/version.pyi new file mode 100644 index 000000000000..24179934d795 --- /dev/null +++ b/stubs/resampy/resampy/version.pyi @@ -0,0 +1,4 @@ +from typing import Final + +short_version: Final[str] +version: Final[str]