Skip to content

Conversation

@hunterhogan
Copy link
Contributor

Introduce core functionality and metadata for the resampy library, including initial stubs for resampling methods and filter functions. Update metadata to specify dependencies.

See also #15338.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@@ -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"]

Comment on lines +1 to +2
short_version: str
version: str
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]

@@ -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

Comment on lines +9 to +12
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"]
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]

Comment on lines +3 to +5
import numba
import numpy as np
from numba import guvectorize
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

Comment on lines +23 to +66
@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: ...
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: ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants