diff --git a/.mypyignore-todo b/.mypyignore-todo index 563820b0..c0227689 100644 --- a/.mypyignore-todo +++ b/.mypyignore-todo @@ -8,17 +8,24 @@ numpy(\..+)?\.floating.as_integer_ratio numpy(\..+)?\.complexfloating.__hash__ numpy(\..+)?\.complexfloating.__complex__ -numpy(\.lib\._polynomial_impl|\.matlib)?\.poly1d\.integ - numpy._globals._CopyMode.IF_NEEDED numpy._globals._CopyMode.__bool__ -numpy._pyinstaller.hook-numpy - numpy.compat numpy.compat.py3k +numpy._pyinstaller.hook-numpy numpy.ctypeslib._ctypeslib +numpy.fft.helper + +numpy(\.lib\._polynomial_impl|\.matlib)?\.poly1d\.integ +numpy.lib(._arrayterator_impl)?.Arrayterator.__array__ +numpy.lib.(_array_utils_impl|array_utils).normalize_axis_tuple +numpy.lib._iotools.NameValidator.defaultdeletechars +numpy.lib.format.open_memmap +numpy.lib.format.read_array(_header_(1|2)_0)? +numpy.lib.mixins.NDArrayOperatorsMixin.__array_ufunc__ +numpy.lib.recfunctions.unstructured_to_structured numpy.distutils @@ -34,22 +41,6 @@ numpy.f2py.crackfortran numpy.f2py.symbolic numpy.f2py.((cb|common|f90mod|use)_)?rules -numpy.fft.helper - -numpy.lib(._arrayterator_impl)?.Arrayterator.__array__ -numpy.lib.(_array_utils_impl|array_utils).normalize_axis_tuple -numpy.lib._iotools.NameValidator.defaultdeletechars -numpy.lib.format.open_memmap -numpy.lib.format.read_array(_header_(1|2)_0)? -numpy.lib.mixins.NDArrayOperatorsMixin.__array_ufunc__ -numpy.lib.recfunctions.unstructured_to_structured - -numpy.linalg(._linalg)?.cholesky -numpy.linalg(._linalg)?.pinv -numpy.linalg(._linalg)?.tensordot -numpy.linalg.lapack_lite -numpy.linalg.linalg - numpy.ma.testutils numpy.ma.timer_comparison numpy.ma.core._convert2ma.__doc__ diff --git a/src/numpy-stubs/_typing/_ufunc.pyi b/src/numpy-stubs/_typing/_ufunc.pyi index cfb1bc22..3ce53efe 100644 --- a/src/numpy-stubs/_typing/_ufunc.pyi +++ b/src/numpy-stubs/_typing/_ufunc.pyi @@ -75,10 +75,6 @@ class _Kwargs3(_KwargsCommon, total=False): where: _ArrayLikeBool_co | None signature: _Tuple3[DTypeLike] | str | None -@type_check_only -class _Kwargs3_g(_KwargsCommon, total=False): - signature: _Tuple3[DTypeLike] | str | None - @type_check_only class _Kwargs4(_KwargsCommon, total=False): where: _ArrayLikeBool_co | None @@ -94,6 +90,18 @@ class _Kwargs4_(_KwargsCommon, total=False): where: _ArrayLikeBool_co | None signature: _Tuple4_[DTypeLike] | str | None +@type_check_only +class _Kwargs2_g(_KwargsCommon, total=False): + signature: _Tuple2[DTypeLike] | str | None + axes: Sequence[_Tuple2[SupportsIndex]] + axis: SupportsIndex + +@type_check_only +class _Kwargs3_g(_KwargsCommon, total=False): + signature: _Tuple3[DTypeLike] | str | None + axes: Sequence[_Tuple2[SupportsIndex]] + axis: SupportsIndex + ### # ufunc method signatures @@ -592,9 +600,119 @@ class _Call22(Protocol): **kwds: Unpack[_Kwargs4], ) -> _Tuple2[Any]: ... +@type_check_only +class _Call11_g(Protocol): + @overload + def __call__( + self, + x: ArrayLike, + /, + out: _Out1[_ArrayT], + *, + dtype: None = None, + **kwds: Unpack[_Kwargs2_g], + ) -> _ArrayT: ... + @overload + def __call__( + self, + x: ArrayLike, + /, + out: _Out1[_AnyArray | None] = None, + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs2_g], + ) -> Any: ... + +@type_check_only +class _Call12_g(Protocol): + @overload + def __call__( + self, + x: ArrayLike, + out1: None = None, + out2: None = None, + /, + out: _Tuple2[None] = (None, None), + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs3_g], + ) -> tuple[Any, Any]: ... + @overload + def __call__( + self, + x: ArrayLike, + out1: None = None, + out2: None = None, + /, + *, + out: tuple[None, _ArrayT2], + dtype: None = None, + **kwds: Unpack[_Kwargs3_g], + ) -> tuple[Any, _ArrayT2]: ... + @overload + def __call__( + self, + x: ArrayLike, + out1: None = None, + out2: None = None, + /, + *, + out: tuple[_ArrayT1, None], + dtype: None = None, + **kwds: Unpack[_Kwargs3_g], + ) -> tuple[_ArrayT1, Any]: ... + @overload + def __call__( + self, + x: ArrayLike, + out1: None = None, + out2: None = None, + /, + *, + out: tuple[_ArrayT1, _ArrayT2], + dtype: None = None, + **kwds: Unpack[_Kwargs3_g], + ) -> tuple[_ArrayT1, _ArrayT2]: ... + @overload + def __call__( + self, + x: ArrayLike, + out1: None, + out2: _ArrayT2, + /, + *, + out: _Tuple2[None] = (None, None), + dtype: None = None, + **kwds: Unpack[_Kwargs3_g], + ) -> tuple[Any, _ArrayT2]: ... + @overload + def __call__( + self, + x: ArrayLike, + out1: _ArrayT1, + out2: None, + /, + *, + out: _Tuple2[None] = (None, None), + dtype: None = None, + **kwds: Unpack[_Kwargs3_g], + ) -> tuple[_ArrayT1, Any]: ... + @overload + def __call__( + self, + x: ArrayLike, + out1: _ArrayT1, + out2: _ArrayT2, + /, + *, + out: _Tuple2[None] = (None, None), + dtype: None = None, + **kwds: Unpack[_Kwargs3_g], + ) -> tuple[_ArrayT1, _ArrayT2]: ... + @type_check_only class _Call21_g(Protocol): - # Scalar for 1D array-likes; ndarray otherwise + # scalar for 1D array-likes; ndarray otherwise @overload def __call__( self, @@ -604,8 +722,6 @@ class _Call21_g(Protocol): out: _Out1[_ArrayT], *, dtype: None = None, - axis: SupportsIndex = ..., - axes: Sequence[_Tuple2[SupportsIndex]] = ..., **kwds: Unpack[_Kwargs3_g], ) -> _ArrayT: ... @overload @@ -617,8 +733,6 @@ class _Call21_g(Protocol): out: _Out1[_AnyArray | None] = None, *, dtype: DTypeLike | None = None, - axis: SupportsIndex = ..., - axes: Sequence[_Tuple2[SupportsIndex]] = ..., **kwds: Unpack[_Kwargs3_g], ) -> Any: ... @@ -1074,7 +1188,6 @@ _CallT11 = TypeVar("_CallT11", bound=Callable[Concatenate[Any, ...], object], de _CallT12 = TypeVar("_CallT12", bound=Callable[Concatenate[Any, ...], tuple[object, object]], default=_Call12) _CallT21 = TypeVar("_CallT21", bound=Callable[Concatenate[Any, Any, ...], object], default=_Call21) _CallT22 = TypeVar("_CallT22", bound=Callable[Concatenate[Any, Any, ...], tuple[object, object]], default=_Call22) -_CallT21G = TypeVar("_CallT21G", bound=Callable[Concatenate[Any, ...], object], default=_Call21_g) _ufunc_1_1 = TypeAliasType( "_ufunc_1_1", @@ -1097,12 +1210,30 @@ _ufunc_2_2 = TypeAliasType( type_params=(_CallT22,), ) +# + +_CallT11G = TypeVar("_CallT11G", bound=Callable[Concatenate[Any, ...], object], default=_Call11_g) +_CallT12G = TypeVar("_CallT12G", bound=Callable[Concatenate[Any, ...], object], default=_Call12_g) +_CallT21G = TypeVar("_CallT21G", bound=Callable[Concatenate[Any, ...], object], default=_Call21_g) + +_gufunc_1_1 = TypeAliasType( + "_gufunc_1_1", + np.ufunc[_CallT11G, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE], + type_params=(_CallT11G,), +) +_gufunc_1_2 = TypeAliasType( + "_gufunc_1_2", + np.ufunc[_CallT12G, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE], + type_params=(_CallT12G,), +) _gufunc_2_1 = TypeAliasType( "_gufunc_2_1", - np.ufunc[_CallT21G, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _Outer2], + np.ufunc[_CallT21G, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _Outer1], type_params=(_CallT21G,), ) +# + _pyfunc_1_1 = TypeAliasType( "_pyfunc_1_1", np.ufunc[_Call11_py[_OutT], _At1, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE], diff --git a/src/numpy-stubs/linalg/_linalg.pyi b/src/numpy-stubs/linalg/_linalg.pyi index 722fff68..a8f5357b 100644 --- a/src/numpy-stubs/linalg/_linalg.pyi +++ b/src/numpy-stubs/linalg/_linalg.pyi @@ -32,7 +32,10 @@ from _numtype import ( CoInteger_1d, CoInteger_1ds, CoInteger_1nd, + CoSInteger_1nd, CoTimeDelta_1d, + CoTimeDelta_1nd, + CoUInteger_1nd, Is, Sequence_2d, Sequence_2nd, @@ -84,6 +87,7 @@ from _numtype import ( ToObject_1d, ToObject_1nd, ToObject_2nd, + ToSInteger_1nd, ToTimeDelta_1d, ToTimeDelta_1nd, ToUInteger_1nd, @@ -101,7 +105,8 @@ from _numtype import ( _ToArray_3nd, ) from numpy._core.fromnumeric import matrix_transpose -from numpy._core.numeric import tensordot, vecdot +from numpy._core.numeric import vecdot +from numpy._globals import _NoValueType from numpy._typing import DTypeLike, _32Bit, _64Bit, _DTypeLike as _ToDType __all__ = [ @@ -222,6 +227,8 @@ _LstSqResult: TypeAlias = tuple[Array[_ScalarT], Array[_FloatingT], np.int32, Ar ### +fortran_int = np.intc + class EigResult(NamedTuple, Generic[_InexactT_co]): eigenvalues: Array[_InexactT_co] eigenvectors: _Array_2nd[_InexactT_co] @@ -245,6 +252,40 @@ class SlogdetResult(NamedTuple, Generic[_FloatingNDT_co, _InexactNDT_co]): class LinAlgError(ValueError): ... +# keep in sync with `numpy._core.numeric.tensordot` +@overload +def tensordot(x1: ToBool_1nd, x2: ToBool_1nd, /, *, axes: _Ax2 = 2) -> Array[np.bool]: ... +@overload +def tensordot(x1: ToUInteger_1nd, x2: CoUInteger_1nd, /, *, axes: _Ax2 = 2) -> Array[np.unsignedinteger]: ... +@overload +def tensordot(x1: CoUInteger_1nd, x2: ToUInteger_1nd, /, *, axes: _Ax2 = 2) -> Array[np.unsignedinteger]: ... +@overload +def tensordot(x1: ToSInteger_1nd, x2: CoSInteger_1nd, /, *, axes: _Ax2 = 2) -> Array[np.signedinteger]: ... +@overload +def tensordot(x1: CoSInteger_1nd, x2: ToSInteger_1nd, /, *, axes: _Ax2 = 2) -> Array[np.signedinteger]: ... +@overload +def tensordot(x1: ToFloating_1nd, x2: CoFloating_1nd, /, *, axes: _Ax2 = 2) -> Array[np.floating]: ... +@overload +def tensordot(x1: CoFloating_1nd, x2: ToFloating_1nd, /, *, axes: _Ax2 = 2) -> Array[np.floating]: ... +@overload +def tensordot(x1: ToComplex_1nd, x2: CoComplex_1nd, /, *, axes: _Ax2 = 2) -> Array[np.complexfloating]: ... +@overload +def tensordot(x1: CoComplex_1nd, x2: ToComplex_1nd, /, *, axes: _Ax2 = 2) -> Array[np.complexfloating]: ... +@overload +def tensordot(x1: ToTimeDelta_1nd, x2: CoTimeDelta_1nd, /, *, axes: _Ax2 = 2) -> Array[np.timedelta64]: ... +@overload +def tensordot(x1: CoTimeDelta_1nd, x2: ToTimeDelta_1nd, /, *, axes: _Ax2 = 2) -> Array[np.timedelta64]: ... +@overload +def tensordot(x1: ToObject_1nd, x2: ToObject_1nd, /, *, axes: _Ax2 = 2) -> Array[np.object_]: ... +@overload +def tensordot( + x1: CoComplex_1nd | CoTimeDelta_1nd | ToObject_1nd, + x2: CoComplex_1nd | CoTimeDelta_1nd | ToObject_1nd, + /, + *, + axes: _Ax2 = 2, +) -> Array[Any]: ... + # keep in sync with `solve` @overload def tensorsolve(a: _ToFloat64_1nd, b: CoFloat64_1nd, axes: _Axes | None = None) -> Array[np.float64]: ... @@ -316,7 +357,7 @@ def pinv( rcond: ToFloating_nd | None = None, hermitian: bool = False, *, - rtol: ToFloating_nd | None = None, + rtol: ToFloating_nd | _NoValueType = ..., ) -> _Array_2nd[np.float64]: ... @overload def pinv( @@ -324,7 +365,7 @@ def pinv( rcond: ToFloating_nd | None = None, hermitian: bool = False, *, - rtol: ToFloating_nd | None = None, + rtol: ToFloating_nd | _NoValueType = ..., ) -> _Array_2nd[np.complex128]: ... @overload def pinv( @@ -332,7 +373,7 @@ def pinv( rcond: ToFloating_nd | None = None, hermitian: bool = False, *, - rtol: ToFloating_nd | None = None, + rtol: ToFloating_nd | _NoValueType = ..., ) -> _Array_2nd[np.float32]: ... @overload def pinv( @@ -340,7 +381,7 @@ def pinv( rcond: ToFloating_nd | None = None, hermitian: bool = False, *, - rtol: ToFloating_nd | None = None, + rtol: ToFloating_nd | _NoValueType = ..., ) -> _Array_2nd[np.complex64]: ... @overload def pinv( @@ -348,7 +389,7 @@ def pinv( rcond: ToFloating_nd | None = None, hermitian: bool = False, *, - rtol: ToFloating_nd | None = None, + rtol: ToFloating_nd | _NoValueType = ..., ) -> _Array_2nd[np.floating]: ... @overload def pinv( @@ -356,7 +397,7 @@ def pinv( rcond: ToFloating_nd | None = None, hermitian: bool = False, *, - rtol: ToFloating_nd | None = None, + rtol: ToFloating_nd | _NoValueType = ..., ) -> _Array_2nd[np.inexact]: ... _PosInt: TypeAlias = L[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] @@ -392,17 +433,17 @@ def matrix_power(a: CoComplex_1nd | ToObject_1nd, n: CanIndex) -> _Array_2nd[Any # @overload -def cholesky(a: _ToFloat64_1nd) -> _Array_2nd[np.float64]: ... +def cholesky(a: _ToFloat64_1nd, /, *, upper: bool = False) -> _Array_2nd[np.float64]: ... @overload -def cholesky(a: ToComplex128_1nd) -> _Array_2nd[np.complex128]: ... +def cholesky(a: ToComplex128_1nd, /, *, upper: bool = False) -> _Array_2nd[np.complex128]: ... @overload -def cholesky(a: ToFloat32_1nd) -> _Array_2nd[np.float32]: ... +def cholesky(a: ToFloat32_1nd, /, *, upper: bool = False) -> _Array_2nd[np.float32]: ... @overload -def cholesky(a: ToComplex64_1nd) -> _Array_2nd[np.complex64]: ... +def cholesky(a: ToComplex64_1nd, /, *, upper: bool = False) -> _Array_2nd[np.complex64]: ... @overload -def cholesky(a: CoFloat64_1nd) -> _Array_2nd[np.floating]: ... +def cholesky(a: CoFloat64_1nd, /, *, upper: bool = False) -> _Array_2nd[np.floating]: ... @overload -def cholesky(a: CoComplex128_1nd) -> _Array_2nd[np.inexact]: ... +def cholesky(a: CoComplex128_1nd, /, *, upper: bool = False) -> _Array_2nd[np.inexact]: ... # @overload diff --git a/src/numpy-stubs/linalg/_umath_linalg.pyi b/src/numpy-stubs/linalg/_umath_linalg.pyi new file mode 100644 index 00000000..703b800e --- /dev/null +++ b/src/numpy-stubs/linalg/_umath_linalg.pyi @@ -0,0 +1,60 @@ +from typing import Final + +import numpy as np +from numpy._typing._ufunc import _gufunc_1_1, _gufunc_1_2, _gufunc_2_1 + +__version__: Final[str] = ... +_ilp64: Final[bool] = ... + +### +# 1 -> 1 + +# (m,m) -> () +det: Final[_gufunc_1_1] = ... +# (m,m) -> (m) +cholesky_lo: Final[_gufunc_1_1] = ... +cholesky_up: Final[_gufunc_1_1] = ... +eigvals: Final[_gufunc_1_1] = ... +eigvalsh_lo: Final[_gufunc_1_1] = ... +eigvalsh_up: Final[_gufunc_1_1] = ... +# (m,m) -> (m,m) +inv: Final[_gufunc_1_1] = ... +# (m,n) -> (p) +qr_r_raw: Final[_gufunc_1_1] = ... +svd: Final[_gufunc_1_1] = ... + +### +# 1 -> 2 + +# (m,m) -> (), () +slogdet: Final[_gufunc_1_2] = ... +# (m,m) -> (m), (m,m) +eig: Final[_gufunc_1_2] = ... +eigh_lo: Final[_gufunc_1_2] = ... +eigh_up: Final[_gufunc_1_2] = ... + +### +# 2 -> 1 + +# (m,n), (n) -> (m,m) +qr_complete: Final[_gufunc_2_1] = ... +# (m,n), (k) -> (m,k) +qr_reduced: Final[_gufunc_2_1] = ... +# (m,m), (m,n) -> (m,n) +solve: Final[_gufunc_2_1] = ... +# (m,m), (m) -> (m) +solve1: Final[_gufunc_2_1] = ... + +### +# 1 -> 3 + +# (m,n) -> (m,m), (p), (n,n) +svd_f: Final[np.ufunc] = ... +# (m,n) -> (m,p), (p), (p,n) +svd_s: Final[np.ufunc] = ... + +### +# 3 -> 4 + +# (m,n), (m,k), () -> (n,k), (k), (), (p) +lstsq: Final[np.ufunc] = ... diff --git a/src/numpy-stubs/linalg/lapack_lite.pyi b/src/numpy-stubs/linalg/lapack_lite.pyi new file mode 100644 index 00000000..f3e9a18b --- /dev/null +++ b/src/numpy-stubs/linalg/lapack_lite.pyi @@ -0,0 +1,141 @@ +from typing import Any, Final, TypedDict, type_check_only + +import numpy as np +from numpy._typing import NDArray + +from ._linalg import fortran_int + +### + +@type_check_only +class _GELSD(TypedDict): + m: int + n: int + nrhs: int + lda: int + ldb: int + rank: int + lwork: int + info: int + +@type_check_only +class _DGELSD(_GELSD): + dgelsd_: int + rcond: float + +@type_check_only +class _ZGELSD(_GELSD): + zgelsd_: int + +@type_check_only +class _GEQRF(TypedDict): + m: int + n: int + lda: int + lwork: int + info: int + +@type_check_only +class _DGEQRF(_GEQRF): + dgeqrf_: int + +@type_check_only +class _ZGEQRF(_GEQRF): + zgeqrf_: int + +@type_check_only +class _DORGQR(TypedDict): + dorgqr_: int + info: int + +@type_check_only +class _ZUNGQR(TypedDict): + zungqr_: int + info: int + +### + +_ilp64: Final[bool] = ... + +def dgelsd( + m: int, + n: int, + nrhs: int, + a: NDArray[np.float64], + lda: int, + b: NDArray[np.float64], + ldb: int, + s: NDArray[np.float64], + rcond: float, + rank: int, + work: NDArray[np.float64], + lwork: int, + iwork: NDArray[fortran_int], + info: int, +) -> _DGELSD: ... +def zgelsd( + m: int, + n: int, + nrhs: int, + a: NDArray[np.complex128], + lda: int, + b: NDArray[np.complex128], + ldb: int, + s: NDArray[np.float64], + rcond: float, + rank: int, + work: NDArray[np.complex128], + lwork: int, + rwork: NDArray[np.float64], + iwork: NDArray[fortran_int], + info: int, +) -> _ZGELSD: ... + +# +def dgeqrf( + m: int, + n: int, + a: NDArray[np.float64], # in/out, shape: (lda, n) + lda: int, + tau: NDArray[np.float64], # out, shape: (min(m, n),) + work: NDArray[np.float64], # out, shape: (max(1, lwork),) + lwork: int, + info: int, # out +) -> _DGEQRF: ... +def zgeqrf( + m: int, + n: int, + a: NDArray[np.complex128], # in/out, shape: (lda, n) + lda: int, + tau: NDArray[np.complex128], # out, shape: (min(m, n),) + work: NDArray[np.complex128], # out, shape: (max(1, lwork),) + lwork: int, + info: int, # out +) -> _ZGEQRF: ... + +# +def dorgqr( + m: int, # >=0 + n: int, # m >= n >= 0 + k: int, # n >= k >= 0 + a: NDArray[np.float64], # in/out, shape: (lda, n) + lda: int, # >= max(1, m) + tau: NDArray[np.float64], # in, shape: (k,) + work: NDArray[np.float64], # out, shape: (max(1, lwork),) + lwork: int, + info: int, # out +) -> _DORGQR: ... +def zungqr( + m: int, + n: int, + k: int, + a: NDArray[np.complex128], + lda: int, + tau: NDArray[np.complex128], + work: NDArray[np.complex128], + lwork: int, + info: int, +) -> _ZUNGQR: ... + +# +def xerbla(srname: Any, info: int) -> None: ... diff --git a/src/numpy-stubs/linalg/linalg.pyi b/src/numpy-stubs/linalg/linalg.pyi new file mode 100644 index 00000000..dbe9becf --- /dev/null +++ b/src/numpy-stubs/linalg/linalg.pyi @@ -0,0 +1,69 @@ +from ._linalg import ( + LinAlgError, + cholesky, + cond, + cross, + det, + diagonal, + eig, + eigh, + eigvals, + eigvalsh, + inv, + lstsq, + matmul, + matrix_norm, + matrix_power, + matrix_rank, + matrix_transpose, + multi_dot, + norm, + outer, + pinv, + qr, + slogdet, + solve, + svd, + svdvals, + tensordot, + tensorinv, + tensorsolve, + trace, + vecdot, + vector_norm, +) + +__all__ = [ + "LinAlgError", + "cholesky", + "cond", + "cross", + "det", + "diagonal", + "eig", + "eigh", + "eigvals", + "eigvalsh", + "inv", + "lstsq", + "matmul", + "matrix_norm", + "matrix_power", + "matrix_rank", + "matrix_transpose", + "multi_dot", + "norm", + "outer", + "pinv", + "qr", + "slogdet", + "solve", + "svd", + "svdvals", + "tensordot", + "tensorinv", + "tensorsolve", + "trace", + "vecdot", + "vector_norm", +]