Skip to content

Commit 13bf726

Browse files
authored
Merge pull request #185 from jorenham/optype-0.7
optype 0.7
2 parents f299392 + d27f4e9 commit 13bf726

File tree

117 files changed

+1904
-1929
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+1904
-1929
lines changed

poetry.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ packages = [{include = "scipy-stubs"}]
1313
classifiers = [
1414
"Development Status :: 4 - Beta",
1515
"Operating System :: OS Independent",
16-
"Programming Language :: Python :: 3.10",
17-
"Programming Language :: Python :: 3.11",
18-
"Programming Language :: Python :: 3.12",
19-
"Programming Language :: Python :: 3.13",
2016
"Typing :: Stubs Only",
2117
"Typing :: Typed",
2218
]
@@ -32,8 +28,8 @@ Funding = "https://github.com/sponsors/jorenham"
3228
scipy = ["scipy"]
3329

3430
[tool.poetry.dependencies]
35-
python = "^3.10.1"
36-
optype = "^0.6.1"
31+
python = "^3.10"
32+
optype = "^0.7.1"
3733
scipy = {version = ">=1.10", optional = true}
3834

3935
[tool.poetry.group.dev.dependencies]

scipy-stubs/_lib/_finite_differences.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ from typing_extensions import TypeVar
44

55
import numpy as np
66
import numpy.typing as npt
7-
from scipy._typing import AnyInt, AnyReal
7+
import optype.numpy as onp
88

99
_T = TypeVar("_T", bound=np.floating[Any] | npt.NDArray[np.floating[Any]])
1010

1111
@overload
1212
def _derivative(
13-
func: Callable[Concatenate[float, ...], AnyReal],
13+
func: Callable[Concatenate[float, ...], onp.ToFloat],
1414
x0: float,
15-
dx: AnyReal = 1.0,
16-
n: AnyInt = 1,
15+
dx: onp.ToFloat = 1.0,
16+
n: onp.ToInt = 1,
1717
args: tuple[object, ...] = (),
18-
order: AnyInt = 3,
18+
order: onp.ToInt = 3,
1919
) -> np.float64: ...
2020
@overload
2121
def _derivative(
22-
func: Callable[Concatenate[_T, ...], AnyReal],
22+
func: Callable[Concatenate[_T, ...], onp.ToFloat],
2323
x0: _T,
24-
dx: AnyReal = 1.0,
25-
n: AnyInt = 1,
24+
dx: onp.ToFloat = 1.0,
25+
n: onp.ToInt = 1,
2626
args: tuple[object, ...] = (),
27-
order: AnyInt = 3,
27+
order: onp.ToInt = 3,
2828
) -> _T: ...

