diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index 41d2d75d..89f510a9 100644 --- a/src/numpy-stubs/__init__.pyi +++ b/src/numpy-stubs/__init__.pyi @@ -480,7 +480,7 @@ from .lib._type_check_impl import ( ) from .lib._ufunclike_impl import fix, isneginf, isposinf from .lib._utils_impl import get_include, info, show_runtime -from .matrixlib import asmatrix, bmat +from .matrixlib import asmatrix, bmat, matrix from .version import __version__ @runtime_checkable @@ -628,7 +628,6 @@ _NumericArrayT = TypeVar("_NumericArrayT", bound=NDArray[number | timedelta64 | _ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...]) _ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True) -_2DShapeT_co = TypeVar("_2DShapeT_co", bound=_2D, covariant=True) _1NShapeT = TypeVar("_1NShapeT", bound=tuple[L[1], Unpack[tuple[L[1], ...]]]) # (1,) | (1, 1) | (1, 1, 1) | ... _ScalarT = TypeVar("_ScalarT", bound=generic) @@ -744,7 +743,6 @@ _Falsy: TypeAlias = L[False, 0] | bool_[L[False]] _Truthy: TypeAlias = L[True, 1] | bool_[L[True]] _1D: TypeAlias = tuple[int] -_2D: TypeAlias = tuple[int, int] _2Tuple: TypeAlias = tuple[_T, _T] _ArrayUInt_co: TypeAlias = NDArray[unsignedinteger | bool_] @@ -5252,9 +5250,9 @@ class ufunc: @property def __name__(self) -> LiteralString: ... @property - def __qualname__(self) -> LiteralString: ... + def __qualname__(self) -> LiteralString: ... # pyright: ignore[reportIncompatibleVariableOverride] @property - def __doc__(self) -> str: ... + def __doc__(self) -> str: ... # type: ignore[override] # pyright: ignore[reportIncompatibleVariableOverride] # @property @@ -5393,166 +5391,3 @@ bitwise_invert: Final = invert bitwise_right_shift: Final = right_shift permute_dims: Final = transpose pow: Final = power - -class matrix(ndarray[_2DShapeT_co, _DTypeT_co]): - __array_priority__: ClassVar[float] = ... - - # - def __new__(cls, data: ArrayLike, dtype: DTypeLike = ..., copy: py_bool = ...) -> matrix[_2D, Any]: ... - - # - @overload - def __getitem__(self, key: (CanIndex | _ArrayLikeInt_co | tuple[CanIndex | _ArrayLikeInt_co, ...]), /) -> Any: ... - @overload - def __getitem__( - self, - key: slice - | EllipsisType - | CanIndex - | _ArrayLikeInt_co - | tuple[slice | EllipsisType | _ArrayLikeInt_co | CanIndex | None, ...] - | None, - /, - ) -> matrix[_2D, _DTypeT_co]: ... - @overload - def __getitem__(self: NDArray[void], key: str, /) -> matrix[_2D, dtype[Any]]: ... - @overload - def __getitem__(self: NDArray[void], key: list[str], /) -> matrix[_2DShapeT_co, dtype[void]]: ... - - # - def __mul__(self, other: ArrayLike, /) -> matrix[_2D, Any]: ... - def __rmul__(self, other: ArrayLike, /) -> matrix[_2D, Any]: ... - def __imul__(self, other: ArrayLike, /) -> Self: ... - - # - def __pow__(self, other: ArrayLike, /) -> matrix[_2D, Any]: ... - def __ipow__(self, other: ArrayLike, /) -> Self: ... - - # - @overload - def sum(self, axis: None = ..., dtype: DTypeLike = ..., out: None = ...) -> Any: ... - @overload - def sum(self, axis: _ShapeLike, dtype: DTypeLike = ..., out: None = ...) -> matrix[_2D, Any]: ... - @overload - def sum(self, axis: _ShapeLike | None = ..., dtype: DTypeLike = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - @overload - def mean(self, axis: None = ..., dtype: DTypeLike = ..., out: None = ...) -> Any: ... - @overload - def mean(self, axis: _ShapeLike, dtype: DTypeLike = ..., out: None = ...) -> matrix[_2D, Any]: ... - @overload - def mean(self, axis: _ShapeLike | None = ..., dtype: DTypeLike = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - @overload - def std(self, axis: None = ..., dtype: DTypeLike = ..., out: None = ..., ddof: float = ...) -> Any: ... - @overload - def std(self, axis: _ShapeLike, dtype: DTypeLike = ..., out: None = ..., ddof: float = ...) -> matrix[_2D, Any]: ... - @overload - def std(self, axis: _ShapeLike | None = ..., dtype: DTypeLike = ..., out: _ArrayT = ..., ddof: float = ...) -> _ArrayT: ... - - # - @overload - def var(self, axis: None = ..., dtype: DTypeLike = ..., out: None = ..., ddof: float = ...) -> Any: ... - @overload - def var(self, axis: _ShapeLike, dtype: DTypeLike = ..., out: None = ..., ddof: float = ...) -> matrix[_2D, Any]: ... - @overload - def var(self, axis: _ShapeLike | None = ..., dtype: DTypeLike = ..., out: _ArrayT = ..., ddof: float = ...) -> _ArrayT: ... - - # - @overload - def prod(self, axis: None = ..., dtype: DTypeLike = ..., out: None = ...) -> Any: ... - @overload - def prod(self, axis: _ShapeLike, dtype: DTypeLike = ..., out: None = ...) -> matrix[_2D, Any]: ... - @overload - def prod(self, axis: _ShapeLike | None = ..., dtype: DTypeLike = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - @overload - def any(self, axis: None = ..., out: None = ...) -> bool_: ... - @overload - def any(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, dtype[bool_]]: ... - @overload - def any(self, axis: _ShapeLike | None = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - @overload - def all(self, axis: None = ..., out: None = ...) -> bool_: ... - @overload - def all(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, dtype[bool_]]: ... - @overload - def all(self, axis: _ShapeLike | None = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - @overload - def max(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> _ScalarT: ... - @overload - def max(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, _DTypeT_co]: ... - @overload - def max(self, axis: _ShapeLike | None = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - @overload - def min(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> _ScalarT: ... - @overload - def min(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, _DTypeT_co]: ... - @overload - def min(self, axis: _ShapeLike | None = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - @overload - def argmax(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> intp: ... - @overload - def argmax(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, dtype[intp]]: ... - @overload - def argmax(self, axis: _ShapeLike | None = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - @overload - def argmin(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> intp: ... - @overload - def argmin(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, dtype[intp]]: ... - @overload - def argmin(self, axis: _ShapeLike | None = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - @overload - def ptp(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> _ScalarT: ... - @overload - def ptp(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, _DTypeT_co]: ... - @overload - def ptp(self, axis: _ShapeLike | None = ..., out: _ArrayT = ...) -> _ArrayT: ... - - # - def tolist(self: _CanItem[_T]) -> list[list[_T]]: ... - - # - def squeeze(self, axis: _ShapeLike | None = ...) -> matrix[_2D, _DTypeT_co]: ... - def ravel(self, /, order: _OrderKACF = "C") -> matrix[tuple[L[1], int], _DTypeT_co]: ... # pyright: ignore[reportIncompatibleMethodOverride] - def flatten(self, /, order: _OrderKACF = "C") -> matrix[tuple[L[1], int], _DTypeT_co]: ... # pyright: ignore[reportIncompatibleMethodOverride] - - # - @property - def T(self) -> matrix[_2D, _DTypeT_co]: ... - def getT(self) -> matrix[_2D, _DTypeT_co]: ... - - # - @property - def I(self) -> matrix[_2D, Any]: ... - def getI(self) -> matrix[_2D, Any]: ... - - # - @property - def A(self) -> ndarray[_2DShapeT_co, _DTypeT_co]: ... - def getA(self) -> ndarray[_2DShapeT_co, _DTypeT_co]: ... - - # - @property - def A1(self) -> ndarray[tuple[int, ...], _DTypeT_co]: ... - def getA1(self) -> ndarray[tuple[int, ...], _DTypeT_co]: ... - - # - @property - def H(self) -> matrix[_2D, _DTypeT_co]: ... - def getH(self) -> matrix[_2D, _DTypeT_co]: ... diff --git a/src/numpy-stubs/matrixlib/defmatrix.pyi b/src/numpy-stubs/matrixlib/defmatrix.pyi index dceafc2d..d144220b 100644 --- a/src/numpy-stubs/matrixlib/defmatrix.pyi +++ b/src/numpy-stubs/matrixlib/defmatrix.pyi @@ -1,17 +1,323 @@ -from collections.abc import Mapping, Sequence -from typing import Any +from collections.abc import Mapping +from types import EllipsisType +from typing import Any, ClassVar, SupportsIndex as CanIndex, TypeAlias, overload +from typing_extensions import Self, TypeVar, override import numpy as np -from numpy import matrix # noqa: ICN003 -from numpy._typing import ArrayLike, DTypeLike, NDArray +from _numtype import ( + Array, + Is, + Matrix, + Sequence_3nd, + ToBool_nd, + ToBytes_nd, + ToComplex128_nd, + ToFloat64_nd, + ToGeneric_3nd, + ToGeneric_nd, + ToIntP_nd, + ToInteger_1nd, + ToObject_nd, + ToStr_nd, + _ToArray1_1nd, + _ToArray1_nd, +) +from numpy import _CanItem, _OrderKACF # noqa: ICN003 +from numpy._typing import ArrayLike, DTypeLike, _ArrayLikeInt_co, _DTypeLike __all__ = ["asmatrix", "bmat", "matrix"] +### + +_T = TypeVar("_T") +_ArrayT = TypeVar("_ArrayT", bound=Array) +_ScalarT = TypeVar("_ScalarT", bound=np.generic) +_ShapeT_co = TypeVar("_ShapeT_co", bound=_2D, default=_2D, covariant=True) +_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype[Any], default=np.dtype[Any], covariant=True) + +_2D: TypeAlias = tuple[int, int] + +_ToIndex1: TypeAlias = slice | EllipsisType | ToInteger_1nd | None +_ToIndex2: TypeAlias = tuple[_ToIndex1, _ToIndex1 | CanIndex] | tuple[_ToIndex1 | CanIndex, _ToIndex1] + +_ToAxis: TypeAlias = CanIndex | tuple[()] | tuple[CanIndex] | tuple[CanIndex, CanIndex] + +### + +class matrix(np.ndarray[_ShapeT_co, _DTypeT_co]): + __array_priority__: ClassVar[float] = 10.0 # pyright: ignore[reportIncompatibleMethodOverride] + + # + def __new__(cls, data: ArrayLike, dtype: DTypeLike | None = None, copy: bool = ...) -> Matrix: ... + + # + @overload # type: ignore[override] + def __getitem__(self, key: CanIndex | _ArrayLikeInt_co | tuple[CanIndex | _ArrayLikeInt_co, ...], /) -> Any: ... + @overload + def __getitem__(self, key: _ToIndex1 | _ToIndex2, /) -> matrix[_2D, _DTypeT_co]: ... + @overload + def __getitem__(self: Array[np.void], key: str, /) -> matrix[_ShapeT_co, np.dtype[Any]]: ... + @overload + def __getitem__(self: Array[np.void], key: list[str], /) -> matrix[_ShapeT_co, np.dtype[np.void]]: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @override + def __mul__(self, other: ArrayLike, /) -> Matrix: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + @override + def __rmul__(self, other: ArrayLike, /) -> Matrix: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + def __imul__(self, other: ArrayLike, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + + # + @override + def __pow__(self, other: ArrayLike, /) -> Matrix: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + @override + def __ipow__(self, other: ArrayLike, /) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload # type: ignore[override] + def sum(self, /, axis: None = None, dtype: DTypeLike | None = None, out: None = None) -> Any: ... + @overload + def sum(self, /, axis: _ToAxis, dtype: DTypeLike | None = None, out: None = None) -> Matrix: ... + @overload + def sum(self, /, axis: _ToAxis | None, dtype: DTypeLike, out: _ArrayT) -> _ArrayT: ... + @overload + def sum(self, /, axis: _ToAxis | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT) -> _ArrayT: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload # type: ignore[override] + def mean(self, /, axis: None = None, dtype: DTypeLike | None = None, out: None = None) -> Any: ... + @overload + def mean(self, /, axis: _ToAxis, dtype: DTypeLike | None = None, out: None = None) -> Matrix: ... + @overload + def mean(self, /, axis: _ToAxis | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ... + @overload + def mean(self, /, axis: _ToAxis | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT) -> _ArrayT: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload # type: ignore[override] + def std(self, /, axis: None = None, dtype: DTypeLike | None = None, out: None = None, ddof: float = 0) -> Any: ... + @overload + def std(self, /, axis: _ToAxis, dtype: DTypeLike | None = None, out: None = None, ddof: float = 0) -> Matrix: ... + @overload + def std(self, /, axis: _ToAxis | None, dtype: DTypeLike | None, out: _ArrayT, ddof: float = 0) -> _ArrayT: ... + @overload + def std( # pyright: ignore[reportIncompatibleMethodOverride] + self, + /, + axis: _ToAxis | None = None, + dtype: DTypeLike | None = None, + *, + out: _ArrayT, + ddof: float = 0, + ) -> _ArrayT: ... + + # + @overload # type: ignore[override] + def var(self, /, axis: None = None, dtype: DTypeLike | None = None, out: None = None, ddof: float = 0) -> Any: ... + @overload + def var(self, /, axis: _ToAxis, dtype: DTypeLike | None = None, out: None = None, ddof: float = 0) -> Matrix: ... + @overload + def var(self, /, axis: _ToAxis | None, dtype: DTypeLike | None, out: _ArrayT, ddof: float = 0) -> _ArrayT: ... + @overload + def var( # pyright: ignore[reportIncompatibleMethodOverride] + self, + /, + axis: _ToAxis | None = None, + dtype: DTypeLike | None = None, + *, + out: _ArrayT, + ddof: float = 0, + ) -> _ArrayT: ... + + # + @overload # type: ignore[override] + def prod(self, /, axis: None = None, dtype: DTypeLike | None = None, out: None = None) -> Any: ... + @overload + def prod(self, /, axis: _ToAxis, dtype: DTypeLike | None = None, out: None = None) -> Matrix: ... + @overload + def prod(self, /, axis: _ToAxis | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ... + @overload + def prod(self, /, axis: _ToAxis | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT) -> _ArrayT: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload # type: ignore[override] + def any(self, /, axis: None = None, out: None = None) -> np.bool: ... + @overload + def any(self, /, axis: _ToAxis, out: None = None) -> Matrix[np.bool]: ... + @overload + def any(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ... + @overload + def any(self, /, axis: _ToAxis | None = None, *, out: _ArrayT) -> _ArrayT: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload # type: ignore[override] + def all(self, /, axis: None = None, out: None = None) -> np.bool: ... + @overload + def all(self, /, axis: _ToAxis, out: None = None) -> Matrix[np.bool]: ... + @overload + def all(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ... + @overload + def all(self, /, axis: _ToAxis | None = None, *, out: _ArrayT) -> _ArrayT: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload # type: ignore[override] + def max(self: Array[_ScalarT], /, axis: None = None, out: None = None) -> _ScalarT: ... + @overload + def max(self, /, axis: _ToAxis, out: None = None) -> matrix[_2D, _DTypeT_co]: ... + @overload + def max(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ... + @overload + def max(self, /, axis: _ToAxis | None = None, *, out: _ArrayT) -> _ArrayT: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload # type: ignore[override] + def min(self: Array[_ScalarT], /, axis: None = None, out: None = None) -> _ScalarT: ... + @overload + def min(self, /, axis: _ToAxis, out: None = None) -> matrix[_2D, _DTypeT_co]: ... + @overload + def min(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ... + @overload + def min(self, /, axis: _ToAxis | None = None, *, out: _ArrayT) -> _ArrayT: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload # type: ignore[override] + def argmax(self: Array[_ScalarT], /, axis: None = None, out: None = None) -> np.intp: ... + @overload + def argmax(self, /, axis: _ToAxis, out: None = None) -> Matrix[np.intp]: ... + @overload + def argmax(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ... + @overload + def argmax(self, /, axis: _ToAxis | None = None, *, out: _ArrayT) -> _ArrayT: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload # type: ignore[override] + def argmin(self: Array[_ScalarT], /, axis: None = None, out: None = None) -> np.intp: ... + @overload + def argmin(self, /, axis: _ToAxis, out: None = None) -> Matrix[np.intp]: ... + @overload + def argmin(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ... + @overload + def argmin(self, /, axis: _ToAxis | None = None, *, out: _ArrayT) -> _ArrayT: ... # pyright: ignore[reportIncompatibleMethodOverride] + + # + @overload + def ptp(self: Array[_ScalarT], /, axis: None = None, out: None = None) -> _ScalarT: ... + @overload + def ptp(self, /, axis: _ToAxis, out: None = None) -> matrix[_2D, _DTypeT_co]: ... + @overload + def ptp(self, /, axis: _ToAxis | None, out: _ArrayT) -> _ArrayT: ... + @overload + def ptp(self, /, axis: _ToAxis | None = None, *, out: _ArrayT) -> _ArrayT: ... + + # + def tolist(self: _CanItem[_T]) -> list[list[_T]]: ... + + # + def squeeze(self, /, axis: _ToAxis | None = None) -> matrix[_2D, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + def ravel(self, /, order: _OrderKACF = "C") -> matrix[_2D, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + def flatten(self, /, order: _OrderKACF = "C") -> matrix[_2D, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + + # + @property + def T(self) -> matrix[_2D, _DTypeT_co]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] + def getT(self) -> matrix[_2D, _DTypeT_co]: ... + + # + @property + def H(self) -> matrix[_2D, _DTypeT_co]: ... + def getH(self) -> matrix[_2D, _DTypeT_co]: ... + + # + @property + def I(self) -> Matrix: ... + def getI(self) -> Matrix: ... + + # + @property + def A(self) -> np.ndarray[_ShapeT_co, _DTypeT_co]: ... + def getA(self) -> np.ndarray[_ShapeT_co, _DTypeT_co]: ... + + # + @property + def A1(self) -> np.ndarray[tuple[int], _DTypeT_co]: ... + def getA1(self) -> np.ndarray[tuple[int], _DTypeT_co]: ... + +# +@overload def bmat( - obj: str | Sequence[ArrayLike] | NDArray[Any], - ldict: Mapping[str, Any] | None = ..., - gdict: Mapping[str, Any] | None = ..., -) -> np.matrix[tuple[int, int], Any]: ... -def asmatrix(data: ArrayLike, dtype: DTypeLike = ...) -> matrix[tuple[int, int], Any]: ... + obj: str, + ldict: Mapping[str, Any] | None = None, + gdict: Mapping[str, Any] | None = None, +) -> Matrix: ... +@overload +def bmat( + obj: _ToArray1_1nd[_ScalarT], + ldict: Mapping[str, Any] | None = None, + gdict: Mapping[str, Any] | None = None, +) -> Matrix[_ScalarT]: ... +@overload +def bmat( + obj: Sequence_3nd[bool], + ldict: Mapping[str, Any] | None = None, + gdict: Mapping[str, Any] | None = None, +) -> Matrix[np.bool]: ... +@overload +def bmat( + obj: Sequence_3nd[Is[int]], + ldict: Mapping[str, Any] | None = None, + gdict: Mapping[str, Any] | None = None, +) -> Matrix[np.intp]: ... +@overload +def bmat( + obj: Sequence_3nd[Is[float]], + ldict: Mapping[str, Any] | None = None, + gdict: Mapping[str, Any] | None = None, +) -> Matrix[np.float64]: ... +@overload +def bmat( + obj: Sequence_3nd[Is[complex]], + ldict: Mapping[str, Any] | None = None, + gdict: Mapping[str, Any] | None = None, +) -> Matrix[np.complex128]: ... +@overload +def bmat( + obj: Sequence_3nd[Is[bytes]], + ldict: Mapping[str, Any] | None = None, + gdict: Mapping[str, Any] | None = None, +) -> Matrix[np.bytes_]: ... +@overload +def bmat( + obj: Sequence_3nd[Is[str]], + ldict: Mapping[str, Any] | None = None, + gdict: Mapping[str, Any] | None = None, +) -> Matrix[np.str_]: ... +@overload +def bmat( + obj: ToGeneric_3nd, + ldict: Mapping[str, Any] | None = None, + gdict: Mapping[str, Any] | None = None, +) -> Matrix: ... + +# +@overload +def asmatrix(data: _ToArray1_nd[_ScalarT], dtype: None = None) -> Matrix[_ScalarT]: ... # type: ignore[overload-overlap] +@overload +def asmatrix(data: ToGeneric_nd, dtype: _DTypeLike[_ScalarT]) -> Matrix[_ScalarT]: ... +@overload +def asmatrix(data: ToBool_nd, dtype: None = None) -> Matrix[np.bool]: ... +@overload +def asmatrix(data: ToIntP_nd, dtype: None = None) -> Matrix[np.intp]: ... +@overload +def asmatrix(data: ToFloat64_nd, dtype: None = None) -> Matrix[np.float64]: ... +@overload +def asmatrix(data: ToObject_nd, dtype: None = None) -> Matrix[np.object_]: ... +@overload +def asmatrix(data: ToComplex128_nd, dtype: None = None) -> Matrix[np.complex128]: ... +@overload +def asmatrix(data: ToBytes_nd, dtype: None = None) -> Matrix[np.bytes_]: ... +@overload +def asmatrix(data: ToStr_nd, dtype: None = None) -> Matrix[np.str_]: ... +@overload +def asmatrix(data: ToGeneric_nd, dtype: DTypeLike | None) -> Matrix: ... mat = asmatrix diff --git a/test/static/accept/matrix.pyi b/test/static/accept/matrix.pyi index 68d07fc1..c65e1c28 100644 --- a/test/static/accept/matrix.pyi +++ b/test/static/accept/matrix.pyi @@ -9,11 +9,11 @@ _Shape2D: TypeAlias = tuple[int, int] mat: np.matrix[_Shape2D, np.dtype[np.int64]] ar_f8: npt.NDArray[np.float64] -assert_type(mat * 5, np.matrix[_Shape2D, Any]) -assert_type(5 * mat, np.matrix[_Shape2D, Any]) +assert_type(mat * 5, np.matrix[_Shape2D, np.dtype[Any]]) +assert_type(5 * mat, np.matrix[_Shape2D, np.dtype[Any]]) mat *= 5 -assert_type(mat**5, np.matrix[_Shape2D, Any]) +assert_type(mat**5, np.matrix[_Shape2D, np.dtype[Any]]) mat **= 5 assert_type(mat.sum(), Any) @@ -29,11 +29,11 @@ assert_type(mat.argmax(), np.intp) assert_type(mat.argmin(), np.intp) assert_type(mat.ptp(), np.int64) -assert_type(mat.sum(axis=0), np.matrix[_Shape2D, Any]) -assert_type(mat.mean(axis=0), np.matrix[_Shape2D, Any]) -assert_type(mat.std(axis=0), np.matrix[_Shape2D, Any]) -assert_type(mat.var(axis=0), np.matrix[_Shape2D, Any]) -assert_type(mat.prod(axis=0), np.matrix[_Shape2D, Any]) +assert_type(mat.sum(axis=0), np.matrix[_Shape2D, np.dtype[Any]]) +assert_type(mat.mean(axis=0), np.matrix[_Shape2D, np.dtype[Any]]) +assert_type(mat.std(axis=0), np.matrix[_Shape2D, np.dtype[Any]]) +assert_type(mat.var(axis=0), np.matrix[_Shape2D, np.dtype[Any]]) +assert_type(mat.prod(axis=0), np.matrix[_Shape2D, np.dtype[Any]]) assert_type(mat.any(axis=0), np.matrix[_Shape2D, np.dtype[np.bool]]) assert_type(mat.all(axis=0), np.matrix[_Shape2D, np.dtype[np.bool]]) assert_type(mat.max(axis=0), np.matrix[_Shape2D, np.dtype[np.int64]]) @@ -56,18 +56,18 @@ assert_type(mat.argmin(out=ar_f8), npt.NDArray[np.float64]) assert_type(mat.ptp(out=ar_f8), npt.NDArray[np.float64]) assert_type(mat.T, np.matrix[_Shape2D, np.dtype[np.int64]]) -assert_type(mat.I, np.matrix[_Shape2D, Any]) +assert_type(mat.I, np.matrix[_Shape2D, np.dtype[Any]]) assert_type(mat.A, np.ndarray[_Shape2D, np.dtype[np.int64]]) -assert_type(mat.A1, npt.NDArray[np.int64]) +assert_type(mat.A1, np.ndarray[tuple[int], np.dtype[np.int64]]) assert_type(mat.H, np.matrix[_Shape2D, np.dtype[np.int64]]) assert_type(mat.getT(), np.matrix[_Shape2D, np.dtype[np.int64]]) -assert_type(mat.getI(), np.matrix[_Shape2D, Any]) +assert_type(mat.getI(), np.matrix[_Shape2D, np.dtype[Any]]) assert_type(mat.getA(), np.ndarray[_Shape2D, np.dtype[np.int64]]) -assert_type(mat.getA1(), npt.NDArray[np.int64]) +assert_type(mat.getA1(), np.ndarray[tuple[int], np.dtype[np.int64]]) assert_type(mat.getH(), np.matrix[_Shape2D, np.dtype[np.int64]]) -assert_type(np.bmat(ar_f8), np.matrix[_Shape2D, Any]) -assert_type(np.bmat([[0, 1, 2]]), np.matrix[_Shape2D, Any]) -assert_type(np.bmat("mat"), np.matrix[_Shape2D, Any]) +assert_type(np.bmat(ar_f8), np.matrix[_Shape2D, np.dtype[np.float64]]) +assert_type(np.bmat([[[0, 1, 2]]]), np.matrix[_Shape2D, np.dtype[np.intp]]) +assert_type(np.bmat("mat"), np.matrix[_Shape2D, np.dtype[Any]]) -assert_type(np.asmatrix(ar_f8, dtype=np.int64), np.matrix[_Shape2D, Any]) +assert_type(np.asmatrix(ar_f8, dtype=np.int64), np.matrix[_Shape2D, np.dtype[np.int64]])