diff --git a/stubs/resampy/METADATA.toml b/stubs/resampy/METADATA.toml new file mode 100644 index 000000000000..d09e841b4347 --- /dev/null +++ b/stubs/resampy/METADATA.toml @@ -0,0 +1,3 @@ +version = "0.4.*" +upstream_repository = "https://github.com/bmcfee/resampy" +requires = ["numba", "numpy"] 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..83a0da5fe2a9 --- /dev/null +++ b/stubs/resampy/resampy/core.pyi @@ -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]] + +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, +) -> _FloatArray: ... diff --git a/stubs/resampy/resampy/filters.pyi b/stubs/resampy/resampy/filters.pyi new file mode 100644 index 000000000000..2ea4688451c4 --- /dev/null +++ b/stubs/resampy/resampy/filters.pyi @@ -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]] = {} + +# List of filter functions available +FILTER_FUNCTIONS: list[str] = ["sinc_window"] + +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: ... diff --git a/stubs/resampy/resampy/interpn.pyi b/stubs/resampy/resampy/interpn.pyi new file mode 100644 index 000000000000..13765dc6dba3 --- /dev/null +++ b/stubs/resampy/resampy/interpn.pyi @@ -0,0 +1,66 @@ +from typing import Any + +import numba +import numpy as np +from numba import guvectorize + +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: ... + +# JIT-compiled parallel version of _resample_loop +_resample_loop_p = ... + +# JIT-compiled sequential version of _resample_loop +_resample_loop_s = ... + +@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: ... diff --git a/stubs/resampy/resampy/version.pyi b/stubs/resampy/resampy/version.pyi new file mode 100644 index 000000000000..ce09f8d9b25d --- /dev/null +++ b/stubs/resampy/resampy/version.pyi @@ -0,0 +1,2 @@ +short_version: str +version: str