-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👽️
cluster
: fix new stubtest errors (#334)
- Loading branch information
Showing
3 changed files
with
139 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,102 @@ | ||
from typing import Any, Literal, overload | ||
from typing import Any, Literal, TypeAlias, overload | ||
from typing_extensions import TypeVar | ||
|
||
import numpy as np | ||
import optype.numpy as onp | ||
from scipy._typing import ToRNG as Seed # TODO(jorenham) | ||
from scipy._typing import ToRNG | ||
|
||
__all__ = ["kmeans", "kmeans2", "vq", "whiten"] | ||
|
||
_SCT_fc = TypeVar("_SCT_fc", bound=np.inexact[Any]) | ||
_InitMethod: TypeAlias = Literal["random", "points", "++", "matrix"] | ||
_MissingMethod: TypeAlias = Literal["warn", "raise"] | ||
|
||
_Floating: TypeAlias = np.floating[Any] | ||
_Inexact: TypeAlias = np.inexact[Any] | ||
|
||
_InexactT = TypeVar("_InexactT", bound=_Inexact) | ||
|
||
### | ||
|
||
class ClusterError(Exception): ... | ||
|
||
# TODO(jorenham): Array API support | ||
@overload | ||
def whiten(obs: onp.ArrayND[_SCT_fc], check_finite: bool = True) -> onp.Array2D[_SCT_fc]: ... | ||
def whiten(obs: onp.ArrayND[np.bool_ | np.integer[Any]], check_finite: bool = True) -> onp.Array2D[np.float64]: ... | ||
@overload | ||
def whiten(obs: onp.ToFloat2D, check_finite: bool = True) -> onp.Array2D[np.floating[Any]]: ... | ||
@overload | ||
def whiten(obs: onp.ToComplex2D, check_finite: bool = True) -> onp.Array2D[np.inexact[Any]]: ... | ||
def whiten(obs: onp.ArrayND[_InexactT], check_finite: bool = True) -> onp.Array2D[_InexactT]: ... | ||
|
||
# | ||
@overload | ||
def vq( | ||
obs: onp.ToFloat2D, | ||
code_book: onp.ToFloat2D, | ||
check_finite: bool = True, | ||
) -> tuple[onp.Array1D[np.int32 | np.intp], onp.Array1D[_Floating]]: ... | ||
@overload | ||
def vq( | ||
obs: onp.ToComplex2D, | ||
code_book: onp.ToComplex2D, | ||
check_finite: bool = True, | ||
) -> tuple[onp.Array1D[np.int32 | np.intp], onp.Array1D[_SCT_fc]]: ... | ||
) -> tuple[onp.Array1D[np.int32 | np.intp], onp.Array1D[_Inexact]]: ... | ||
|
||
# | ||
@overload | ||
def py_vq( | ||
obs: onp.ToFloat2D, | ||
code_book: onp.ToFloat2D, | ||
check_finite: bool = True, | ||
) -> tuple[onp.Array1D[np.intp], onp.Array1D[_Floating]]: ... | ||
@overload | ||
def py_vq( | ||
obs: onp.ToComplex2D, | ||
code_book: onp.ToComplex2D, | ||
check_finite: bool = True, | ||
) -> tuple[onp.Array1D[np.intp], onp.Array1D[_SCT_fc]]: ... | ||
) -> tuple[onp.Array1D[np.intp], onp.Array1D[_Inexact]]: ... | ||
|
||
# | ||
@overload # real | ||
def kmeans( | ||
obs: onp.ToFloat2D, | ||
k_or_guess: onp.ToJustInt | onp.ToFloatND, | ||
iter: int = 20, | ||
thresh: float = 1e-05, | ||
thresh: float = 1e-5, | ||
check_finite: bool = True, | ||
*, | ||
seed: Seed | None = None, | ||
) -> tuple[onp.Array2D[np.floating[Any]], float]: ... | ||
rng: ToRNG = None, | ||
) -> tuple[onp.Array2D[_Floating], float]: ... | ||
@overload # complex | ||
def kmeans( | ||
obs: onp.ToComplex2D, | ||
k_or_guess: onp.ToJustInt | onp.ToFloatND, | ||
iter: int = 20, | ||
thresh: float = 1e-05, | ||
thresh: float = 1e-5, | ||
check_finite: bool = True, | ||
*, | ||
seed: Seed | None = None, | ||
) -> tuple[onp.Array2D[np.inexact[Any]], float]: ... | ||
rng: ToRNG = None, | ||
) -> tuple[onp.Array2D[_Inexact], float]: ... | ||
|
||
# | ||
@overload # real | ||
def kmeans2( | ||
data: onp.ToFloat1D | onp.ToFloat2D, | ||
k: onp.ToJustInt | onp.ToFloatND, | ||
iter: int = 10, | ||
thresh: float = 1e-05, | ||
minit: Literal["random", "points", "++", "matrix"] = "random", | ||
missing: Literal["warn", "raise"] = "warn", | ||
thresh: float = 1e-5, | ||
minit: _InitMethod = "random", | ||
missing: _MissingMethod = "warn", | ||
check_finite: bool = True, | ||
*, | ||
seed: Seed | None = None, | ||
) -> tuple[onp.Array2D[np.floating[Any]], onp.Array1D[np.int32]]: ... | ||
rng: ToRNG = None, | ||
) -> tuple[onp.Array2D[_Floating], onp.Array1D[np.int32]]: ... | ||
@overload # complex | ||
def kmeans2( | ||
data: onp.ToComplex1D | onp.ToComplex2D, | ||
k: onp.ToJustInt | onp.ToFloatND, | ||
iter: int = 10, | ||
thresh: float = 1e-05, | ||
minit: Literal["random", "points", "++", "matrix"] = "random", | ||
missing: Literal["warn", "raise"] = "warn", | ||
thresh: float = 1e-5, | ||
minit: _InitMethod = "random", | ||
missing: _MissingMethod = "warn", | ||
check_finite: bool = True, | ||
*, | ||
seed: Seed | None = None, | ||
) -> tuple[onp.Array2D[np.inexact[Any]], onp.Array1D[np.int32]]: ... | ||
rng: ToRNG = None, | ||
) -> tuple[onp.Array2D[_Inexact], onp.Array1D[np.int32]]: ... |