scipy-stubs/_typing.pyi

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ __all__ = [
1414
"RNG",
1515
"Alternative",
1616
"AnyBool",
17-
"AnyChar",
18-
"AnyComplex",
19-
"AnyInt",
20-
"AnyReal",
21-
"AnyScalar",
2217
"AnyShape",
23-
"Array0D",
2418
"ByteOrder",
2519
"Casting",
2620
"CorrelateMode",
@@ -68,16 +62,8 @@ FileLike: TypeAlias = IO[_ByteSOrStr] | FileName
6862
FileModeRW: TypeAlias = Literal["r", "w"]
6963
FileModeRWA: TypeAlias = Literal[FileModeRW, "a"]
7064

71-
_SCT = TypeVar("_SCT", bound=np.generic, default=np.generic)
72-
Array0D: TypeAlias = np.ndarray[tuple[()], np.dtype[_SCT]]
73-
7465
# keep in sync with `numpy._typing._scalars`
7566
AnyBool: TypeAlias = bool | np.bool_ | Literal[0, 1]
76-
AnyInt: TypeAlias = int | np.integer[Any] | np.bool_
77-
AnyReal: TypeAlias = int | float | np.floating[Any] | np.integer[Any] | np.bool_
78-
AnyComplex: TypeAlias = int | float | complex | np.number[Any] | np.bool_
79-
AnyChar: TypeAlias = str | bytes # `np.str_ <: builtins.str` and `np.bytes_ <: builtins.bytes`
80-
AnyScalar: TypeAlias = int | float | complex | AnyChar | np.generic
8167

8268
# equivalent to `numpy._typing._shape._ShapeLike`
8369
AnyShape: TypeAlias = op.CanIndex | Sequence[op.CanIndex]

scipy-stubs/cluster/hierarchy.pyi

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from collections.abc import Callable, Sequence
1+
from collections.abc import Callable
22
from types import ModuleType
33
from typing import Any, Literal, TypeAlias, TypedDict, overload
44
from typing_extensions import TypeVar, override
55

66
import numpy as np
7-
import numpy.typing as npt
87
import optype.numpy as onp
98
from scipy._lib._disjoint_set import DisjointSet
109
from scipy.spatial.distance import _MetricCallback, _MetricKind
@@ -47,7 +46,7 @@ __all__ = [
4746
_T = TypeVar("_T")
4847
_SCT = TypeVar("_SCT", bound=np.number[Any], default=np.float64)
4948
_LinkageMethod: TypeAlias = Literal["single", "complete", "average", "weighted", "centroid", "median", "ward"]
50-
_LinkageArray: TypeAlias = onp.Array[tuple[int, int], _SCT]
49+
_LinkageArray: TypeAlias = onp.Array2D[_SCT]
5150
_ClusterCriterion: TypeAlias = Literal["inconsistent", "distance", "maxclust", "monocrit", "maxclust_monocrit"]
5251
_SortOrder: TypeAlias = Literal["ascending", "descending"]
5352

@@ -64,16 +63,16 @@ class _DendrogramResult(TypedDict):
6463

6564
class ClusterWarning(UserWarning): ...
6665

67-
def int_floor(arr: onp.AnyArray, xp: ModuleType) -> int: ...
68-
def single(y: onp.AnyArray) -> _LinkageArray: ...
69-
def complete(y: onp.AnyArray) -> _LinkageArray: ...
70-
def average(y: onp.AnyArray) -> _LinkageArray: ...
71-
def weighted(y: onp.AnyArray) -> _LinkageArray: ...
72-
def centroid(y: onp.AnyArray) -> _LinkageArray: ...
73-
def median(y: onp.AnyArray) -> _LinkageArray: ...
74-
def ward(y: onp.AnyArray) -> _LinkageArray: ...
66+
def int_floor(arr: onp.ToArrayND, xp: ModuleType) -> int: ...
67+
def single(y: onp.ToArrayND) -> _LinkageArray: ...
68+
def complete(y: onp.ToArrayND) -> _LinkageArray: ...
69+
def average(y: onp.ToArrayND) -> _LinkageArray: ...
70+
def weighted(y: onp.ToArrayND) -> _LinkageArray: ...
71+
def centroid(y: onp.ToArrayND) -> _LinkageArray: ...
72+
def median(y: onp.ToArrayND) -> _LinkageArray: ...
73+
def ward(y: onp.ToArrayND) -> _LinkageArray: ...
7574
def linkage(
76-
y: onp.AnyArray,
75+
y: onp.ToArrayND,
7776
method: _LinkageMethod = "single",
7877
metric: _MetricKind | _MetricCallback = "euclidean",
7978
optimal_ordering: bool = False,
@@ -109,61 +108,58 @@ class ClusterNode:
109108
def pre_order(self, /, func: Callable[[ClusterNode], _T]) -> list[_T]: ...
110109

111110
def cut_tree(
112-
Z: onp.AnyArray,
113-
n_clusters: Sequence[int] | npt.NDArray[np.integer[Any]] | None = None,
114-
height: Sequence[float] | npt.NDArray[np.integer[Any] | np.floating[Any]] | None = None,
115-
) -> onp.Array[tuple[int, int], np.int64]: ...
111+
Z: onp.ToArray2D,
112+
n_clusters: onp.ToInt1D | None = None,
113+
height: onp.ToFloat1D | None = None,
114+
) -> onp.Array2D[np.int64]: ...
116115
@overload
117-
def to_tree(Z: onp.AnyArray, rd: Literal[False] = False) -> ClusterNode: ...
116+
def to_tree(Z: onp.ToArray2D, rd: Literal[False] = False) -> ClusterNode: ...
118117
@overload
119-
def to_tree(Z: onp.AnyArray, rd: Literal[True]) -> tuple[ClusterNode, list[ClusterNode]]: ...
118+
def to_tree(Z: onp.ToArray2D, rd: Literal[True]) -> tuple[ClusterNode, list[ClusterNode]]: ...
120119
def optimal_leaf_ordering(
121-
Z: onp.AnyArray,
122-
y: onp.AnyArray,
120+
Z: onp.ToArray2D,
121+
y: onp.ToArrayND,
123122
metric: _MetricKind | _MetricCallback = "euclidean",
124123
) -> _LinkageArray: ...
125124
@overload
126-
def cophenet(Z: onp.AnyArray, Y: None = None) -> onp.Array[tuple[int], np.float64]: ...
125+
def cophenet(Z: onp.ToArray2D, Y: None = None) -> onp.Array1D[np.float64]: ...
127126
@overload
128-
def cophenet(
129-
Z: onp.AnyArray,
130-
Y: onp.AnyArray,
131-
) -> tuple[onp.Array[tuple[int], np.float64], onp.Array[tuple[int], np.float64]]: ...
132-
def inconsistent(Z: onp.AnyArray, d: int = 2) -> _LinkageArray: ...
133-
def from_mlab_linkage(Z: onp.AnyArray) -> _LinkageArray: ...
134-
def to_mlab_linkage(Z: onp.AnyArray) -> _LinkageArray: ...
135-
def is_monotonic(Z: onp.AnyArray) -> bool: ...
136-
def is_valid_im(R: onp.AnyArray, warning: bool = False, throw: bool = False, name: str | None = None) -> bool: ...
137-
def is_valid_linkage(Z: onp.AnyArray, warning: bool = False, throw: bool = False, name: str | None = None) -> bool: ...
138-
def num_obs_linkage(Z: onp.AnyArray) -> int: ...
139-
def correspond(Z: onp.AnyArray, Y: onp.AnyArray) -> bool: ...
127+
def cophenet(Z: onp.ToArray2D, Y: onp.ToArrayND) -> tuple[onp.Array1D[np.float64], onp.Array1D[np.float64]]: ...
128+
def inconsistent(Z: onp.ToArray2D, d: int = 2) -> _LinkageArray: ...
129+
def from_mlab_linkage(Z: onp.ToArray2D) -> _LinkageArray: ...
130+
def to_mlab_linkage(Z: onp.ToArray2D) -> _LinkageArray: ...
131+
def is_monotonic(Z: onp.ToArray2D) -> bool: ...
132+
def is_valid_im(R: onp.ToArrayND, warning: bool = False, throw: bool = False, name: str | None = None) -> bool: ...
133+
def is_valid_linkage(Z: onp.ToArray2D, warning: bool = False, throw: bool = False, name: str | None = None) -> bool: ...
134+
def num_obs_linkage(Z: onp.ToArray2D) -> int: ...
135+
def correspond(Z: onp.ToArray2D, Y: onp.ToArrayND) -> bool: ...
140136
def fcluster(
141-
Z: onp.AnyArray,
137+
Z: onp.ToArray2D,
142138
t: float | np.floating[Any] | np.integer[Any],
143139
criterion: _ClusterCriterion = "inconsistent",
144140
depth: int = 2,
145-
R: onp.AnyArray | None = None,
146-
monocrit: onp.AnyArray | None = None,
147-
) -> onp.Array[tuple[int], np.int32]: ...
141+
R: onp.ToArrayND | None = None,
142+
monocrit: onp.ToArrayND | None = None,
143+
) -> onp.Array1D[np.int32]: ...
148144
def fclusterdata(
149-
X: onp.AnyArray,
145+
X: onp.ToArrayND,
150146
t: float | np.floating[Any] | np.integer[Any],
151147
criterion: _ClusterCriterion = "inconsistent",
152148
metric: _MetricKind | _MetricCallback = "euclidean",
153149
depth: int = 2,
154150
method: _LinkageMethod = "single",
155-
R: onp.AnyArray | None = None,
156-
) -> onp.Array[tuple[int], np.int32]: ...
157-
def leaves_list(Z: onp.AnyArray) -> onp.Array[tuple[int], np.int32]: ...
151+
R: onp.ToArrayND | None = None,
152+
) -> onp.Array1D[np.int32]: ...
153+
def leaves_list(Z: onp.ToArray2D) -> onp.Array1D[np.int32]: ...
158154
def set_link_color_palette(palette: list[str] | tuple[str, ...] | None) -> None: ...
159155
def dendrogram(
160-
Z: onp.AnyArray,
156+
Z: onp.ToArray2D,
161157
p: int = 30,
162158
truncate_mode: Literal["lastp", "level"] | None = None,
163159
color_threshold: float | np.floating[Any] | None = None,
164160
get_leaves: bool = True,
165161
orientation: Literal["top", "bottom", "left", "right"] = "top",
166-
labels: onp.AnyArray | None = None,
162+
labels: onp.ToArrayND | None = None,
167163
count_sort: _SortOrder | bool = False,
168164
distance_sort: _SortOrder | bool = False,
169165
show_leaf_counts: bool = True,
@@ -177,8 +173,8 @@ def dendrogram(
177173
ax: _MatplotlibAxes | None = None,
178174
above_threshold_color: str = "C0",
179175
) -> _DendrogramResult: ...
180-
def is_isomorphic(T1: onp.AnyArray, T2: onp.AnyArray) -> bool: ...
181-
def maxdists(Z: onp.AnyArray) -> onp.Array[tuple[int], np.float64]: ...
182-
def maxinconsts(Z: onp.AnyArray, R: onp.AnyArray) -> onp.Array[tuple[int], np.float64]: ...
183-
def maxRstat(Z: onp.AnyArray, R: onp.AnyArray, i: int) -> onp.Array[tuple[int], np.float64]: ...
184-
def leaders(Z: onp.AnyArray, T: onp.AnyArray) -> tuple[onp.Array[tuple[int], np.int32], onp.Array[tuple[int], np.int32]]: ...
176+
def is_isomorphic(T1: onp.ToArrayND, T2: onp.ToArrayND) -> bool: ...
177+
def maxdists(Z: onp.ToArray2D) -> onp.Array1D[np.float64]: ...
178+
def maxinconsts(Z: onp.ToArray2D, R: onp.ToArrayND) -> onp.Array1D[np.float64]: ...
179+
def maxRstat(Z: onp.ToArray2D, R: onp.ToArrayND, i: int) -> onp.Array1D[np.float64]: ...
180+
def leaders(Z: onp.ToArray2D, T: onp.ToArrayND) -> tuple[onp.Array1D[np.int32], onp.Array1D[np.int32]]: ...

scipy-stubs/cluster/vq.pyi

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
1-
from collections.abc import Sequence
2-
from typing import Any, Literal, TypeAlias, overload
1+
from typing import Any, Literal, overload
32
from typing_extensions import TypeVar
43

54
import numpy as np
65
import numpy.typing as npt
76
import optype.numpy as onp
7+
from scipy._typing import Seed
88

99
__all__ = ["kmeans", "kmeans2", "vq", "whiten"]
1010

1111
_SCT_fc = TypeVar("_SCT_fc", bound=np.inexact[Any])
12-
_ArrayLike_1d_fc: TypeAlias = onp.AnyNumberArray | Sequence[complex | np.number[Any]]
13-
_ArrayLike_2d_fc: TypeAlias = onp.AnyNumberArray | Sequence[Sequence[complex | np.number[Any]]]
12+
13+
###
1414

1515
class ClusterError(Exception): ...
1616

1717
@overload
18-
def whiten(obs: npt.NDArray[_SCT_fc], check_finite: bool = True) -> onp.Array[tuple[int, int], _SCT_fc]: ...
18+
def whiten(obs: npt.NDArray[_SCT_fc], check_finite: bool = True) -> onp.Array2D[_SCT_fc]: ...
1919
@overload
20-
def whiten(obs: _ArrayLike_2d_fc, check_finite: bool = True) -> onp.Array[tuple[int, int], np.inexact[Any]]: ...
20+
def whiten(obs: onp.ToComplex2D, check_finite: bool = True) -> onp.Array2D[np.inexact[Any]]: ...
21+
22+
#
2123
def vq(
22-
obs: _ArrayLike_2d_fc,
23-
code_book: _ArrayLike_2d_fc,
24+
obs: onp.ToComplex2D,
25+
code_book: onp.ToComplex2D,
2426
check_finite: bool = True,
25-
) -> tuple[onp.Array[tuple[int], np.int32 | np.intp], onp.Array[tuple[int], _SCT_fc]]: ...
27+
) -> tuple[onp.Array1D[np.int32 | np.intp], onp.Array1D[_SCT_fc]]: ...
2628
def py_vq(
27-
obs: _ArrayLike_2d_fc,
28-
code_book: _ArrayLike_2d_fc,
29+
obs: onp.ToComplex2D,
30+
code_book: onp.ToComplex2D,
2931
check_finite: bool = True,
30-
) -> tuple[onp.Array[tuple[int], np.intp], onp.Array[tuple[int], _SCT_fc]]: ...
32+
) -> tuple[onp.Array1D[np.intp], onp.Array1D[_SCT_fc]]: ...
33+
34+
#
3135
def kmeans(
32-
obs: _ArrayLike_2d_fc,
36+
obs: onp.ToComplex2D,
3337
k_or_guess: npt.ArrayLike,
3438
iter: int = 20,
3539
thresh: float = 1e-05,
3640
check_finite: bool = True,
3741
*,
38-
seed: int | np.random.Generator | np.random.RandomState | None = None,
39-
) -> tuple[onp.Array[tuple[int, int], np.inexact[Any]], float]: ...
42+
seed: Seed | None = None,
43+
) -> tuple[onp.Array2D[np.inexact[Any]], float]: ...
4044
def kmeans2(
41-
data: _ArrayLike_1d_fc | _ArrayLike_2d_fc,
45+
data: onp.ToComplex1D | onp.ToComplex2D,
4246
k: npt.ArrayLike,
4347
iter: int = 10,
4448
thresh: float = 1e-05,
4549
minit: Literal["random", "points", "++", "matrix"] = "random",
4650
missing: Literal["warn", "raise"] = "warn",
4751
check_finite: bool = True,
4852
*,
49-
seed: int | np.random.Generator | np.random.RandomState | None = None,
50-
) -> tuple[onp.Array[tuple[int, int], np.inexact[Any]], onp.Array[tuple[int], np.int32]]: ...
53+
seed: Seed | None = None,
54+
) -> tuple[onp.Array2D[np.inexact[Any]], onp.Array1D[np.int32]]: ...

0 commit comments

Comments
 (0)