Skip to content

Commit 8a80706

Browse files
authored
Merge pull request #248 from numpy/linalg
🏷️ stub the missing submodules of `numpy.linalg`
2 parents 0eba466 + 277af03 commit 8a80706

File tree

6 files changed

+477
-44
lines changed

6 files changed

+477
-44
lines changed

.mypyignore-todo

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,24 @@ numpy(\..+)?\.floating.as_integer_ratio
88
numpy(\..+)?\.complexfloating.__hash__
99
numpy(\..+)?\.complexfloating.__complex__
1010

11-
numpy(\.lib\._polynomial_impl|\.matlib)?\.poly1d\.integ
12-
1311
numpy._globals._CopyMode.IF_NEEDED
1412
numpy._globals._CopyMode.__bool__
1513

16-
numpy._pyinstaller.hook-numpy
17-
1814
numpy.compat
1915
numpy.compat.py3k
2016

17+
numpy._pyinstaller.hook-numpy
2118
numpy.ctypeslib._ctypeslib
19+
numpy.fft.helper
20+
21+
numpy(\.lib\._polynomial_impl|\.matlib)?\.poly1d\.integ
22+
numpy.lib(._arrayterator_impl)?.Arrayterator.__array__
23+
numpy.lib.(_array_utils_impl|array_utils).normalize_axis_tuple
24+
numpy.lib._iotools.NameValidator.defaultdeletechars
25+
numpy.lib.format.open_memmap
26+
numpy.lib.format.read_array(_header_(1|2)_0)?
27+
numpy.lib.mixins.NDArrayOperatorsMixin.__array_ufunc__
28+
numpy.lib.recfunctions.unstructured_to_structured
2229

2330
numpy.distutils
2431

@@ -34,22 +41,6 @@ numpy.f2py.crackfortran
3441
numpy.f2py.symbolic
3542
numpy.f2py.((cb|common|f90mod|use)_)?rules
3643

37-
numpy.fft.helper
38-
39-
numpy.lib(._arrayterator_impl)?.Arrayterator.__array__
40-
numpy.lib.(_array_utils_impl|array_utils).normalize_axis_tuple
41-
numpy.lib._iotools.NameValidator.defaultdeletechars
42-
numpy.lib.format.open_memmap
43-
numpy.lib.format.read_array(_header_(1|2)_0)?
44-
numpy.lib.mixins.NDArrayOperatorsMixin.__array_ufunc__
45-
numpy.lib.recfunctions.unstructured_to_structured
46-
47-
numpy.linalg(._linalg)?.cholesky
48-
numpy.linalg(._linalg)?.pinv
49-
numpy.linalg(._linalg)?.tensordot
50-
numpy.linalg.lapack_lite
51-
numpy.linalg.linalg
52-
5344
numpy.ma.testutils
5445
numpy.ma.timer_comparison
5546
numpy.ma.core._convert2ma.__doc__

src/numpy-stubs/_typing/_ufunc.pyi

Lines changed: 142 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ class _Kwargs3(_KwargsCommon, total=False):
7575
where: _ArrayLikeBool_co | None
7676
signature: _Tuple3[DTypeLike] | str | None
7777

78-
@type_check_only
79-
class _Kwargs3_g(_KwargsCommon, total=False):
80-
signature: _Tuple3[DTypeLike] | str | None
81-
8278
@type_check_only
8379
class _Kwargs4(_KwargsCommon, total=False):
8480
where: _ArrayLikeBool_co | None
@@ -94,6 +90,18 @@ class _Kwargs4_(_KwargsCommon, total=False):
9490
where: _ArrayLikeBool_co | None
9591
signature: _Tuple4_[DTypeLike] | str | None
9692

93+
@type_check_only
94+
class _Kwargs2_g(_KwargsCommon, total=False):
95+
signature: _Tuple2[DTypeLike] | str | None
96+
axes: Sequence[_Tuple2[SupportsIndex]]
97+
axis: SupportsIndex
98+
99+
@type_check_only
100+
class _Kwargs3_g(_KwargsCommon, total=False):
101+
signature: _Tuple3[DTypeLike] | str | None
102+
axes: Sequence[_Tuple2[SupportsIndex]]
103+
axis: SupportsIndex
104+
97105
###
98106
# ufunc method signatures
99107

@@ -592,9 +600,119 @@ class _Call22(Protocol):
592600
**kwds: Unpack[_Kwargs4],
593601
) -> _Tuple2[Any]: ...
594602

