diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-06-14 14:07:18 -0600 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-06-14 14:07:18 -0600 |
commit | 8c78b84968e580f24b3705378fb35705a434cdf1 (patch) | |
tree | c9f82beeb5a2c3f0301f7984d4b6d19539c35d23 /numpy/lib/arraypad.pyi | |
parent | 8bf3a4618f1de951c7a4ccdb8bc3e36825a1b744 (diff) | |
parent | 75f852edf94a7293e7982ad516bee314d7187c2d (diff) | |
download | numpy-8c78b84968e580f24b3705378fb35705a434cdf1.tar.gz |
Merge branch 'main' into matrix_rank-doc-fix
Diffstat (limited to 'numpy/lib/arraypad.pyi')
-rw-r--r-- | numpy/lib/arraypad.pyi | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/numpy/lib/arraypad.pyi b/numpy/lib/arraypad.pyi new file mode 100644 index 000000000..df9538dd7 --- /dev/null +++ b/numpy/lib/arraypad.pyi @@ -0,0 +1,94 @@ +import sys +from typing import ( + Any, + Dict, + List, + overload, + Tuple, + TypeVar, +) + +from numpy import ndarray, dtype, generic + +from numpy.typing import ( + ArrayLike, + NDArray, + _ArrayLikeInt, + _NestedSequence, + _SupportsArray, +) + +if sys.version_info >= (3, 8): + from typing import Literal as L, Protocol +else: + from typing_extensions import Literal as L, Protocol + +_SCT = TypeVar("_SCT", bound=generic) + +class _ModeFunc(Protocol): + def __call__( + self, + __vector: NDArray[Any], + __iaxis_pad_width: Tuple[int, int], + __iaxis: int, + __kwargs: Dict[str, Any], + ) -> None: ... + +_ModeKind = L[ + "constant", + "edge", + "linear_ramp", + "maximum", + "mean", + "median", + "minimum", + "reflect", + "symmetric", + "wrap", + "empty", +] + +_ArrayLike = _NestedSequence[_SupportsArray[dtype[_SCT]]] + +__all__: List[str] + +# TODO: In practice each keyword argument is exclusive to one or more +# specific modes. Consider adding more overloads to express this in the future. + +# Expand `**kwargs` into explicit keyword-only arguments +@overload +def pad( + array: _ArrayLike[_SCT], + pad_width: _ArrayLikeInt, + mode: _ModeKind = ..., + *, + stat_length: None | _ArrayLikeInt = ..., + constant_values: ArrayLike = ..., + end_values: ArrayLike = ..., + reflect_type: L["odd", "even"] = ..., +) -> NDArray[_SCT]: ... +@overload +def pad( + array: ArrayLike, + pad_width: _ArrayLikeInt, + mode: _ModeKind = ..., + *, + stat_length: None | _ArrayLikeInt = ..., + constant_values: ArrayLike = ..., + end_values: ArrayLike = ..., + reflect_type: L["odd", "even"] = ..., +) -> NDArray[Any]: ... +@overload +def pad( + array: _ArrayLike[_SCT], + pad_width: _ArrayLikeInt, + mode: _ModeFunc, + **kwargs: Any, +) -> NDArray[_SCT]: ... +@overload +def pad( + array: ArrayLike, + pad_width: _ArrayLikeInt, + mode: _ModeFunc, + **kwargs: Any, +) -> NDArray[Any]: ... |