summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/multiarray.py18
-rw-r--r--numpy/core/multiarray.pyi378
-rw-r--r--numpy/core/numeric.pyi17
3 files changed, 387 insertions, 26 deletions
diff --git a/numpy/core/multiarray.py b/numpy/core/multiarray.py
index b7a3a8d67..78aa7a65c 100644
--- a/numpy/core/multiarray.py
+++ b/numpy/core/multiarray.py
@@ -249,7 +249,7 @@ def concatenate(arrays, axis=None, out=None, *, dtype=None, casting=None):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.inner)
def inner(a, b):
"""
- inner(a, b)
+ inner(a, b, /)
Inner product of two arrays.
@@ -341,7 +341,7 @@ def inner(a, b):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.where)
def where(condition, x=None, y=None):
"""
- where(condition, [x, y])
+ where(condition, [x, y], /)
Return elements chosen from `x` or `y` depending on `condition`.
@@ -613,7 +613,7 @@ def can_cast(from_, to, casting=None):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.min_scalar_type)
def min_scalar_type(a):
"""
- min_scalar_type(a)
+ min_scalar_type(a, /)
For scalar ``a``, returns the data type with the smallest size
and smallest scalar kind which can hold its value. For non-scalar
@@ -825,7 +825,7 @@ def dot(a, b, out=None):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.vdot)
def vdot(a, b):
"""
- vdot(a, b)
+ vdot(a, b, /)
Return the dot product of two vectors.
@@ -883,7 +883,7 @@ def vdot(a, b):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.bincount)
def bincount(x, weights=None, minlength=None):
"""
- bincount(x, weights=None, minlength=0)
+ bincount(x, /, weights=None, minlength=0)
Count number of occurrences of each value in array of non-negative ints.
@@ -1151,7 +1151,7 @@ def putmask(a, mask, values):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.packbits)
def packbits(a, axis=None, bitorder='big'):
"""
- packbits(a, axis=None, bitorder='big')
+ packbits(a, /, axis=None, bitorder='big')
Packs the elements of a binary-valued array into bits in a uint8 array.
@@ -1209,7 +1209,7 @@ def packbits(a, axis=None, bitorder='big'):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.unpackbits)
def unpackbits(a, axis=None, count=None, bitorder='big'):
"""
- unpackbits(a, axis=None, count=None, bitorder='big')
+ unpackbits(a, /, axis=None, count=None, bitorder='big')
Unpacks elements of a uint8 array into a binary-valued output array.
@@ -1293,7 +1293,7 @@ def unpackbits(a, axis=None, count=None, bitorder='big'):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.shares_memory)
def shares_memory(a, b, max_work=None):
"""
- shares_memory(a, b, max_work=None)
+ shares_memory(a, b, /, max_work=None)
Determine if two arrays share memory.
@@ -1368,7 +1368,7 @@ def shares_memory(a, b, max_work=None):
@array_function_from_c_func_and_dispatcher(_multiarray_umath.may_share_memory)
def may_share_memory(a, b, max_work=None):
"""
- may_share_memory(a, b, max_work=None)
+ may_share_memory(a, b, /, max_work=None)
Determine if two arrays might share memory
diff --git a/numpy/core/multiarray.pyi b/numpy/core/multiarray.pyi
new file mode 100644
index 000000000..70048d0e6
--- /dev/null
+++ b/numpy/core/multiarray.pyi
@@ -0,0 +1,378 @@
+# TODO: Sort out any and all missing functions in this namespace
+
+import sys
+from typing import (
+ Any,
+ Optional,
+ overload,
+ TypeVar,
+ List,
+ Type,
+ Union,
+ Sequence,
+ Tuple,
+)
+
+from numpy import (
+ busdaycalendar as busdaycalendar,
+ ndarray,
+ dtype,
+ str_,
+ bool_,
+ uint8,
+ intp,
+ float64,
+ timedelta64,
+ generic,
+ unsignedinteger,
+ signedinteger,
+ floating,
+ complexfloating,
+ _OrderKACF,
+ _OrderCF,
+ _CastingKind,
+ _ModeKind,
+)
+
+from numpy.typing import (
+ # Shapes
+ _ShapeLike,
+
+ # DTypes
+ DTypeLike,
+ _SupportsDType,
+
+ # Arrays
+ NDArray,
+ ArrayLike,
+ _SupportsArray,
+ _NestedSequence,
+ _ArrayLikeBool_co,
+ _ArrayLikeUInt_co,
+ _ArrayLikeInt_co,
+ _ArrayLikeFloat_co,
+ _ArrayLikeComplex_co,
+ _ArrayLikeTD64_co,
+ _ArrayLikeObject_co,
+ _IntLike_co,
+)
+
+if sys.version_info >= (3, 8):
+ from typing import SupportsIndex, Literal as L
+else:
+ from typing_extensions import SupportsIndex, Literal as L
+
+_SCT = TypeVar("_SCT", bound=generic)
+_ArrayType = TypeVar("_ArrayType", bound=NDArray[Any])
+
+_DTypeLike = Union[
+ dtype[_SCT],
+ Type[_SCT],
+ _SupportsDType[dtype[_SCT]],
+]
+_ArrayLike = _NestedSequence[_SupportsArray[dtype[_SCT]]]
+
+__all__: List[str]
+
+@overload
+def empty_like(
+ prototype: _ArrayLike[_SCT],
+ dtype: None = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ shape: Optional[_ShapeLike] = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def empty_like(
+ prototype: object,
+ dtype: None = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ shape: Optional[_ShapeLike] = ...,
+) -> NDArray[Any]: ...
+@overload
+def empty_like(
+ prototype: Any,
+ dtype: _DTypeLike[_SCT],
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ shape: Optional[_ShapeLike] = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def empty_like(
+ prototype: Any,
+ dtype: DTypeLike,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ shape: Optional[_ShapeLike] = ...,
+) -> NDArray[Any]: ...
+
+@overload
+def array(
+ object: _ArrayLike[_SCT],
+ dtype: None = ...,
+ *,
+ copy: bool = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ ndmin: int = ...,
+ like: ArrayLike = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def array(
+ object: object,
+ dtype: None = ...,
+ *,
+ copy: bool = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ ndmin: int = ...,
+ like: ArrayLike = ...,
+) -> NDArray[Any]: ...
+@overload
+def array(
+ object: Any,
+ dtype: _DTypeLike[_SCT],
+ *,
+ copy: bool = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ ndmin: int = ...,
+ like: ArrayLike = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def array(
+ object: Any,
+ dtype: DTypeLike,
+ *,
+ copy: bool = ...,
+ order: _OrderKACF = ...,
+ subok: bool = ...,
+ ndmin: int = ...,
+ like: ArrayLike = ...,
+) -> NDArray[Any]: ...
+
+@overload
+def zeros(
+ shape: _ShapeLike,
+ dtype: None = ...,
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[float64]: ...
+@overload
+def zeros(
+ shape: _ShapeLike,
+ dtype: _DTypeLike[_SCT],
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def zeros(
+ shape: _ShapeLike,
+ dtype: DTypeLike,
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[Any]: ...
+
+@overload
+def empty(
+ shape: _ShapeLike,
+ dtype: None = ...,
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[float64]: ...
+@overload
+def empty(
+ shape: _ShapeLike,
+ dtype: _DTypeLike[_SCT],
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[_SCT]: ...
+@overload
+def empty(
+ shape: _ShapeLike,
+ dtype: DTypeLike,
+ order: _OrderCF = ...,
+ *,
+ like: ArrayLike = ...,
+) -> NDArray[Any]: ...
+
+@overload
+def unravel_index( # type: ignore[misc]
+ indices: _IntLike_co,
+ shape: _ShapeLike,
+ order: _OrderCF = ...,
+) -> Tuple[intp, ...]: ...
+@overload
+def unravel_index(
+ indices: _ArrayLikeInt_co,
+ shape: _ShapeLike,
+ order: _OrderCF = ...,
+) -> Tuple[NDArray[intp], ...]: ...
+
+@overload
+def ravel_multi_index( # type: ignore[misc]
+ multi_index: Sequence[_IntLike_co],
+ dims: Sequence[SupportsIndex],
+ mode: Union[_ModeKind, Tuple[_ModeKind, ...]] = ...,
+ order: _OrderCF = ...,
+) -> intp: ...
+@overload
+def ravel_multi_index(
+ multi_index: Sequence[_ArrayLikeInt_co],
+ dims: Sequence[SupportsIndex],
+ mode: Union[_ModeKind, Tuple[_ModeKind, ...]] = ...,
+ order: _OrderCF = ...,
+) -> NDArray[intp]: ...
+
+@overload
+def concatenate( # type: ignore[misc]
+ __arrays: _ArrayLike[_SCT],
+ axis: Optional[SupportsIndex] = ...,
+ out: None = ...,
+ *,
+ dtype: None = ...,
+ casting: Optional[_CastingKind] = ...
+) -> NDArray[_SCT]: ...
+@overload
+def concatenate( # type: ignore[misc]
+ __arrays: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+ out: None = ...,
+ *,
+ dtype: None = ...,
+ casting: Optional[_CastingKind] = ...
+) -> NDArray[Any]: ...
+@overload
+def concatenate( # type: ignore[misc]
+ __arrays: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+ out: None = ...,
+ *,
+ dtype: _DTypeLike[_SCT],
+ casting: Optional[_CastingKind] = ...
+) -> NDArray[_SCT]: ...
+@overload
+def concatenate( # type: ignore[misc]
+ __arrays: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+ out: None = ...,
+ *,
+ dtype: DTypeLike,
+ casting: Optional[_CastingKind] = ...
+) -> NDArray[Any]: ...
+@overload
+def concatenate(
+ __arrays: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+ out: _ArrayType = ...,
+ *,
+ dtype: DTypeLike = ...,
+ casting: Optional[_CastingKind] = ...
+) -> _ArrayType: ...
+
+def inner(
+ __a: ArrayLike,
+ __b: ArrayLike,
+) -> Any: ...
+
+@overload
+def where(
+ __condition: ArrayLike,
+) -> Tuple[NDArray[intp], ...]: ...
+@overload
+def where(
+ __condition: ArrayLike,
+ __x: ArrayLike,
+ __y: ArrayLike,
+) -> NDArray[Any]: ...
+
+def lexsort(
+ keys: ArrayLike,
+ axis: Optional[SupportsIndex] = ...,
+) -> Any: ...
+
+def can_cast(
+ from_: Union[ArrayLike, DTypeLike],
+ to: DTypeLike,
+ casting: Optional[_CastingKind] = ...,
+) -> bool: ...
+
+def min_scalar_type(
+ __a: ArrayLike,
+) -> dtype[Any]: ...
+
+def result_type(
+ *arrays_and_dtypes: Union[ArrayLike, DTypeLike],
+) -> dtype[Any]: ...
+
+@overload
+def dot(a: ArrayLike, b: ArrayLike, out: None = ...) -> Any: ...
+@overload
+def dot(a: ArrayLike, b: ArrayLike, out: _ArrayType) -> _ArrayType: ...
+
+@overload
+def vdot(__a: _ArrayLikeBool_co, __b: _ArrayLikeBool_co) -> bool_: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeUInt_co, __b: _ArrayLikeUInt_co) -> unsignedinteger[Any]: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeInt_co, __b: _ArrayLikeInt_co) -> signedinteger[Any]: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeFloat_co, __b: _ArrayLikeFloat_co) -> floating[Any]: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeComplex_co, __b: _ArrayLikeComplex_co) -> complexfloating[Any, Any]: ... # type: ignore[misc]
+@overload
+def vdot(__a: _ArrayLikeTD64_co, __b: _ArrayLikeTD64_co) -> timedelta64: ...
+@overload
+def vdot(__a: _ArrayLikeObject_co, __b: Any) -> Any: ...
+@overload
+def vdot(__a: Any, __b: _ArrayLikeObject_co) -> Any: ...
+
+def bincount(
+ __x: ArrayLike,
+ weights: Optional[ArrayLike] = ...,
+ minlength: SupportsIndex = ...,
+) -> NDArray[intp]: ...
+
+def copyto(
+ dst: NDArray[Any],
+ src: ArrayLike,
+ casting: Optional[_CastingKind] = ...,
+ where: Optional[_ArrayLikeBool_co] = ...,
+) -> None: ...
+
+def putmask(
+ a: NDArray[Any],
+ mask: _ArrayLikeBool_co,
+ values: ArrayLike,
+) -> None: ...
+
+def packbits(
+ __a: _ArrayLikeInt_co,
+ axis: Optional[SupportsIndex] = ...,
+ bitorder: L["big", "little"] = ...,
+) -> NDArray[uint8]: ...
+
+def unpackbits(
+ __a: _ArrayLike[uint8],
+ axis: Optional[SupportsIndex] = ...,
+ count: Optional[SupportsIndex] = ...,
+ bitorder: L["big", "little"] = ...,
+) -> NDArray[uint8]: ...
+
+def shares_memory(
+ __a: object,
+ __b: object,
+ max_work: Optional[int] = ...,
+) -> bool: ...
+
+def may_share_memory(
+ __a: object,
+ __b: object,
+ max_work: Optional[int] = ...,
+) -> bool: ...
diff --git a/numpy/core/numeric.pyi b/numpy/core/numeric.pyi
index f57951434..3c2b553ec 100644
--- a/numpy/core/numeric.pyi
+++ b/numpy/core/numeric.pyi
@@ -67,23 +67,6 @@ def ones_like(
shape: Optional[_ShapeLike] = ...,
) -> ndarray: ...
-@overload
-def empty_like(
- a: _ArrayType,
- dtype: None = ...,
- order: _OrderKACF = ...,
- subok: Literal[True] = ...,
- shape: None = ...,
-) -> _ArrayType: ...
-@overload
-def empty_like(
- a: ArrayLike,
- dtype: DTypeLike = ...,
- order: _OrderKACF = ...,
- subok: bool = ...,
- shape: Optional[_ShapeLike] = ...,
-) -> ndarray: ...
-
def full(
shape: _ShapeLike,
fill_value: Any,