603+
@type_check_only
604+
class _Call11_g(Protocol):
605+
@overload
606+
def __call__(
607+
self,
608+
x: ArrayLike,
609+
/,
610+
out: _Out1[_ArrayT],
611+
*,
612+
dtype: None = None,
613+
**kwds: Unpack[_Kwargs2_g],
614+
) -> _ArrayT: ...
615+
@overload
616+
def __call__(
617+
self,
618+
x: ArrayLike,
619+
/,
620+
out: _Out1[_AnyArray | None] = None,
621+
*,
622+
dtype: DTypeLike | None = None,
623+
**kwds: Unpack[_Kwargs2_g],
624+
) -> Any: ...
625+
626+
@type_check_only
627+
class _Call12_g(Protocol):
628+
@overload
629+
def __call__(
630+
self,
631+
x: ArrayLike,
632+
out1: None = None,
633+
out2: None = None,
634+
/,
635+
out: _Tuple2[None] = (None, None),
636+
*,
637+
dtype: DTypeLike | None = None,
638+
**kwds: Unpack[_Kwargs3_g],
639+
) -> tuple[Any, Any]: ...
640+
@overload
641+
def __call__(
642+
self,
643+
x: ArrayLike,
644+
out1: None = None,
645+
out2: None = None,
646+
/,
647+
*,
648+
out: tuple[None, _ArrayT2],
649+
dtype: None = None,
650+
**kwds: Unpack[_Kwargs3_g],
651+
) -> tuple[Any, _ArrayT2]: ...
652+
@overload
653+
def __call__(
654+
self,
655+
x: ArrayLike,
656+
out1: None = None,
657+
out2: None = None,
658+
/,
659+
*,
660+
out: tuple[_ArrayT1, None],
661+
dtype: None = None,
662+
**kwds: Unpack[_Kwargs3_g],
663+
) -> tuple[_ArrayT1, Any]: ...
664+
@overload
665+
def __call__(
666+
self,
667+
x: ArrayLike,
668+
out1: None = None,
669+
out2: None = None,
670+
/,
671+
*,
672+
out: tuple[_ArrayT1, _ArrayT2],
673+
dtype: None = None,
674+
**kwds: Unpack[_Kwargs3_g],
675+
) -> tuple[_ArrayT1, _ArrayT2]: ...
676+
@overload
677+
def __call__(
678+
self,
679+
x: ArrayLike,
680+
out1: None,
681+
out2: _ArrayT2,
682+
/,
683+
*,
684+
out: _Tuple2[None] = (None, None),
685+
dtype: None = None,
686+
**kwds: Unpack[_Kwargs3_g],
687+
) -> tuple[Any, _ArrayT2]: ...
688+
@overload
689+
def __call__(
690+
self,
691+
x: ArrayLike,
692+
out1: _ArrayT1,
693+
out2: None,
694+
/,
695+
*,
696+
out: _Tuple2[None] = (None, None),
697+
dtype: None = None,
698+
**kwds: Unpack[_Kwargs3_g],
699+
) -> tuple[_ArrayT1, Any]: ...
700+
@overload
701+
def __call__(
702+
self,
703+
x: ArrayLike,
704+
out1: _ArrayT1,
705+
out2: _ArrayT2,
706+
/,
707+
*,
708+
out: _Tuple2[None] = (None, None),
709+
dtype: None = None,
710+
**kwds: Unpack[_Kwargs3_g],
711+
) -> tuple[_ArrayT1, _ArrayT2]: ...
712+
595713
@type_check_only
596714
class _Call21_g(Protocol):
597-
# Scalar for 1D array-likes; ndarray otherwise
715+
# scalar for 1D array-likes; ndarray otherwise
598716
@overload
599717
def __call__(
600718
self,
@@ -604,8 +722,6 @@ class _Call21_g(Protocol):
604722
out: _Out1[_ArrayT],
605723
*,
606724
dtype: None = None,
607-
axis: SupportsIndex = ...,
608-
axes: Sequence[_Tuple2[SupportsIndex]] = ...,
609725
**kwds: Unpack[_Kwargs3_g],
610726
) -> _ArrayT: ...
611727
@overload
@@ -617,8 +733,6 @@ class _Call21_g(Protocol):
617733
out: _Out1[_AnyArray | None] = None,
618734
*,
619735
dtype: DTypeLike | None = None,
620-
axis: SupportsIndex = ...,
621-
axes: Sequence[_Tuple2[SupportsIndex]] = ...,
622736
**kwds: Unpack[_Kwargs3_g],
623737
) -> Any: ...
624738

@@ -1074,7 +1188,6 @@ _CallT11 = TypeVar("_CallT11", bound=Callable[Concatenate[Any, ...], object], de
10741188
_CallT12 = TypeVar("_CallT12", bound=Callable[Concatenate[Any, ...], tuple[object, object]], default=_Call12)
10751189
_CallT21 = TypeVar("_CallT21", bound=Callable[Concatenate[Any, Any, ...], object], default=_Call21)
10761190
_CallT22 = TypeVar("_CallT22", bound=Callable[Concatenate[Any, Any, ...], tuple[object, object]], default=_Call22)
1077-
_CallT21G = TypeVar("_CallT21G", bound=Callable[Concatenate[Any, ...], object], default=_Call21_g)
10781191

10791192
_ufunc_1_1 = TypeAliasType(
10801193
"_ufunc_1_1",
@@ -1097,12 +1210,30 @@ _ufunc_2_2 = TypeAliasType(
10971210
type_params=(_CallT22,),
10981211
)
10991212

1213+
#
1214+
1215+
_CallT11G = TypeVar("_CallT11G", bound=Callable[Concatenate[Any, ...], object], default=_Call11_g)
1216+
_CallT12G = TypeVar("_CallT12G", bound=Callable[Concatenate[Any, ...], object], default=_Call12_g)
1217+
_CallT21G = TypeVar("_CallT21G", bound=Callable[Concatenate[Any, ...], object], default=_Call21_g)
1218+
1219+
_gufunc_1_1 = TypeAliasType(
1220+
"_gufunc_1_1",
1221+
np.ufunc[_CallT11G, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE],
1222+
type_params=(_CallT11G,),
1223+
)
1224+
_gufunc_1_2 = TypeAliasType(
1225+
"_gufunc_1_2",
1226+
np.ufunc[_CallT12G, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE],
1227+
type_params=(_CallT12G,),
1228+
)
11001229
_gufunc_2_1 = TypeAliasType(
11011230
"_gufunc_2_1",
1102-
np.ufunc[_CallT21G, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _Outer2],
1231+
np.ufunc[_CallT21G, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _Outer1],
11031232
type_params=(_CallT21G,),
11041233
)
11051234

1235+
#
1236+
11061237
_pyfunc_1_1 = TypeAliasType(
11071238
"_pyfunc_1_1",
11081239
np.ufunc[_Call11_py[_OutT], _At1, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE],

0 commit comments

Comments
 (0)