🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3512,7 +3512,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
# See https://github.com/numpy/numpy-stubs/pull/80 for more details.
class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
@abstractmethod
def __new__(self) -> None: ...
def __new__(cls) -> Self: ...
def __hash__(self) -> int: ...
@overload
def __array__(self, dtype: None = None, /) -> ndarray[tuple[()], dtype[Self]]: ...
Expand Down
16 changes: 8 additions & 8 deletions numpy/lib/_histograms_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ def histogram_bin_edges(

def histogram(
a: ArrayLike,
bins: _BinKind | SupportsIndex | ArrayLike = ...,
range: tuple[float, float] | None = ...,
density: bool = ...,
weights: ArrayLike | None = ...,
bins: _BinKind | SupportsIndex | ArrayLike = 10,
range: tuple[float, float] | None = None,
density: bool | None = None,
weights: ArrayLike | None = None,
) -> tuple[NDArray[Any], NDArray[Any]]: ...

def histogramdd(
sample: ArrayLike,
bins: SupportsIndex | ArrayLike = ...,
range: Sequence[tuple[float, float]] = ...,
density: bool | None = ...,
weights: ArrayLike | None = ...,
bins: SupportsIndex | ArrayLike = 10,
range: Sequence[tuple[float, float]] | None = None,
density: bool | None = None,
weights: ArrayLike | None = None,
) -> tuple[NDArray[Any], tuple[NDArray[Any], ...]]: ...
18 changes: 10 additions & 8 deletions numpy/lib/_polynomial_impl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,22 @@ def polyfit(
x: _ArrayLikeFloat_co,
y: _ArrayLikeFloat_co,
deg: SupportsIndex | SupportsInt,
rcond: float | None = ...,
full: L[False] = ...,
w: _ArrayLikeFloat_co | None = ...,
cov: L[True, "unscaled"] = ...,
rcond: float | None = None,
full: L[False] = False,
w: _ArrayLikeFloat_co | None = None,
*,
cov: L[True, "unscaled"],
) -> _2Tup[NDArray[float64]]: ...
@overload
def polyfit(
x: _ArrayLikeComplex_co,
y: _ArrayLikeComplex_co,
deg: SupportsIndex | SupportsInt,
rcond: float | None = ...,
full: L[False] = ...,
w: _ArrayLikeFloat_co | None = ...,
cov: L[True, "unscaled"] = ...,
rcond: float | None = None,
full: L[False] = False,
w: _ArrayLikeFloat_co | None = None,
*,
cov: L[True, "unscaled"],
) -> _2Tup[NDArray[complex128]]: ...
@overload
def polyfit(
Expand Down
71 changes: 32 additions & 39 deletions numpy/linalg/_linalg.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ from numpy import (
)
from numpy._core.fromnumeric import matrix_transpose
from numpy._core.numeric import tensordot
from numpy._globals import _NoValueType
from numpy._typing import (
ArrayLike,
DTypeLike,
Expand Down Expand Up @@ -78,7 +79,7 @@ __all__ = [
"vecdot",
]

_ArrayT = TypeVar("_ArrayT", bound=NDArray[Any])
_NumberT = TypeVar("_NumberT", bound=np.number)

_ModeKind: TypeAlias = L["reduced", "complete", "r", "raw"]

Expand Down Expand Up @@ -182,33 +183,29 @@ def cholesky(a: _ArrayLikeFloat_co, /, *, upper: bool = False) -> NDArray[floati
def cholesky(a: _ArrayLikeComplex_co, /, *, upper: bool = False) -> NDArray[complexfloating]: ...

@overload
def outer(x1: _ArrayLike[Never], x2: _ArrayLike[Never]) -> NDArray[Any]: ...
def outer(x1: _ArrayLike[Never], x2: _ArrayLike[Never], /) -> NDArray[Any]: ...
@overload
def outer(x1: _ArrayLikeBool_co, x2: _ArrayLikeBool_co) -> NDArray[np.bool]: ...
def outer(x1: _ArrayLikeBool_co, x2: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ...
@overload
def outer(x1: _ArrayLikeUInt_co, x2: _ArrayLikeUInt_co) -> NDArray[unsignedinteger]: ...
def outer(x1: _ArrayLike[_NumberT], x2: _ArrayLike[_NumberT], /) -> NDArray[_NumberT]: ...
@overload
def outer(x1: _ArrayLikeInt_co, x2: _ArrayLikeInt_co) -> NDArray[signedinteger]: ...
def outer(x1: _ArrayLikeUInt_co, x2: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ...
@overload
def outer(x1: _ArrayLikeFloat_co, x2: _ArrayLikeFloat_co) -> NDArray[floating]: ...
def outer(x1: _ArrayLikeInt_co, x2: _ArrayLikeInt_co, /) -> NDArray[signedinteger]: ...
@overload
def outer(
x1: _ArrayLikeComplex_co,
x2: _ArrayLikeComplex_co,
) -> NDArray[complexfloating]: ...
def outer(x1: _ArrayLikeFloat_co, x2: _ArrayLikeFloat_co, /) -> NDArray[floating]: ...
@overload
def outer(
x1: _ArrayLikeTD64_co,
x2: _ArrayLikeTD64_co,
out: None = ...,
) -> NDArray[timedelta64]: ...
def outer(x1: _ArrayLikeComplex_co, x2: _ArrayLikeComplex_co, /) -> NDArray[complexfloating]: ...
@overload
def outer(x1: _ArrayLikeTD64_co, x2: _ArrayLikeTD64_co, /) -> NDArray[timedelta64]: ...
@overload
def outer(x1: _ArrayLikeObject_co, x2: _ArrayLikeObject_co) -> NDArray[object_]: ...
def outer(x1: _ArrayLikeObject_co, x2: _ArrayLikeObject_co, /) -> NDArray[object_]: ...
@overload
def outer(
x1: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co,
x2: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co,
) -> _ArrayT: ...
/,
) -> NDArray[Any]: ...

@overload
def qr(a: _ArrayLikeInt_co, mode: _ModeKind = ...) -> QRResult: ...
Expand Down Expand Up @@ -308,20 +305,26 @@ def matrix_rank(
@overload
def pinv(
a: _ArrayLikeInt_co,
rcond: _ArrayLikeFloat_co = ...,
hermitian: bool = ...,
rcond: _ArrayLikeFloat_co | None = None,
hermitian: bool = False,
*,
rtol: _ArrayLikeFloat_co | _NoValueType = ...,
) -> NDArray[float64]: ...
@overload
def pinv(
a: _ArrayLikeFloat_co,
rcond: _ArrayLikeFloat_co = ...,
hermitian: bool = ...,
rcond: _ArrayLikeFloat_co | None = None,
hermitian: bool = False,
*,
rtol: _ArrayLikeFloat_co | _NoValueType = ...,
) -> NDArray[floating]: ...
@overload
def pinv(
a: _ArrayLikeComplex_co,
rcond: _ArrayLikeFloat_co = ...,
hermitian: bool = ...,
rcond: _ArrayLikeFloat_co | None = None,
hermitian: bool = False,
*,
rtol: _ArrayLikeFloat_co | _NoValueType = ...,
) -> NDArray[complexfloating]: ...

# TODO: Returns a 2-tuple of scalars for 2D arrays and
Expand Down Expand Up @@ -461,22 +464,12 @@ def cross(
) -> NDArray[complexfloating]: ...

@overload
def matmul(
x1: _ArrayLikeInt_co,
x2: _ArrayLikeInt_co,
) -> NDArray[signedinteger]: ...
def matmul(x1: _ArrayLike[_NumberT], x2: _ArrayLike[_NumberT], /) -> NDArray[_NumberT]: ...
@overload
def matmul(
x1: _ArrayLikeUInt_co,
x2: _ArrayLikeUInt_co,
) -> NDArray[unsignedinteger]: ...
def matmul(x1: _ArrayLikeInt_co, x2: _ArrayLikeInt_co, /) -> NDArray[signedinteger]: ...
@overload
def matmul(
x1: _ArrayLikeFloat_co,
x2: _ArrayLikeFloat_co,
) -> NDArray[floating]: ...
def matmul(x1: _ArrayLikeUInt_co, x2: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ...
@overload
def matmul(
x1: _ArrayLikeComplex_co,
x2: _ArrayLikeComplex_co,
) -> NDArray[complexfloating]: ...
def matmul(x1: _ArrayLikeFloat_co, x2: _ArrayLikeFloat_co, /) -> NDArray[floating]: ...
@overload
def matmul(x1: _ArrayLikeComplex_co, x2: _ArrayLikeComplex_co, /) -> NDArray[complexfloating]: ...
12 changes: 6 additions & 6 deletions numpy/typing/tests/data/reveal/linalg.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ assert_type(np.linalg.cholesky(AR_i8), npt.NDArray[np.float64])
assert_type(np.linalg.cholesky(AR_f8), npt.NDArray[np.floating])
assert_type(np.linalg.cholesky(AR_c16), npt.NDArray[np.complexfloating])

assert_type(np.linalg.outer(AR_i8, AR_i8), npt.NDArray[np.signedinteger])
assert_type(np.linalg.outer(AR_f8, AR_f8), npt.NDArray[np.floating])
assert_type(np.linalg.outer(AR_c16, AR_c16), npt.NDArray[np.complexfloating])
assert_type(np.linalg.outer(AR_i8, AR_i8), npt.NDArray[np.int64])
assert_type(np.linalg.outer(AR_f8, AR_f8), npt.NDArray[np.float64])
assert_type(np.linalg.outer(AR_c16, AR_c16), npt.NDArray[np.complex128])
assert_type(np.linalg.outer(AR_b, AR_b), npt.NDArray[np.bool])
assert_type(np.linalg.outer(AR_O, AR_O), npt.NDArray[np.object_])
assert_type(np.linalg.outer(AR_i8, AR_m), npt.NDArray[np.timedelta64])
Expand Down Expand Up @@ -127,6 +127,6 @@ assert_type(np.linalg.cross(AR_i8, AR_i8), npt.NDArray[np.signedinteger])
assert_type(np.linalg.cross(AR_f8, AR_f8), npt.NDArray[np.floating])
assert_type(np.linalg.cross(AR_c16, AR_c16), npt.NDArray[np.complexfloating])

assert_type(np.linalg.matmul(AR_i8, AR_i8), npt.NDArray[np.signedinteger])
assert_type(np.linalg.matmul(AR_f8, AR_f8), npt.NDArray[np.floating])
assert_type(np.linalg.matmul(AR_c16, AR_c16), npt.NDArray[np.complexfloating])
assert_type(np.linalg.matmul(AR_i8, AR_i8), npt.NDArray[np.int64])
assert_type(np.linalg.matmul(AR_f8, AR_f8), npt.NDArray[np.float64])
assert_type(np.linalg.matmul(AR_c16, AR_c16), npt.NDArray[np.complex128])
Loading