Skip to content

Commit 5ffe837

Browse files
authored
signal: complete _fir_filter_design.* en max_len_seq (#384)
2 parents 742394b + bccdf1a commit 5ffe837

File tree

4 files changed

+135
-49
lines changed

4 files changed

+135
-49
lines changed

scipy-stubs/signal/_arraytools.pyi

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
from typing import TypeVar
1+
from typing import Literal, TypeAlias, TypeVar, overload
22

33
import numpy as np
44
import optype as op
55
import optype.numpy as onp
66

77
_SCT = TypeVar("_SCT", bound=np.generic)
88

9+
_Truthy: TypeAlias = Literal[True, 1]
10+
11+
###
12+
913
def axis_slice(
1014
a: onp.ArrayND[_SCT],
1115
start: op.CanIndex | None = None,
@@ -14,7 +18,15 @@ def axis_slice(
1418
axis: op.CanIndex = -1,
1519
) -> onp.ArrayND[_SCT]: ...
1620
def axis_reverse(a: onp.ArrayND[_SCT], axis: op.CanIndex = -1) -> onp.ArrayND[_SCT]: ...
21+
22+
#
1723
def odd_ext(x: onp.ArrayND[_SCT], n: onp.ToInt, axis: op.CanIndex = -1) -> onp.ArrayND[_SCT]: ...
1824
def even_ext(x: onp.ArrayND[_SCT], n: onp.ToInt, axis: op.CanIndex = -1) -> onp.ArrayND[_SCT]: ...
1925
def const_ext(x: onp.ArrayND[_SCT], n: onp.ToInt, axis: op.CanIndex = -1) -> onp.ArrayND[_SCT]: ...
2026
def zero_ext(x: onp.ArrayND[_SCT], n: onp.ToInt, axis: op.CanIndex = -1) -> onp.ArrayND[_SCT]: ...
27+
28+
#
29+
@overload
30+
def _validate_fs(fs: None, allow_none: _Truthy = True) -> None: ...
31+
@overload
32+
def _validate_fs(fs: onp.ToFloat, allow_none: onp.ToBool = True) -> float: ...
+100-42
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,113 @@
1-
from typing import Literal
1+
from typing import Literal, TypeAlias, overload
2+
from typing_extensions import TypeVar
23

3-
from scipy._typing import Untyped, UntypedArray
4+
import numpy as np
5+
import optype as op
6+
import optype.numpy as onp
7+
import optype.numpy.compat as npc
8+
from .windows._windows import _ToWindow
49

510
__all__ = ["firls", "firwin", "firwin2", "kaiser_atten", "kaiser_beta", "kaiserord", "minimum_phase", "remez"]
611

7-
def kaiser_beta(a: Untyped) -> Untyped: ...
8-
def kaiser_atten(numtaps: int, width: float | None) -> Untyped: ...
9-
def kaiserord(ripple: Untyped, width: float | None) -> Untyped: ...
12+
###
13+
14+
_InexactT_py = TypeVar("_InexactT_py", bound=complex)
15+
_InexactT_np = TypeVar("_InexactT_np", bound=npc.inexact)
16+
17+
_IIRFilterType: TypeAlias = Literal["bandpass", "lowpass", "highpass", "bandstop"]
18+
_RemezFilterType: TypeAlias = Literal["bandpass", "differentiator", "hilbert"]
19+
_LinearPhaseFIRMethod: TypeAlias = Literal["homomorphic", "hilbert"]
20+
21+
###
22+
23+
#
24+
def kaiser_beta(a: onp.ToFloat) -> float: ...
25+
def kaiserord(ripple: onp.ToFloat, width: onp.ToFloat) -> tuple[int, float]: ...
26+
27+
#
28+
@overload
29+
def kaiser_atten(numtaps: _InexactT_py, width: _InexactT_py) -> _InexactT_py: ...
30+
@overload
31+
def kaiser_atten(numtaps: _InexactT_np | float, width: _InexactT_np) -> _InexactT_np: ...
32+
@overload
33+
def kaiser_atten(numtaps: npc.integer, width: npc.integer | float) -> np.float64: ...
34+
@overload
35+
def kaiser_atten(numtaps: npc.integer | float, width: npc.integer) -> np.float64: ...
36+
37+
#
38+
@overload
39+
def firwin(
40+
numtaps: onp.ToJustInt,
41+
cutoff: onp.ToFloat64 | onp.ToFloat64_1D,
42+
*,
43+
width: onp.ToFloat64 | None = None,
44+
window: _ToWindow = "hamming",
45+
pass_zero: _IIRFilterType | bool = True,
46+
scale: op.CanBool = True,
47+
fs: onp.ToFloat64 | None = None,
48+
) -> onp.Array1D[np.float64]: ...
49+
@overload
1050
def firwin(
11-
numtaps: int,
12-
cutoff: Untyped,
51+
numtaps: onp.ToJustInt,
52+
cutoff: onp.ToFloat | onp.ToFloat1D,
1353
*,
14-
width: Untyped | None = None,
15-
window: str = "hamming",
16-
pass_zero: Literal["bandpass", "lowpass", "highpass", "bandstop"] | bool = True,
17-
scale: bool = True,
18-
fs: float | None = None,
19-
) -> Untyped: ...
54+
width: onp.ToFloat | None = None,
55+
window: _ToWindow = "hamming",
56+
pass_zero: _IIRFilterType | bool = True,
57+
scale: op.CanBool = True,
58+
fs: onp.ToFloat | None = None,
59+
) -> onp.Array1D[np.float64 | np.longdouble]: ...
60+
61+
#
2062
def firwin2(
21-
numtaps: int,
22-
freq: Untyped,
23-
gain: Untyped,
63+
numtaps: onp.ToJustInt,
64+
freq: onp.ToFloat1D,
65+
gain: onp.ToFloat1D,
2466
*,
25-
nfreqs: Untyped | None = None,
26-
window: str = "hamming",
27-
antisymmetric: bool = False,
28-
fs: float | None = None,
29-
) -> Untyped: ...
30-
def remez(
31-
numtaps: int,
32-
bands: Untyped,
33-
desired: Untyped,
67+
nfreqs: onp.ToJustInt | None = None,
68+
window: _ToWindow = "hamming",
69+
antisymmetric: op.CanBool = False,
70+
fs: onp.ToFloat | None = None,
71+
) -> onp.Array1D[np.float64]: ...
72+
73+
#
74+
@overload
75+
def firls(
76+
numtaps: onp.ToJustInt,
77+
bands: onp.ToFloat1D,
78+
desired: onp.ToFloat1D,
3479
*,
35-
weight: Untyped | None = None,
36-
type: str = "bandpass",
37-
maxiter: int = 25,
38-
grid_density: int = 16,
39-
fs: float | None = None,
40-
) -> Untyped: ...
80+
weight: onp.ToFloat1D | None = None,
81+
fs: onp.ToFloat | None = None,
82+
) -> onp.Array1D[np.float64]: ...
83+
@overload
4184
def firls(
42-
numtaps: int,
43-
bands: Untyped,
44-
desired: Untyped,
85+
numtaps: onp.ToJustInt,
86+
bands: onp.ToFloat2D,
87+
desired: onp.ToFloat2D,
4588
*,
46-
weight: Untyped | None = None,
47-
fs: float | None = None,
48-
) -> Untyped: ...
89+
weight: onp.ToFloat1D | None = None,
90+
fs: onp.ToFloat | None = None,
91+
) -> onp.Array1D[np.float64]: ...
92+
93+
#
94+
def remez(
95+
numtaps: onp.ToJustInt,
96+
bands: onp.ToFloat1D,
97+
desired: onp.ToFloat1D,
98+
*,
99+
weight: onp.ToFloat1D | None = None,
100+
type: _RemezFilterType = "bandpass",
101+
maxiter: onp.ToJustInt = 25,
102+
grid_density: onp.ToJustInt = 16,
103+
fs: onp.ToFloat | None = None,
104+
) -> onp.Array1D[np.float64]: ...
105+
106+
#
49107
def minimum_phase(
50-
h: UntypedArray,
51-
method: Literal["homomorphic", "hilbert"] = "homomorphic",
52-
n_fft: int | None = None,
108+
h: onp.ToFloat1D,
109+
method: _LinearPhaseFIRMethod = "homomorphic",
110+
n_fft: onp.ToJustInt | None = None,
53111
*,
54-
half: bool = True,
55-
) -> UntypedArray: ...
112+
half: op.CanBool = True,
113+
) -> onp.Array1D[np.float64]: ...

