Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stubs/resampy/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = "0.4.*"
upstream_repository = "https://github.com/bmcfee/resampy"
requires = ["numba", "numpy"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. numpy ships py.typed file since version 1.20
  2. numba is not needed here, we can get rid of it (see below)
Suggested change
requires = ["numba", "numpy"]
# Requires a version of numpy with a `py.typed` file
requires = ["numpy>=1.20"]

2 changes: 2 additions & 0 deletions stubs/resampy/resampy/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import filters as filters
Copy link
Contributor

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:

Suggested change
from . import filters as filters
from .version import version as __version__
from . import filters as filters

from .core import *
29 changes: 29 additions & 0 deletions stubs/resampy/resampy/core.pyi
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]]

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: ...
25 changes: 25 additions & 0 deletions stubs/resampy/resampy/filters.pyi
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]] = {}

# List of filter functions available
FILTER_FUNCTIONS: list[str] = ["sinc_window"]
Comment on lines +9 to +12
Copy link
Contributor

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:

Suggested change
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]


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: ...
66 changes: 66 additions & 0 deletions stubs/resampy/resampy/interpn.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from typing import Any

import numba

Check failure on line 3 in stubs/resampy/resampy/interpn.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

Stub file not found for "numba" (reportMissingTypeStubs)
import numpy as np
from numba import guvectorize

Check failure on line 5 in stubs/resampy/resampy/interpn.pyi

View workflow job for this annotation

GitHub Actions / pyright: Run test cases (Linux, 3.13)

Stub file not found for "numba" (reportMissingTypeStubs)
Comment on lines +3 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import numba
import numpy as np
from numba import guvectorize
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: ...

# 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: ...
Comment on lines +23 to +66
Copy link
Contributor

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.

Suggested change
@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: ...

2 changes: 2 additions & 0 deletions stubs/resampy/resampy/version.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
short_version: str
version: str
Comment on lines +1 to +2
Copy link
Contributor

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:

Suggested change
short_version: str
version: str
from typing import Final
short_version: Final[str]
version: Final[str]

Loading