scipy-stubs/signal/_max_len_seq.pyi

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
from scipy._typing import Untyped, UntypedArray
1+
from typing import Final
2+
3+
import numpy as np
4+
import optype.numpy as onp
25

36
__all__ = ["max_len_seq"]
47

8+
_mls_taps: Final[dict[int, list[int]]] = ...
9+
510
def max_len_seq(
6-
nbits: int,
7-
state: Untyped | None = None,
8-
length: int | None = None,
9-
taps: Untyped | None = None,
10-
) -> tuple[UntypedArray, UntypedArray]: ...
11+
nbits: onp.ToJustInt,
12+
state: onp.ToInt1D | None = None,
13+
length: onp.ToJustInt | None = None,
14+
taps: onp.ToJustInt1D | None = None,
15+
) -> tuple[onp.Array1D[np.int8], onp.Array1D[np.int8]]: ...
+11
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
import numpy as np
2+
import optype.numpy as onp
3+
14
__pythran__: tuple[str, str] = ...
5+
6+
def _max_len_seq_inner(
7+
taps: onp.Array1D[np.intp],
8+
state: onp.Array1D[np.int8],
9+
nbits: int | np.intp,
10+
length: int | np.intp,
11+
out: onp.Array1D[np.int8],
12+
) -> onp.Array1D[np.int8]: ...

0 commit comments

Comments
 (0)