done
This commit is contained in:
		| @ -0,0 +1,126 @@ | ||||
| from typing import Any | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| b_ = np.bool() | ||||
| dt = np.datetime64(0, "D") | ||||
| td = np.timedelta64(0, "D") | ||||
|  | ||||
| AR_b: npt.NDArray[np.bool] | ||||
| AR_u: npt.NDArray[np.uint32] | ||||
| AR_i: npt.NDArray[np.int64] | ||||
| AR_f: npt.NDArray[np.longdouble] | ||||
| AR_c: npt.NDArray[np.complex128] | ||||
| AR_m: npt.NDArray[np.timedelta64] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
|  | ||||
| ANY: Any | ||||
|  | ||||
| AR_LIKE_b: list[bool] | ||||
| AR_LIKE_u: list[np.uint32] | ||||
| AR_LIKE_i: list[int] | ||||
| AR_LIKE_f: list[float] | ||||
| AR_LIKE_c: list[complex] | ||||
| AR_LIKE_m: list[np.timedelta64] | ||||
| AR_LIKE_M: list[np.datetime64] | ||||
|  | ||||
| # Array subtraction | ||||
|  | ||||
| # NOTE: mypys `NoReturn` errors are, unfortunately, not that great | ||||
| _1 = AR_b - AR_LIKE_b  # type: ignore[var-annotated] | ||||
| _2 = AR_LIKE_b - AR_b  # type: ignore[var-annotated] | ||||
| AR_i - bytes()  # type: ignore[operator] | ||||
|  | ||||
| AR_f - AR_LIKE_m  # type: ignore[operator] | ||||
| AR_f - AR_LIKE_M  # type: ignore[operator] | ||||
| AR_c - AR_LIKE_m  # type: ignore[operator] | ||||
| AR_c - AR_LIKE_M  # type: ignore[operator] | ||||
|  | ||||
| AR_m - AR_LIKE_f  # type: ignore[operator] | ||||
| AR_M - AR_LIKE_f  # type: ignore[operator] | ||||
| AR_m - AR_LIKE_c  # type: ignore[operator] | ||||
| AR_M - AR_LIKE_c  # type: ignore[operator] | ||||
|  | ||||
| AR_m - AR_LIKE_M  # type: ignore[operator] | ||||
| AR_LIKE_m - AR_M  # type: ignore[operator] | ||||
|  | ||||
| # array floor division | ||||
|  | ||||
| AR_M // AR_LIKE_b  # type: ignore[operator] | ||||
| AR_M // AR_LIKE_u  # type: ignore[operator] | ||||
| AR_M // AR_LIKE_i  # type: ignore[operator] | ||||
| AR_M // AR_LIKE_f  # type: ignore[operator] | ||||
| AR_M // AR_LIKE_c  # type: ignore[operator] | ||||
| AR_M // AR_LIKE_m  # type: ignore[operator] | ||||
| AR_M // AR_LIKE_M  # type: ignore[operator] | ||||
|  | ||||
| AR_b // AR_LIKE_M  # type: ignore[operator] | ||||
| AR_u // AR_LIKE_M  # type: ignore[operator] | ||||
| AR_i // AR_LIKE_M  # type: ignore[operator] | ||||
| AR_f // AR_LIKE_M  # type: ignore[operator] | ||||
| AR_c // AR_LIKE_M  # type: ignore[operator] | ||||
| AR_m // AR_LIKE_M  # type: ignore[operator] | ||||
| AR_M // AR_LIKE_M  # type: ignore[operator] | ||||
|  | ||||
| _3 = AR_m // AR_LIKE_b  # type: ignore[var-annotated] | ||||
| AR_m // AR_LIKE_c  # type: ignore[operator] | ||||
|  | ||||
| AR_b // AR_LIKE_m  # type: ignore[operator] | ||||
| AR_u // AR_LIKE_m  # type: ignore[operator] | ||||
| AR_i // AR_LIKE_m  # type: ignore[operator] | ||||
| AR_f // AR_LIKE_m  # type: ignore[operator] | ||||
| AR_c // AR_LIKE_m  # type: ignore[operator] | ||||
|  | ||||
| # regression tests for https://github.com/numpy/numpy/issues/28957 | ||||
| AR_c // 2  # type: ignore[operator] | ||||
| AR_c // AR_i  # type: ignore[operator] | ||||
| AR_c // AR_c  # type: ignore[operator] | ||||
|  | ||||
| # Array multiplication | ||||
|  | ||||
| AR_b *= AR_LIKE_u  # type: ignore[arg-type] | ||||
| AR_b *= AR_LIKE_i  # type: ignore[arg-type] | ||||
| AR_b *= AR_LIKE_f  # type: ignore[arg-type] | ||||
| AR_b *= AR_LIKE_c  # type: ignore[arg-type] | ||||
| AR_b *= AR_LIKE_m  # type: ignore[arg-type] | ||||
|  | ||||
| AR_u *= AR_LIKE_f  # type: ignore[arg-type] | ||||
| AR_u *= AR_LIKE_c  # type: ignore[arg-type] | ||||
| AR_u *= AR_LIKE_m  # type: ignore[arg-type] | ||||
|  | ||||
| AR_i *= AR_LIKE_f  # type: ignore[arg-type] | ||||
| AR_i *= AR_LIKE_c  # type: ignore[arg-type] | ||||
| AR_i *= AR_LIKE_m  # type: ignore[arg-type] | ||||
|  | ||||
| AR_f *= AR_LIKE_c  # type: ignore[arg-type] | ||||
| AR_f *= AR_LIKE_m  # type: ignore[arg-type] | ||||
|  | ||||
| # Array power | ||||
|  | ||||
| AR_b **= AR_LIKE_b  # type: ignore[misc] | ||||
| AR_b **= AR_LIKE_u  # type: ignore[misc] | ||||
| AR_b **= AR_LIKE_i  # type: ignore[misc] | ||||
| AR_b **= AR_LIKE_f  # type: ignore[misc] | ||||
| AR_b **= AR_LIKE_c  # type: ignore[misc] | ||||
|  | ||||
| AR_u **= AR_LIKE_f  # type: ignore[arg-type] | ||||
| AR_u **= AR_LIKE_c  # type: ignore[arg-type] | ||||
|  | ||||
| AR_i **= AR_LIKE_f  # type: ignore[arg-type] | ||||
| AR_i **= AR_LIKE_c  # type: ignore[arg-type] | ||||
|  | ||||
| AR_f **= AR_LIKE_c  # type: ignore[arg-type] | ||||
|  | ||||
| # Scalars | ||||
|  | ||||
| b_ - b_  # type: ignore[call-overload] | ||||
|  | ||||
| dt + dt  # type: ignore[operator] | ||||
| td - dt  # type: ignore[operator] | ||||
| td % 1  # type: ignore[operator] | ||||
| td / dt  # type: ignore[operator] | ||||
| td % dt  # type: ignore[operator] | ||||
|  | ||||
| -b_  # type: ignore[operator] | ||||
| +b_  # type: ignore[operator] | ||||
| @ -0,0 +1,34 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| a: npt.NDArray[np.float64] | ||||
| generator = (i for i in range(10)) | ||||
|  | ||||
| np.require(a, requirements=1)  # type: ignore[call-overload] | ||||
| np.require(a, requirements="TEST")  # type: ignore[arg-type] | ||||
|  | ||||
| np.zeros("test")  # type: ignore[arg-type] | ||||
| np.zeros()  # type: ignore[call-overload] | ||||
|  | ||||
| np.ones("test")  # type: ignore[arg-type] | ||||
| np.ones()  # type: ignore[call-overload] | ||||
|  | ||||
| np.array(0, float, True)  # type: ignore[call-overload] | ||||
|  | ||||
| np.linspace(None, 'bob')  # type: ignore[call-overload] | ||||
| np.linspace(0, 2, num=10.0)  # type: ignore[call-overload] | ||||
| np.linspace(0, 2, endpoint='True')  # type: ignore[call-overload] | ||||
| np.linspace(0, 2, retstep=b'False')  # type: ignore[call-overload] | ||||
| np.linspace(0, 2, dtype=0)  # type: ignore[call-overload] | ||||
| np.linspace(0, 2, axis=None)  # type: ignore[call-overload] | ||||
|  | ||||
| np.logspace(None, 'bob')  # type: ignore[call-overload] | ||||
| np.logspace(0, 2, base=None)  # type: ignore[call-overload] | ||||
|  | ||||
| np.geomspace(None, 'bob')  # type: ignore[call-overload] | ||||
|  | ||||
| np.stack(generator)  # type: ignore[call-overload] | ||||
| np.hstack({1, 2})  # type: ignore[call-overload] | ||||
| np.vstack(1)  # type: ignore[call-overload] | ||||
|  | ||||
| np.array([1], like=1)  # type: ignore[call-overload] | ||||
| @ -0,0 +1,15 @@ | ||||
| import numpy as np | ||||
| from numpy._typing import ArrayLike | ||||
|  | ||||
| class A: ... | ||||
|  | ||||
| x1: ArrayLike = (i for i in range(10))  # type: ignore[assignment] | ||||
| x2: ArrayLike = A()  # type: ignore[assignment] | ||||
| x3: ArrayLike = {1: "foo", 2: "bar"}  # type: ignore[assignment] | ||||
|  | ||||
| scalar = np.int64(1) | ||||
| scalar.__array__(dtype=np.float64)  # type: ignore[call-overload] | ||||
| array = np.array([1]) | ||||
| array.__array__(dtype=np.float64)  # type: ignore[call-overload] | ||||
|  | ||||
| array.setfield(np.eye(1), np.int32, (0, 1))  # type: ignore[arg-type] | ||||
| @ -0,0 +1,6 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_i8: npt.NDArray[np.int64] | ||||
|  | ||||
| np.pad(AR_i8, 2, mode="bob")  # type: ignore[call-overload] | ||||
| @ -0,0 +1,16 @@ | ||||
| from collections.abc import Callable | ||||
| from typing import Any | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR: npt.NDArray[np.float64] | ||||
| func1: Callable[[Any], str] | ||||
| func2: Callable[[np.integer], str] | ||||
|  | ||||
| np.array2string(AR, style=None)  # type: ignore[call-overload] | ||||
| np.array2string(AR, legacy="1.14")  # type: ignore[call-overload] | ||||
| np.array2string(AR, sign="*")  # type: ignore[call-overload] | ||||
| np.array2string(AR, floatmode="default")  # type: ignore[call-overload] | ||||
| np.array2string(AR, formatter={"A": func1})  # type: ignore[call-overload] | ||||
| np.array2string(AR, formatter={"float": func2})  # type: ignore[call-overload] | ||||
| @ -0,0 +1,14 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_i8: npt.NDArray[np.int64] | ||||
| ar_iter = np.lib.Arrayterator(AR_i8) | ||||
|  | ||||
| np.lib.Arrayterator(np.int64())  # type: ignore[arg-type] | ||||
| ar_iter.shape = (10, 5)  # type: ignore[misc] | ||||
| ar_iter[None]  # type: ignore[index] | ||||
| ar_iter[None, 1]  # type: ignore[index] | ||||
| ar_iter[np.intp()]  # type: ignore[index] | ||||
| ar_iter[np.intp(), ...]  # type: ignore[index] | ||||
| ar_iter[AR_i8]  # type: ignore[index] | ||||
| ar_iter[AR_i8, :]  # type: ignore[index] | ||||
| @ -0,0 +1,17 @@ | ||||
| import numpy as np | ||||
|  | ||||
| i8 = np.int64() | ||||
| i4 = np.int32() | ||||
| u8 = np.uint64() | ||||
| b_ = np.bool() | ||||
| i = int() | ||||
|  | ||||
| f8 = np.float64() | ||||
|  | ||||
| b_ >> f8  # type: ignore[call-overload] | ||||
| i8 << f8  # type: ignore[call-overload] | ||||
| i | f8  # type: ignore[operator] | ||||
| i8 ^ f8  # type: ignore[call-overload] | ||||
| u8 & f8  # type: ignore[call-overload] | ||||
| ~f8  # type: ignore[operator] | ||||
| # TODO: Certain mixes like i4 << u8 go to float and thus should fail | ||||
| @ -0,0 +1,65 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_U: npt.NDArray[np.str_] | ||||
| AR_S: npt.NDArray[np.bytes_] | ||||
|  | ||||
| np.char.equal(AR_U, AR_S)  # type: ignore[arg-type] | ||||
| np.char.not_equal(AR_U, AR_S)  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.greater_equal(AR_U, AR_S)  # type: ignore[arg-type] | ||||
| np.char.less_equal(AR_U, AR_S)  # type: ignore[arg-type] | ||||
| np.char.greater(AR_U, AR_S)  # type: ignore[arg-type] | ||||
| np.char.less(AR_U, AR_S)  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.encode(AR_S)  # type: ignore[arg-type] | ||||
| np.char.decode(AR_U)  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.join(AR_U, b"_")  # type: ignore[arg-type] | ||||
| np.char.join(AR_S, "_")  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.ljust(AR_U, 5, fillchar=b"a")  # type: ignore[arg-type] | ||||
| np.char.ljust(AR_S, 5, fillchar="a")  # type: ignore[arg-type] | ||||
| np.char.rjust(AR_U, 5, fillchar=b"a")  # type: ignore[arg-type] | ||||
| np.char.rjust(AR_S, 5, fillchar="a")  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.lstrip(AR_U, chars=b"a")  # type: ignore[arg-type] | ||||
| np.char.lstrip(AR_S, chars="a")  # type: ignore[arg-type] | ||||
| np.char.strip(AR_U, chars=b"a")  # type: ignore[arg-type] | ||||
| np.char.strip(AR_S, chars="a")  # type: ignore[arg-type] | ||||
| np.char.rstrip(AR_U, chars=b"a")  # type: ignore[arg-type] | ||||
| np.char.rstrip(AR_S, chars="a")  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.partition(AR_U, b"a")  # type: ignore[arg-type] | ||||
| np.char.partition(AR_S, "a")  # type: ignore[arg-type] | ||||
| np.char.rpartition(AR_U, b"a")  # type: ignore[arg-type] | ||||
| np.char.rpartition(AR_S, "a")  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.replace(AR_U, b"_", b"-")  # type: ignore[arg-type] | ||||
| np.char.replace(AR_S, "_", "-")  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.split(AR_U, b"_")  # type: ignore[arg-type] | ||||
| np.char.split(AR_S, "_")  # type: ignore[arg-type] | ||||
| np.char.rsplit(AR_U, b"_")  # type: ignore[arg-type] | ||||
| np.char.rsplit(AR_S, "_")  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.count(AR_U, b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| np.char.count(AR_S, "a", end=9)  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.endswith(AR_U, b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| np.char.endswith(AR_S, "a", end=9)  # type: ignore[arg-type] | ||||
| np.char.startswith(AR_U, b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| np.char.startswith(AR_S, "a", end=9)  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.find(AR_U, b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| np.char.find(AR_S, "a", end=9)  # type: ignore[arg-type] | ||||
| np.char.rfind(AR_U, b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| np.char.rfind(AR_S, "a", end=9)  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.index(AR_U, b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| np.char.index(AR_S, "a", end=9)  # type: ignore[arg-type] | ||||
| np.char.rindex(AR_U, b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| np.char.rindex(AR_S, "a", end=9)  # type: ignore[arg-type] | ||||
|  | ||||
| np.char.isdecimal(AR_S)  # type: ignore[arg-type] | ||||
| np.char.isnumeric(AR_S)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,62 @@ | ||||
| from typing import Any | ||||
| import numpy as np | ||||
|  | ||||
| AR_U: np.char.chararray[tuple[Any, ...], np.dtype[np.str_]] | ||||
| AR_S: np.char.chararray[tuple[Any, ...], np.dtype[np.bytes_]] | ||||
|  | ||||
| AR_S.encode()  # type: ignore[misc] | ||||
| AR_U.decode()  # type: ignore[misc] | ||||
|  | ||||
| AR_U.join(b"_")  # type: ignore[arg-type] | ||||
| AR_S.join("_")  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U.ljust(5, fillchar=b"a")  # type: ignore[arg-type] | ||||
| AR_S.ljust(5, fillchar="a")  # type: ignore[arg-type] | ||||
| AR_U.rjust(5, fillchar=b"a")  # type: ignore[arg-type] | ||||
| AR_S.rjust(5, fillchar="a")  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U.lstrip(chars=b"a")  # type: ignore[arg-type] | ||||
| AR_S.lstrip(chars="a")  # type: ignore[arg-type] | ||||
| AR_U.strip(chars=b"a")  # type: ignore[arg-type] | ||||
| AR_S.strip(chars="a")  # type: ignore[arg-type] | ||||
| AR_U.rstrip(chars=b"a")  # type: ignore[arg-type] | ||||
| AR_S.rstrip(chars="a")  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U.partition(b"a")  # type: ignore[arg-type] | ||||
| AR_S.partition("a")  # type: ignore[arg-type] | ||||
| AR_U.rpartition(b"a")  # type: ignore[arg-type] | ||||
| AR_S.rpartition("a")  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U.replace(b"_", b"-")  # type: ignore[arg-type] | ||||
| AR_S.replace("_", "-")  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U.split(b"_")  # type: ignore[arg-type] | ||||
| AR_S.split("_")  # type: ignore[arg-type] | ||||
| AR_S.split(1)  # type: ignore[arg-type] | ||||
| AR_U.rsplit(b"_")  # type: ignore[arg-type] | ||||
| AR_S.rsplit("_")  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U.count(b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| AR_S.count("a", end=9)  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U.endswith(b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| AR_S.endswith("a", end=9)  # type: ignore[arg-type] | ||||
| AR_U.startswith(b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| AR_S.startswith("a", end=9)  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U.find(b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| AR_S.find("a", end=9)  # type: ignore[arg-type] | ||||
| AR_U.rfind(b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| AR_S.rfind("a", end=9)  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U.index(b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| AR_S.index("a", end=9)  # type: ignore[arg-type] | ||||
| AR_U.rindex(b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| AR_S.rindex("a", end=9)  # type: ignore[arg-type] | ||||
|  | ||||
| AR_U == AR_S  # type: ignore[operator] | ||||
| AR_U != AR_S  # type: ignore[operator] | ||||
| AR_U >= AR_S  # type: ignore[operator] | ||||
| AR_U <= AR_S  # type: ignore[operator] | ||||
| AR_U > AR_S  # type: ignore[operator] | ||||
| AR_U < AR_S  # type: ignore[operator] | ||||
| @ -0,0 +1,27 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_i: npt.NDArray[np.int64] | ||||
| AR_f: npt.NDArray[np.float64] | ||||
| AR_c: npt.NDArray[np.complex128] | ||||
| AR_m: npt.NDArray[np.timedelta64] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
|  | ||||
| AR_f > AR_m  # type: ignore[operator] | ||||
| AR_c > AR_m  # type: ignore[operator] | ||||
|  | ||||
| AR_m > AR_f  # type: ignore[operator] | ||||
| AR_m > AR_c  # type: ignore[operator] | ||||
|  | ||||
| AR_i > AR_M  # type: ignore[operator] | ||||
| AR_f > AR_M  # type: ignore[operator] | ||||
| AR_m > AR_M  # type: ignore[operator] | ||||
|  | ||||
| AR_M > AR_i  # type: ignore[operator] | ||||
| AR_M > AR_f  # type: ignore[operator] | ||||
| AR_M > AR_m  # type: ignore[operator] | ||||
|  | ||||
| AR_i > str()  # type: ignore[operator] | ||||
| AR_i > bytes()  # type: ignore[operator] | ||||
| str() > AR_M  # type: ignore[operator] | ||||
| bytes() > AR_M  # type: ignore[operator] | ||||
| @ -0,0 +1,3 @@ | ||||
| import numpy as np | ||||
|  | ||||
| np.little_endian = np.little_endian  # type: ignore[misc] | ||||
| @ -0,0 +1,15 @@ | ||||
| from pathlib import Path | ||||
| import numpy as np | ||||
|  | ||||
| path: Path | ||||
| d1: np.lib.npyio.DataSource | ||||
|  | ||||
| d1.abspath(path)  # type: ignore[arg-type] | ||||
| d1.abspath(b"...")  # type: ignore[arg-type] | ||||
|  | ||||
| d1.exists(path)  # type: ignore[arg-type] | ||||
| d1.exists(b"...")  # type: ignore[arg-type] | ||||
|  | ||||
| d1.open(path, "r")  # type: ignore[arg-type] | ||||
| d1.open(b"...", encoding="utf8")  # type: ignore[arg-type] | ||||
| d1.open(None, newline="/n")  # type: ignore[arg-type] | ||||
| @ -0,0 +1,17 @@ | ||||
| import numpy as np | ||||
|  | ||||
| class Test1: | ||||
|     not_dtype = np.dtype(float) | ||||
|  | ||||
| class Test2: | ||||
|     dtype = float | ||||
|  | ||||
| np.dtype(Test1())  # type: ignore[call-overload] | ||||
| np.dtype(Test2())  # type: ignore[arg-type] | ||||
|  | ||||
| np.dtype(  # type: ignore[call-overload] | ||||
|     { | ||||
|         "field1": (float, 1), | ||||
|         "field2": (int, 3), | ||||
|     } | ||||
| ) | ||||
| @ -0,0 +1,12 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_i: npt.NDArray[np.int64] | ||||
| AR_f: npt.NDArray[np.float64] | ||||
| AR_m: npt.NDArray[np.timedelta64] | ||||
| AR_U: npt.NDArray[np.str_] | ||||
|  | ||||
| np.einsum("i,i->i", AR_i, AR_m)  # type: ignore[arg-type] | ||||
| np.einsum("i,i->i", AR_f, AR_f, dtype=np.int32)  # type: ignore[arg-type] | ||||
| np.einsum("i,i->i", AR_i, AR_i, out=AR_U)  # type: ignore[type-var] | ||||
| np.einsum("i,i->i", AR_i, AR_i, out=AR_U, casting="unsafe")  # type: ignore[call-overload] | ||||
| @ -0,0 +1,20 @@ | ||||
| import numpy as np | ||||
| import numpy._typing as npt | ||||
|  | ||||
| class Index: | ||||
|     def __index__(self) -> int: ... | ||||
|  | ||||
| a: np.flatiter[npt.NDArray[np.float64]] | ||||
| supports_array: npt._SupportsArray[np.dtype[np.float64]] | ||||
|  | ||||
| a.base = object()  # type: ignore[assignment, misc] | ||||
| a.coords = object()  # type: ignore[assignment, misc] | ||||
| a.index = object()  # type: ignore[assignment, misc] | ||||
| a.copy(order='C')  # type: ignore[call-arg] | ||||
|  | ||||
| # NOTE: Contrary to `ndarray.__getitem__` its counterpart in `flatiter` | ||||
| # does not accept objects with the `__array__` or `__index__` protocols; | ||||
| # boolean indexing is just plain broken (gh-17175) | ||||
| a[np.bool()]  # type: ignore[index] | ||||
| a[Index()]  # type: ignore[call-overload] | ||||
| a[supports_array]  # type: ignore[index] | ||||
| @ -0,0 +1,148 @@ | ||||
| """Tests for :mod:`numpy._core.fromnumeric`.""" | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| A = np.array(True, ndmin=2, dtype=bool) | ||||
| A.setflags(write=False) | ||||
| AR_U: npt.NDArray[np.str_] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
| AR_f4: npt.NDArray[np.float32] | ||||
|  | ||||
| a = np.bool(True) | ||||
|  | ||||
| np.take(a, None)  # type: ignore[call-overload] | ||||
| np.take(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.take(A, out=1)  # type: ignore[call-overload] | ||||
| np.take(A, mode="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.reshape(a, None)  # type: ignore[call-overload] | ||||
| np.reshape(A, 1, order="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.choose(a, None)  # type: ignore[call-overload] | ||||
| np.choose(a, out=1.0)  # type: ignore[call-overload] | ||||
| np.choose(A, mode="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.repeat(a, None)  # type: ignore[call-overload] | ||||
| np.repeat(A, 1, axis=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.swapaxes(A, None, 1)  # type: ignore[call-overload] | ||||
| np.swapaxes(A, 1, [0])  # type: ignore[call-overload] | ||||
|  | ||||
| np.transpose(A, axes=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.partition(a, None)  # type: ignore[call-overload] | ||||
| np.partition(a, 0, axis="bob") # type: ignore[call-overload] | ||||
| np.partition(A, 0, kind="bob")  # type: ignore[call-overload] | ||||
| np.partition(A, 0, order=range(5))  # type: ignore[arg-type] | ||||
|  | ||||
| np.argpartition(a, None)  # type: ignore[arg-type] | ||||
| np.argpartition(a, 0, axis="bob")  # type: ignore[arg-type] | ||||
| np.argpartition(A, 0, kind="bob") # type: ignore[arg-type] | ||||
| np.argpartition(A, 0, order=range(5))  # type: ignore[arg-type] | ||||
|  | ||||
| np.sort(A, axis="bob")  # type: ignore[call-overload] | ||||
| np.sort(A, kind="bob")  # type: ignore[call-overload] | ||||
| np.sort(A, order=range(5)) # type: ignore[arg-type] | ||||
|  | ||||
| np.argsort(A, axis="bob")  # type: ignore[arg-type] | ||||
| np.argsort(A, kind="bob")  # type: ignore[arg-type] | ||||
| np.argsort(A, order=range(5))  # type: ignore[arg-type] | ||||
|  | ||||
| np.argmax(A, axis="bob")  # type: ignore[call-overload] | ||||
| np.argmax(A, kind="bob")  # type: ignore[call-overload] | ||||
| np.argmax(A, out=AR_f4)  # type: ignore[type-var] | ||||
|  | ||||
| np.argmin(A, axis="bob")  # type: ignore[call-overload] | ||||
| np.argmin(A, kind="bob")  # type: ignore[call-overload] | ||||
| np.argmin(A, out=AR_f4)  # type: ignore[type-var] | ||||
|  | ||||
| np.searchsorted(A[0], 0, side="bob")  # type: ignore[call-overload] | ||||
| np.searchsorted(A[0], 0, sorter=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.resize(A, 1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.squeeze(A, 1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.diagonal(A, offset=None)  # type: ignore[call-overload] | ||||
| np.diagonal(A, axis1="bob")  # type: ignore[call-overload] | ||||
| np.diagonal(A, axis2=[])  # type: ignore[call-overload] | ||||
|  | ||||
| np.trace(A, offset=None)  # type: ignore[call-overload] | ||||
| np.trace(A, axis1="bob")  # type: ignore[call-overload] | ||||
| np.trace(A, axis2=[])  # type: ignore[call-overload] | ||||
|  | ||||
| np.ravel(a, order="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.nonzero(0)  # type: ignore[arg-type] | ||||
|  | ||||
| np.compress([True], A, axis=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.clip(a, 1, 2, out=1)  # type: ignore[call-overload] | ||||
|  | ||||
| np.sum(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.sum(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.sum(a, initial=[1])  # type: ignore[call-overload] | ||||
|  | ||||
| np.all(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.all(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.all(a, out=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.any(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.any(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.any(a, out=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.cumsum(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.cumsum(a, dtype=1.0)  # type: ignore[call-overload] | ||||
| np.cumsum(a, out=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.ptp(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.ptp(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.ptp(a, out=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.amax(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.amax(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.amax(a, out=1.0)  # type: ignore[call-overload] | ||||
| np.amax(a, initial=[1.0])  # type: ignore[call-overload] | ||||
| np.amax(a, where=[1.0])  # type: ignore[arg-type] | ||||
|  | ||||
| np.amin(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.amin(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.amin(a, out=1.0)  # type: ignore[call-overload] | ||||
| np.amin(a, initial=[1.0])  # type: ignore[call-overload] | ||||
| np.amin(a, where=[1.0])  # type: ignore[arg-type] | ||||
|  | ||||
| np.prod(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.prod(a, out=False)  # type: ignore[call-overload] | ||||
| np.prod(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.prod(a, initial=int)  # type: ignore[call-overload] | ||||
| np.prod(a, where=1.0)  # type: ignore[call-overload] | ||||
| np.prod(AR_U)  # type: ignore[arg-type] | ||||
|  | ||||
| np.cumprod(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.cumprod(a, out=False)  # type: ignore[call-overload] | ||||
| np.cumprod(AR_U)  # type: ignore[arg-type] | ||||
|  | ||||
| np.size(a, axis=1.0)  # type: ignore[arg-type] | ||||
|  | ||||
| np.around(a, decimals=1.0)  # type: ignore[call-overload] | ||||
| np.around(a, out=type)  # type: ignore[call-overload] | ||||
| np.around(AR_U)  # type: ignore[arg-type] | ||||
|  | ||||
| np.mean(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.mean(a, out=False)  # type: ignore[call-overload] | ||||
| np.mean(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.mean(AR_U)  # type: ignore[arg-type] | ||||
| np.mean(AR_M)  # type: ignore[arg-type] | ||||
|  | ||||
| np.std(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.std(a, out=False)  # type: ignore[call-overload] | ||||
| np.std(a, ddof='test')  # type: ignore[call-overload] | ||||
| np.std(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.std(AR_U)  # type: ignore[arg-type] | ||||
|  | ||||
| np.var(a, axis=1.0)  # type: ignore[call-overload] | ||||
| np.var(a, out=False)  # type: ignore[call-overload] | ||||
| np.var(a, ddof='test')  # type: ignore[call-overload] | ||||
| np.var(a, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.var(AR_U)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,12 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_i8: npt.NDArray[np.int64] | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
|  | ||||
| np.histogram_bin_edges(AR_i8, range=(0, 1, 2))  # type: ignore[arg-type] | ||||
|  | ||||
| np.histogram(AR_i8, range=(0, 1, 2))  # type: ignore[arg-type] | ||||
|  | ||||
| np.histogramdd(AR_i8, range=(0, 1))  # type: ignore[arg-type] | ||||
| np.histogramdd(AR_i8, range=[(0, 1, 2)])  # type: ignore[list-item] | ||||
| @ -0,0 +1,14 @@ | ||||
| import numpy as np | ||||
|  | ||||
| AR_LIKE_i: list[int] | ||||
| AR_LIKE_f: list[float] | ||||
|  | ||||
| np.ndindex([1, 2, 3])  # type: ignore[call-overload] | ||||
| np.unravel_index(AR_LIKE_f, (1, 2, 3))  # type: ignore[arg-type] | ||||
| np.ravel_multi_index(AR_LIKE_i, (1, 2, 3), mode="bob")  # type: ignore[call-overload] | ||||
| np.mgrid[1]  # type: ignore[index] | ||||
| np.mgrid[...]  # type: ignore[index] | ||||
| np.ogrid[1]  # type: ignore[index] | ||||
| np.ogrid[...]  # type: ignore[index] | ||||
| np.fill_diagonal(AR_LIKE_f, 2)  # type: ignore[arg-type] | ||||
| np.diag_indices(1.0)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,62 @@ | ||||
| from typing import Any | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
| AR_c16: npt.NDArray[np.complex128] | ||||
| AR_m: npt.NDArray[np.timedelta64] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
| AR_O: npt.NDArray[np.object_] | ||||
| AR_b_list: list[npt.NDArray[np.bool]] | ||||
|  | ||||
| def fn_none_i(a: None, /) -> npt.NDArray[Any]: ... | ||||
| def fn_ar_i(a: npt.NDArray[np.float64], posarg: int, /) -> npt.NDArray[Any]: ... | ||||
|  | ||||
| np.average(AR_m)  # type: ignore[arg-type] | ||||
| np.select(1, [AR_f8])  # type: ignore[arg-type] | ||||
| np.angle(AR_m)  # type: ignore[arg-type] | ||||
| np.unwrap(AR_m)  # type: ignore[arg-type] | ||||
| np.unwrap(AR_c16)  # type: ignore[arg-type] | ||||
| np.trim_zeros(1)  # type: ignore[arg-type] | ||||
| np.place(1, [True], 1.5)  # type: ignore[arg-type] | ||||
| np.vectorize(1)  # type: ignore[arg-type] | ||||
| np.place(AR_f8, slice(None), 5)  # type: ignore[arg-type] | ||||
|  | ||||
| np.piecewise(AR_f8, True, [fn_ar_i], 42)  # type: ignore[call-overload] | ||||
| # TODO: enable these once mypy actually supports ParamSpec (released in 2021) | ||||
| # NOTE: pyright correctly reports errors for these (`reportCallIssue`) | ||||
| # np.piecewise(AR_f8, AR_b_list, [fn_none_i])  # type: ignore[call-overload]s | ||||
| # np.piecewise(AR_f8, AR_b_list, [fn_ar_i])  # type: ignore[call-overload] | ||||
| # np.piecewise(AR_f8, AR_b_list, [fn_ar_i], 3.14)  # type: ignore[call-overload] | ||||
| # np.piecewise(AR_f8, AR_b_list, [fn_ar_i], 42, None)  # type: ignore[call-overload] | ||||
| # np.piecewise(AR_f8, AR_b_list, [fn_ar_i], 42, _=None)  # type: ignore[call-overload] | ||||
|  | ||||
| np.interp(AR_f8, AR_c16, AR_f8)  # type: ignore[arg-type] | ||||
| np.interp(AR_c16, AR_f8, AR_f8)  # type: ignore[arg-type] | ||||
| np.interp(AR_f8, AR_f8, AR_f8, period=AR_c16)  # type: ignore[call-overload] | ||||
| np.interp(AR_f8, AR_f8, AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.cov(AR_m)  # type: ignore[arg-type] | ||||
| np.cov(AR_O)  # type: ignore[arg-type] | ||||
| np.corrcoef(AR_m)  # type: ignore[arg-type] | ||||
| np.corrcoef(AR_O)  # type: ignore[arg-type] | ||||
| np.corrcoef(AR_f8, bias=True)  # type: ignore[call-overload] | ||||
| np.corrcoef(AR_f8, ddof=2)  # type: ignore[call-overload] | ||||
| np.blackman(1j)  # type: ignore[arg-type] | ||||
| np.bartlett(1j)  # type: ignore[arg-type] | ||||
| np.hanning(1j)  # type: ignore[arg-type] | ||||
| np.hamming(1j)  # type: ignore[arg-type] | ||||
| np.hamming(AR_c16)  # type: ignore[arg-type] | ||||
| np.kaiser(1j, 1)  # type: ignore[arg-type] | ||||
| np.sinc(AR_O)  # type: ignore[arg-type] | ||||
| np.median(AR_M)  # type: ignore[arg-type] | ||||
|  | ||||
| np.percentile(AR_f8, 50j)  # type: ignore[call-overload] | ||||
| np.percentile(AR_f8, 50, interpolation="bob")  # type: ignore[call-overload] | ||||
| np.quantile(AR_f8, 0.5j)  # type: ignore[call-overload] | ||||
| np.quantile(AR_f8, 0.5, interpolation="bob")  # type: ignore[call-overload] | ||||
| np.meshgrid(AR_f8, AR_f8, indexing="bob")  # type: ignore[call-overload] | ||||
| np.delete(AR_f8, AR_f8)  # type: ignore[arg-type] | ||||
| np.insert(AR_f8, AR_f8, 1.5)  # type: ignore[arg-type] | ||||
| np.digitize(AR_f8, 1j)  # type: ignore[call-overload] | ||||
| @ -0,0 +1,29 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
| AR_c16: npt.NDArray[np.complex128] | ||||
| AR_O: npt.NDArray[np.object_] | ||||
| AR_U: npt.NDArray[np.str_] | ||||
|  | ||||
| poly_obj: np.poly1d | ||||
|  | ||||
| np.polymul(AR_f8, AR_U)  # type: ignore[arg-type] | ||||
| np.polydiv(AR_f8, AR_U)  # type: ignore[arg-type] | ||||
|  | ||||
| 5**poly_obj  # type: ignore[operator] | ||||
|  | ||||
| np.polyint(AR_U)  # type: ignore[arg-type] | ||||
| np.polyint(AR_f8, m=1j)  # type: ignore[call-overload] | ||||
|  | ||||
| np.polyder(AR_U)  # type: ignore[arg-type] | ||||
| np.polyder(AR_f8, m=1j)  # type: ignore[call-overload] | ||||
|  | ||||
| np.polyfit(AR_O, AR_f8, 1)  # type: ignore[arg-type] | ||||
| np.polyfit(AR_f8, AR_f8, 1, rcond=1j)  # type: ignore[call-overload] | ||||
| np.polyfit(AR_f8, AR_f8, 1, w=AR_c16)  # type: ignore[arg-type] | ||||
| np.polyfit(AR_f8, AR_f8, 1, cov="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.polyval(AR_f8, AR_U)  # type: ignore[arg-type] | ||||
| np.polyadd(AR_f8, AR_U)  # type: ignore[arg-type] | ||||
| np.polysub(AR_f8, AR_U)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,3 @@ | ||||
| import numpy.lib.array_utils as array_utils | ||||
|  | ||||
| array_utils.byte_bounds(1)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,6 @@ | ||||
| from numpy.lib import NumpyVersion | ||||
|  | ||||
| version: NumpyVersion | ||||
|  | ||||
| NumpyVersion(b"1.8.0")  # type: ignore[arg-type] | ||||
| version >= b"1.8.0"  # type: ignore[operator] | ||||
| @ -0,0 +1,48 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
| AR_O: npt.NDArray[np.object_] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
|  | ||||
| np.linalg.tensorsolve(AR_O, AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.solve(AR_O, AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.tensorinv(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.inv(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.matrix_power(AR_M, 5)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.cholesky(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.qr(AR_O)  # type: ignore[arg-type] | ||||
| np.linalg.qr(AR_f8, mode="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.linalg.eigvals(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.eigvalsh(AR_O)  # type: ignore[arg-type] | ||||
| np.linalg.eigvalsh(AR_O, UPLO="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.linalg.eig(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.eigh(AR_O)  # type: ignore[arg-type] | ||||
| np.linalg.eigh(AR_O, UPLO="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.linalg.svd(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.cond(AR_O)  # type: ignore[arg-type] | ||||
| np.linalg.cond(AR_f8, p="bob")  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.matrix_rank(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.pinv(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.slogdet(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.det(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.linalg.norm(AR_f8, ord="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.linalg.multi_dot([AR_M])  # type: ignore[list-item] | ||||
							
								
								
									
										143
									
								
								lib/python3.11/site-packages/numpy/typing/tests/data/fail/ma.pyi
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								lib/python3.11/site-packages/numpy/typing/tests/data/fail/ma.pyi
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,143 @@ | ||||
| from typing import TypeAlias, TypeVar | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| from numpy._typing import _Shape | ||||
|  | ||||
| _ScalarT = TypeVar("_ScalarT", bound=np.generic) | ||||
| MaskedArray: TypeAlias = np.ma.MaskedArray[_Shape, np.dtype[_ScalarT]] | ||||
|  | ||||
| MAR_1d_f8: np.ma.MaskedArray[tuple[int], np.dtype[np.float64]] | ||||
| MAR_b: MaskedArray[np.bool] | ||||
| MAR_c: MaskedArray[np.complex128] | ||||
| MAR_td64: MaskedArray[np.timedelta64] | ||||
|  | ||||
| AR_b: npt.NDArray[np.bool] | ||||
|  | ||||
| MAR_1d_f8.shape = (3, 1)  # type: ignore[assignment] | ||||
| MAR_1d_f8.dtype = np.bool  # type: ignore[assignment] | ||||
|  | ||||
| np.ma.min(MAR_1d_f8, axis=1.0)  # type: ignore[call-overload] | ||||
| np.ma.min(MAR_1d_f8, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.ma.min(MAR_1d_f8, out=1.0)  # type: ignore[call-overload] | ||||
| np.ma.min(MAR_1d_f8, fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.min(axis=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.min(keepdims=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.min(out=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.min(fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| np.ma.max(MAR_1d_f8, axis=1.0)  # type: ignore[call-overload] | ||||
| np.ma.max(MAR_1d_f8, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.ma.max(MAR_1d_f8, out=1.0)  # type: ignore[call-overload] | ||||
| np.ma.max(MAR_1d_f8, fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.max(axis=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.max(keepdims=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.max(out=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.max(fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| np.ma.ptp(MAR_1d_f8, axis=1.0)  # type: ignore[call-overload] | ||||
| np.ma.ptp(MAR_1d_f8, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.ma.ptp(MAR_1d_f8, out=1.0)  # type: ignore[call-overload] | ||||
| np.ma.ptp(MAR_1d_f8, fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.ptp(axis=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.ptp(keepdims=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.ptp(out=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.ptp(fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.argmin(axis=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.argmin(keepdims=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.argmin(out=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.argmin(fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| np.ma.argmin(MAR_1d_f8, axis=1.0)  # type: ignore[call-overload] | ||||
| np.ma.argmin(MAR_1d_f8, axis=(1,))  # type: ignore[call-overload] | ||||
| np.ma.argmin(MAR_1d_f8, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.ma.argmin(MAR_1d_f8, out=1.0)  # type: ignore[call-overload] | ||||
| np.ma.argmin(MAR_1d_f8, fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.argmax(axis=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.argmax(keepdims=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.argmax(out=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.argmax(fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| np.ma.argmax(MAR_1d_f8, axis=1.0)  # type: ignore[call-overload] | ||||
| np.ma.argmax(MAR_1d_f8, axis=(0,))  # type: ignore[call-overload] | ||||
| np.ma.argmax(MAR_1d_f8, keepdims=1.0)  # type: ignore[call-overload] | ||||
| np.ma.argmax(MAR_1d_f8, out=1.0)  # type: ignore[call-overload] | ||||
| np.ma.argmax(MAR_1d_f8, fill_value=lambda x: 27)  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.all(axis=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.all(keepdims=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.all(out=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.any(axis=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.any(keepdims=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.any(out=1.0)  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.sort(axis=(0,1))  # type: ignore[arg-type] | ||||
| MAR_1d_f8.sort(axis=None)  # type: ignore[arg-type] | ||||
| MAR_1d_f8.sort(kind='cabbage')  # type: ignore[arg-type] | ||||
| MAR_1d_f8.sort(order=lambda: 'cabbage')  # type: ignore[arg-type] | ||||
| MAR_1d_f8.sort(endwith='cabbage')  # type: ignore[arg-type] | ||||
| MAR_1d_f8.sort(fill_value=lambda: 'cabbage')  # type: ignore[arg-type] | ||||
| MAR_1d_f8.sort(stable='cabbage')  # type: ignore[arg-type] | ||||
| MAR_1d_f8.sort(stable=True)  # type: ignore[arg-type] | ||||
|  | ||||
| MAR_1d_f8.take(axis=1.0)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.take(out=1)  # type: ignore[call-overload] | ||||
| MAR_1d_f8.take(mode="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| np.ma.take(None)  # type: ignore[call-overload] | ||||
| np.ma.take(axis=1.0)  # type: ignore[call-overload] | ||||
| np.ma.take(out=1)  # type: ignore[call-overload] | ||||
| np.ma.take(mode="bob")  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.partition(['cabbage'])  # type: ignore[arg-type] | ||||
| MAR_1d_f8.partition(axis=(0,1))  # type: ignore[arg-type, call-arg] | ||||
| MAR_1d_f8.partition(kind='cabbage')  # type: ignore[arg-type, call-arg] | ||||
| MAR_1d_f8.partition(order=lambda: 'cabbage')  # type: ignore[arg-type, call-arg] | ||||
| MAR_1d_f8.partition(AR_b)  # type: ignore[arg-type] | ||||
|  | ||||
| MAR_1d_f8.argpartition(['cabbage'])  # type: ignore[arg-type] | ||||
| MAR_1d_f8.argpartition(axis=(0,1))  # type: ignore[arg-type, call-arg] | ||||
| MAR_1d_f8.argpartition(kind='cabbage')  # type: ignore[arg-type, call-arg] | ||||
| MAR_1d_f8.argpartition(order=lambda: 'cabbage')  # type: ignore[arg-type, call-arg] | ||||
| MAR_1d_f8.argpartition(AR_b)  # type: ignore[arg-type] | ||||
|  | ||||
| np.ma.ndim(lambda: 'lambda')  # type: ignore[arg-type] | ||||
|  | ||||
| np.ma.size(AR_b, axis='0')  # type: ignore[arg-type] | ||||
|  | ||||
| MAR_1d_f8 >= (lambda x: 'mango') # type: ignore[operator] | ||||
| MAR_1d_f8 > (lambda x: 'mango') # type: ignore[operator] | ||||
| MAR_1d_f8 <= (lambda x: 'mango') # type: ignore[operator] | ||||
| MAR_1d_f8 < (lambda x: 'mango') # type: ignore[operator] | ||||
|  | ||||
| MAR_1d_f8.count(axis=0.)  # type: ignore[call-overload] | ||||
|  | ||||
| np.ma.count(MAR_1d_f8, axis=0.)  # type: ignore[call-overload] | ||||
|  | ||||
| MAR_1d_f8.put(4, 999, mode='flip')  # type: ignore[arg-type] | ||||
|  | ||||
| np.ma.put(MAR_1d_f8, 4, 999, mode='flip')  # type: ignore[arg-type] | ||||
|  | ||||
| np.ma.put([1,1,3], 0, 999)  # type: ignore[arg-type] | ||||
|  | ||||
| np.ma.compressed(lambda: 'compress me')  # type: ignore[call-overload] | ||||
|  | ||||
| np.ma.allequal(MAR_1d_f8, [1,2,3], fill_value=1.5)  # type: ignore[arg-type] | ||||
|  | ||||
| np.ma.allclose(MAR_1d_f8, [1,2,3], masked_equal=4.5)  # type: ignore[arg-type] | ||||
| np.ma.allclose(MAR_1d_f8, [1,2,3], rtol='.4')  # type: ignore[arg-type] | ||||
| np.ma.allclose(MAR_1d_f8, [1,2,3], atol='.5')  # type: ignore[arg-type] | ||||
|  | ||||
| MAR_1d_f8.__setmask__('mask')  # type: ignore[arg-type] | ||||
|  | ||||
| MAR_b *= 2  # type: ignore[arg-type] | ||||
| MAR_c //= 2  # type: ignore[misc] | ||||
| MAR_td64 **= 2  # type: ignore[misc] | ||||
|  | ||||
| MAR_1d_f8.swapaxes(axis1=1, axis2=0)  # type: ignore[call-arg] | ||||
| @ -0,0 +1,5 @@ | ||||
| import numpy as np | ||||
|  | ||||
| with open("file.txt", "r") as f: | ||||
|     np.memmap(f)  # type: ignore[call-overload] | ||||
| np.memmap("test.txt", shape=[10, 5])  # type: ignore[call-overload] | ||||
| @ -0,0 +1,17 @@ | ||||
| import numpy as np | ||||
|  | ||||
| np.testing.bob  # type: ignore[attr-defined] | ||||
| np.bob  # type: ignore[attr-defined] | ||||
|  | ||||
| # Stdlib modules in the namespace by accident | ||||
| np.warnings  # type: ignore[attr-defined] | ||||
| np.sys  # type: ignore[attr-defined] | ||||
| np.os  # type: ignore[attr-defined] | ||||
| np.math  # type: ignore[attr-defined] | ||||
|  | ||||
| # Public sub-modules that are not imported to their parent module by default; | ||||
| # e.g. one must first execute `import numpy.lib.recfunctions` | ||||
| np.lib.recfunctions  # type: ignore[attr-defined] | ||||
|  | ||||
| np.__deprecated_attrs__  # type: ignore[attr-defined] | ||||
| np.__expired_functions__  # type: ignore[attr-defined] | ||||
| @ -0,0 +1,52 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| i8: np.int64 | ||||
|  | ||||
| AR_b: npt.NDArray[np.bool] | ||||
| AR_u1: npt.NDArray[np.uint8] | ||||
| AR_i8: npt.NDArray[np.int64] | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
|  | ||||
| M: np.datetime64 | ||||
|  | ||||
| AR_LIKE_f: list[float] | ||||
|  | ||||
| def func(a: int) -> None: ... | ||||
|  | ||||
| np.where(AR_b, 1)  # type: ignore[call-overload] | ||||
|  | ||||
| np.can_cast(AR_f8, 1)  # type: ignore[arg-type] | ||||
|  | ||||
| np.vdot(AR_M, AR_M)  # type: ignore[arg-type] | ||||
|  | ||||
| np.copyto(AR_LIKE_f, AR_f8)  # type: ignore[arg-type] | ||||
|  | ||||
| np.putmask(AR_LIKE_f, [True, True, False], 1.5)  # type: ignore[arg-type] | ||||
|  | ||||
| np.packbits(AR_f8)  # type: ignore[arg-type] | ||||
| np.packbits(AR_u1, bitorder=">")  # type: ignore[arg-type] | ||||
|  | ||||
| np.unpackbits(AR_i8)  # type: ignore[arg-type] | ||||
| np.unpackbits(AR_u1, bitorder=">")  # type: ignore[arg-type] | ||||
|  | ||||
| np.shares_memory(1, 1, max_work=i8)  # type: ignore[arg-type] | ||||
| np.may_share_memory(1, 1, max_work=i8)  # type: ignore[arg-type] | ||||
|  | ||||
| np.arange(stop=10)  # type: ignore[call-overload] | ||||
|  | ||||
| np.datetime_data(int)  # type: ignore[arg-type] | ||||
|  | ||||
| np.busday_offset("2012", 10)  # type: ignore[call-overload] | ||||
|  | ||||
| np.datetime_as_string("2012")  # type: ignore[call-overload] | ||||
|  | ||||
| np.char.compare_chararrays("a", b"a", "==", False)  # type: ignore[call-overload] | ||||
|  | ||||
| np.nested_iters([AR_i8, AR_i8])  # type: ignore[call-arg] | ||||
| np.nested_iters([AR_i8, AR_i8], 0)  # type: ignore[arg-type] | ||||
| np.nested_iters([AR_i8, AR_i8], [0])  # type: ignore[list-item] | ||||
| np.nested_iters([AR_i8, AR_i8], [[0], [1]], flags=["test"])  # type: ignore[list-item] | ||||
| np.nested_iters([AR_i8, AR_i8], [[0], [1]], op_flags=[["test"]])  # type: ignore[list-item] | ||||
| np.nested_iters([AR_i8, AR_i8], [[0], [1]], buffersize=1.0)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,11 @@ | ||||
| import numpy as np | ||||
|  | ||||
| # Ban setting dtype since mutating the type of the array in place | ||||
| # makes having ndarray be generic over dtype impossible. Generally | ||||
| # users should use `ndarray.view` in this situation anyway. See | ||||
| # | ||||
| # https://github.com/numpy/numpy-stubs/issues/7 | ||||
| # | ||||
| # for more context. | ||||
| float_array = np.array([1.0]) | ||||
| float_array.dtype = np.bool  # type: ignore[assignment, misc] | ||||
| @ -0,0 +1,36 @@ | ||||
| """ | ||||
| Tests for miscellaneous (non-magic) ``np.ndarray``/``np.generic`` methods. | ||||
|  | ||||
| More extensive tests are performed for the methods' | ||||
| function-based counterpart in `../from_numeric.py`. | ||||
|  | ||||
| """ | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| f8: np.float64 | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
| AR_b: npt.NDArray[np.bool] | ||||
|  | ||||
| ctypes_obj = AR_f8.ctypes | ||||
|  | ||||
| f8.argpartition(0)  # type: ignore[attr-defined] | ||||
| f8.diagonal()  # type: ignore[attr-defined] | ||||
| f8.dot(1)  # type: ignore[attr-defined] | ||||
| f8.nonzero()  # type: ignore[attr-defined] | ||||
| f8.partition(0)  # type: ignore[attr-defined] | ||||
| f8.put(0, 2)  # type: ignore[attr-defined] | ||||
| f8.setfield(2, np.float64)  # type: ignore[attr-defined] | ||||
| f8.sort()  # type: ignore[attr-defined] | ||||
| f8.trace()  # type: ignore[attr-defined] | ||||
|  | ||||
| AR_M.__complex__()  # type: ignore[misc] | ||||
| AR_b.__index__()  # type: ignore[misc] | ||||
|  | ||||
| AR_f8[1.5]  # type: ignore[call-overload] | ||||
| AR_f8["field_a"]  # type: ignore[call-overload] | ||||
| AR_f8[["field_a", "field_b"]]  # type: ignore[index] | ||||
|  | ||||
| AR_f8.__array_finalize__(object())  # type: ignore[arg-type] | ||||
| @ -0,0 +1,8 @@ | ||||
| import numpy as np | ||||
|  | ||||
| class Test(np.nditer): ...  # type: ignore[misc] | ||||
|  | ||||
| np.nditer([0, 1], flags=["test"])  # type: ignore[list-item] | ||||
| np.nditer([0, 1], op_flags=[["test"]])  # type: ignore[list-item] | ||||
| np.nditer([0, 1], itershape=(1.0,))  # type: ignore[arg-type] | ||||
| np.nditer([0, 1], buffersize=1.0)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,16 @@ | ||||
| from collections.abc import Sequence | ||||
| from numpy._typing import _NestedSequence | ||||
|  | ||||
| a: Sequence[float] | ||||
| b: list[complex] | ||||
| c: tuple[str, ...] | ||||
| d: int | ||||
| e: str | ||||
|  | ||||
| def func(a: _NestedSequence[int]) -> None: ... | ||||
|  | ||||
| reveal_type(func(a))  # type: ignore[arg-type, misc] | ||||
| reveal_type(func(b))  # type: ignore[arg-type, misc] | ||||
| reveal_type(func(c))  # type: ignore[arg-type, misc] | ||||
| reveal_type(func(d))  # type: ignore[arg-type, misc] | ||||
| reveal_type(func(e))  # type: ignore[arg-type, misc] | ||||
| @ -0,0 +1,24 @@ | ||||
| import pathlib | ||||
| from typing import IO | ||||
|  | ||||
| import numpy.typing as npt | ||||
| import numpy as np | ||||
|  | ||||
| str_path: str | ||||
| bytes_path: bytes | ||||
| pathlib_path: pathlib.Path | ||||
| str_file: IO[str] | ||||
| AR_i8: npt.NDArray[np.int64] | ||||
|  | ||||
| np.load(str_file)  # type: ignore[arg-type] | ||||
|  | ||||
| np.save(bytes_path, AR_i8)  # type: ignore[call-overload] | ||||
| np.save(str_path, AR_i8, fix_imports=True)  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated] | ||||
|  | ||||
| np.savez(bytes_path, AR_i8)  # type: ignore[arg-type] | ||||
|  | ||||
| np.savez_compressed(bytes_path, AR_i8)  # type: ignore[arg-type] | ||||
|  | ||||
| np.loadtxt(bytes_path)  # type: ignore[arg-type] | ||||
|  | ||||
| np.fromregex(bytes_path, ".", np.int64)  # type: ignore[call-overload] | ||||
| @ -0,0 +1,5 @@ | ||||
| import numpy as np | ||||
|  | ||||
| np.isdtype(1, np.int64)  # type: ignore[arg-type] | ||||
|  | ||||
| np.issubdtype(1, np.int64)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,62 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| SEED_FLOAT: float = 457.3 | ||||
| SEED_ARR_FLOAT: npt.NDArray[np.float64] = np.array([1.0, 2, 3, 4]) | ||||
| SEED_ARRLIKE_FLOAT: list[float] = [1.0, 2.0, 3.0, 4.0] | ||||
| SEED_SEED_SEQ: np.random.SeedSequence = np.random.SeedSequence(0) | ||||
| SEED_STR: str = "String seeding not allowed" | ||||
|  | ||||
| # default rng | ||||
| np.random.default_rng(SEED_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.default_rng(SEED_ARR_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.default_rng(SEED_ARRLIKE_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.default_rng(SEED_STR)  # type: ignore[arg-type] | ||||
|  | ||||
| # Seed Sequence | ||||
| np.random.SeedSequence(SEED_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.SeedSequence(SEED_ARR_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.SeedSequence(SEED_ARRLIKE_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.SeedSequence(SEED_SEED_SEQ)  # type: ignore[arg-type] | ||||
| np.random.SeedSequence(SEED_STR)  # type: ignore[arg-type] | ||||
|  | ||||
| seed_seq: np.random.bit_generator.SeedSequence = np.random.SeedSequence() | ||||
| seed_seq.spawn(11.5)  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3.14)  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3, np.uint8)  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3, "uint8")  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3, "u1")  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3, np.uint16)  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3, "uint16")  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3, "u2")  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3, np.int32)  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3, "int32")  # type: ignore[arg-type] | ||||
| seed_seq.generate_state(3, "i4")  # type: ignore[arg-type] | ||||
|  | ||||
| # Bit Generators | ||||
| np.random.MT19937(SEED_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.MT19937(SEED_ARR_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.MT19937(SEED_ARRLIKE_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.MT19937(SEED_STR)  # type: ignore[arg-type] | ||||
|  | ||||
| np.random.PCG64(SEED_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.PCG64(SEED_ARR_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.PCG64(SEED_ARRLIKE_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.PCG64(SEED_STR)  # type: ignore[arg-type] | ||||
|  | ||||
| np.random.Philox(SEED_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.Philox(SEED_ARR_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.Philox(SEED_ARRLIKE_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.Philox(SEED_STR)  # type: ignore[arg-type] | ||||
|  | ||||
| np.random.SFC64(SEED_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.SFC64(SEED_ARR_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.SFC64(SEED_ARRLIKE_FLOAT)  # type: ignore[arg-type] | ||||
| np.random.SFC64(SEED_STR)  # type: ignore[arg-type] | ||||
|  | ||||
| # Generator | ||||
| np.random.Generator(None)  # type: ignore[arg-type] | ||||
| np.random.Generator(12333283902830213)  # type: ignore[arg-type] | ||||
| np.random.Generator("OxFEEDF00D")  # type: ignore[arg-type] | ||||
| np.random.Generator([123, 234])  # type: ignore[arg-type] | ||||
| np.random.Generator(np.array([123, 234], dtype="u4"))  # type: ignore[arg-type] | ||||
| @ -0,0 +1,17 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_i8: npt.NDArray[np.int64] | ||||
|  | ||||
| np.rec.fromarrays(1)  # type: ignore[call-overload] | ||||
| np.rec.fromarrays([1, 2, 3], dtype=[("f8", "f8")], formats=["f8", "f8"])  # type: ignore[call-overload] | ||||
|  | ||||
| np.rec.fromrecords(AR_i8)  # type: ignore[arg-type] | ||||
| np.rec.fromrecords([(1.5,)], dtype=[("f8", "f8")], formats=["f8", "f8"])  # type: ignore[call-overload] | ||||
|  | ||||
| np.rec.fromstring("string", dtype=[("f8", "f8")])  # type: ignore[call-overload] | ||||
| np.rec.fromstring(b"bytes")  # type: ignore[call-overload] | ||||
| np.rec.fromstring(b"(1.5,)", dtype=[("f8", "f8")], formats=["f8", "f8"])  # type: ignore[call-overload] | ||||
|  | ||||
| with open("test", "r") as f: | ||||
|     np.rec.fromfile(f, dtype=[("f8", "f8")])  # type: ignore[call-overload] | ||||
| @ -0,0 +1,87 @@ | ||||
| import sys | ||||
| import numpy as np | ||||
|  | ||||
| f2: np.float16 | ||||
| f8: np.float64 | ||||
| c8: np.complex64 | ||||
|  | ||||
| # Construction | ||||
|  | ||||
| np.float32(3j)  # type: ignore[arg-type] | ||||
|  | ||||
| # Technically the following examples are valid NumPy code. But they | ||||
| # are not considered a best practice, and people who wish to use the | ||||
| # stubs should instead do | ||||
| # | ||||
| # np.array([1.0, 0.0, 0.0], dtype=np.float32) | ||||
| # np.array([], dtype=np.complex64) | ||||
| # | ||||
| # See e.g. the discussion on the mailing list | ||||
| # | ||||
| # https://mail.python.org/pipermail/numpy-discussion/2020-April/080566.html | ||||
| # | ||||
| # and the issue | ||||
| # | ||||
| # https://github.com/numpy/numpy-stubs/issues/41 | ||||
| # | ||||
| # for more context. | ||||
| np.float32([1.0, 0.0, 0.0])  # type: ignore[arg-type] | ||||
| np.complex64([])  # type: ignore[call-overload] | ||||
|  | ||||
| # TODO: protocols (can't check for non-existent protocols w/ __getattr__) | ||||
|  | ||||
| np.datetime64(0)  # type: ignore[call-overload] | ||||
|  | ||||
| class A: | ||||
|     def __float__(self) -> float: ... | ||||
|  | ||||
| np.int8(A())  # type: ignore[arg-type] | ||||
| np.int16(A())  # type: ignore[arg-type] | ||||
| np.int32(A())  # type: ignore[arg-type] | ||||
| np.int64(A())  # type: ignore[arg-type] | ||||
| np.uint8(A())  # type: ignore[arg-type] | ||||
| np.uint16(A())  # type: ignore[arg-type] | ||||
| np.uint32(A())  # type: ignore[arg-type] | ||||
| np.uint64(A())  # type: ignore[arg-type] | ||||
|  | ||||
| np.void("test")  # type: ignore[call-overload] | ||||
| np.void("test", dtype=None)  # type: ignore[call-overload] | ||||
|  | ||||
| np.generic(1)  # type: ignore[abstract] | ||||
| np.number(1)  # type: ignore[abstract] | ||||
| np.integer(1)  # type: ignore[abstract] | ||||
| np.inexact(1)  # type: ignore[abstract] | ||||
| np.character("test")  # type: ignore[abstract] | ||||
| np.flexible(b"test")  # type: ignore[abstract] | ||||
|  | ||||
| np.float64(value=0.0)  # type: ignore[call-arg] | ||||
| np.int64(value=0)  # type: ignore[call-arg] | ||||
| np.uint64(value=0)  # type: ignore[call-arg] | ||||
| np.complex128(value=0.0j)  # type: ignore[call-overload] | ||||
| np.str_(value='bob')  # type: ignore[call-overload] | ||||
| np.bytes_(value=b'test')  # type: ignore[call-overload] | ||||
| np.void(value=b'test')  # type: ignore[call-overload] | ||||
| np.bool(value=True)  # type: ignore[call-overload] | ||||
| np.datetime64(value="2019")  # type: ignore[call-overload] | ||||
| np.timedelta64(value=0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.bytes_(b"hello", encoding='utf-8')  # type: ignore[call-overload] | ||||
| np.str_("hello", encoding='utf-8')  # type: ignore[call-overload] | ||||
|  | ||||
| f8.item(1)  # type: ignore[call-overload] | ||||
| f8.item((0, 1))  # type: ignore[arg-type] | ||||
| f8.squeeze(axis=1)  # type: ignore[arg-type] | ||||
| f8.squeeze(axis=(0, 1))  # type: ignore[arg-type] | ||||
| f8.transpose(1)  # type: ignore[arg-type] | ||||
|  | ||||
| def func(a: np.float32) -> None: ... | ||||
|  | ||||
| func(f2)  # type: ignore[arg-type] | ||||
| func(f8)  # type: ignore[arg-type] | ||||
|  | ||||
| c8.__getnewargs__()  # type: ignore[attr-defined] | ||||
| f2.__getnewargs__()  # type: ignore[attr-defined] | ||||
| f2.hex()  # type: ignore[attr-defined] | ||||
| np.float16.fromhex("0x0.0p+0")  # type: ignore[attr-defined] | ||||
| f2.__trunc__()  # type: ignore[attr-defined] | ||||
| f2.__getformat__("float")  # type: ignore[attr-defined] | ||||
| @ -0,0 +1,6 @@ | ||||
| from typing import Any | ||||
| import numpy as np | ||||
|  | ||||
| # test bounds of _ShapeT_co | ||||
|  | ||||
| np.ndarray[tuple[str, str], Any]  # type: ignore[type-var] | ||||
| @ -0,0 +1,8 @@ | ||||
| import numpy as np | ||||
|  | ||||
| class DTypeLike: | ||||
|     dtype: np.dtype[np.int_] | ||||
|  | ||||
| dtype_like: DTypeLike | ||||
|  | ||||
| np.expand_dims(dtype_like, (5, 10))  # type: ignore[call-overload] | ||||
| @ -0,0 +1,9 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
|  | ||||
| np.lib.stride_tricks.as_strided(AR_f8, shape=8)  # type: ignore[call-overload] | ||||
| np.lib.stride_tricks.as_strided(AR_f8, strides=8)  # type: ignore[call-overload] | ||||
|  | ||||
| np.lib.stride_tricks.sliding_window_view(AR_f8, axis=(1,))  # type: ignore[call-overload] | ||||
| @ -0,0 +1,52 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_U: npt.NDArray[np.str_] | ||||
| AR_S: npt.NDArray[np.bytes_] | ||||
|  | ||||
| np.strings.equal(AR_U, AR_S)  # type: ignore[arg-type] | ||||
| np.strings.not_equal(AR_U, AR_S)  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.greater_equal(AR_U, AR_S)  # type: ignore[arg-type] | ||||
| np.strings.less_equal(AR_U, AR_S)  # type: ignore[arg-type] | ||||
| np.strings.greater(AR_U, AR_S)  # type: ignore[arg-type] | ||||
| np.strings.less(AR_U, AR_S)  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.encode(AR_S)  # type: ignore[arg-type] | ||||
| np.strings.decode(AR_U)  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.lstrip(AR_U, b"a")  # type: ignore[arg-type] | ||||
| np.strings.lstrip(AR_S, "a")  # type: ignore[arg-type] | ||||
| np.strings.strip(AR_U, b"a")  # type: ignore[arg-type] | ||||
| np.strings.strip(AR_S, "a")  # type: ignore[arg-type] | ||||
| np.strings.rstrip(AR_U, b"a")  # type: ignore[arg-type] | ||||
| np.strings.rstrip(AR_S, "a")  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.partition(AR_U, b"a")  # type: ignore[arg-type] | ||||
| np.strings.partition(AR_S, "a")  # type: ignore[arg-type] | ||||
| np.strings.rpartition(AR_U, b"a")  # type: ignore[arg-type] | ||||
| np.strings.rpartition(AR_S, "a")  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.count(AR_U, b"a", [1, 2, 3], [1, 2, 3])  # type: ignore[arg-type] | ||||
| np.strings.count(AR_S, "a", 0, 9)  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.endswith(AR_U, b"a", [1, 2, 3], [1, 2, 3])  # type: ignore[arg-type] | ||||
| np.strings.endswith(AR_S, "a", 0, 9)  # type: ignore[arg-type] | ||||
| np.strings.startswith(AR_U, b"a", [1, 2, 3], [1, 2, 3])  # type: ignore[arg-type] | ||||
| np.strings.startswith(AR_S, "a", 0, 9)  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.find(AR_U, b"a", [1, 2, 3], [1, 2, 3])  # type: ignore[arg-type] | ||||
| np.strings.find(AR_S, "a", 0, 9)  # type: ignore[arg-type] | ||||
| np.strings.rfind(AR_U, b"a", [1, 2, 3], [1, 2, 3])  # type: ignore[arg-type] | ||||
| np.strings.rfind(AR_S, "a", 0, 9)  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.index(AR_U, b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| np.strings.index(AR_S, "a", end=9)  # type: ignore[arg-type] | ||||
| np.strings.rindex(AR_U, b"a", start=[1, 2, 3])  # type: ignore[arg-type] | ||||
| np.strings.rindex(AR_S, "a", end=9)  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.isdecimal(AR_S)  # type: ignore[arg-type] | ||||
| np.strings.isnumeric(AR_S)  # type: ignore[arg-type] | ||||
|  | ||||
| np.strings.replace(AR_U, b"_", b"-", 10)  # type: ignore[arg-type] | ||||
| np.strings.replace(AR_S, "_", "-", 1)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,28 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_U: npt.NDArray[np.str_] | ||||
|  | ||||
| def func(x: object) -> bool: ... | ||||
|  | ||||
| np.testing.assert_(True, msg=1)  # type: ignore[arg-type] | ||||
| np.testing.build_err_msg(1, "test")  # type: ignore[arg-type] | ||||
| np.testing.assert_almost_equal(AR_U, AR_U)  # type: ignore[arg-type] | ||||
| np.testing.assert_approx_equal([1, 2, 3], [1, 2, 3])  # type: ignore[arg-type] | ||||
| np.testing.assert_array_almost_equal(AR_U, AR_U)  # type: ignore[arg-type] | ||||
| np.testing.assert_array_less(AR_U, AR_U)  # type: ignore[arg-type] | ||||
| np.testing.assert_string_equal(b"a", b"a")  # type: ignore[arg-type] | ||||
|  | ||||
| np.testing.assert_raises(expected_exception=TypeError, callable=func)  # type: ignore[call-overload] | ||||
| np.testing.assert_raises_regex(expected_exception=TypeError, expected_regex="T", callable=func)  # type: ignore[call-overload] | ||||
|  | ||||
| np.testing.assert_allclose(AR_U, AR_U)  # type: ignore[arg-type] | ||||
| np.testing.assert_array_almost_equal_nulp(AR_U, AR_U)  # type: ignore[arg-type] | ||||
| np.testing.assert_array_max_ulp(AR_U, AR_U)  # type: ignore[arg-type] | ||||
|  | ||||
| np.testing.assert_warns(RuntimeWarning, func)  # type: ignore[call-overload] | ||||
| np.testing.assert_no_warnings(func=func)  # type: ignore[call-overload] | ||||
| np.testing.assert_no_warnings(func)  # type: ignore[call-overload] | ||||
| np.testing.assert_no_warnings(func, y=None)  # type: ignore[call-overload] | ||||
|  | ||||
| np.testing.assert_no_gc_cycles(func=func)  # type: ignore[call-overload] | ||||
| @ -0,0 +1,32 @@ | ||||
| from typing import Any, TypeVar | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| def func1(ar: npt.NDArray[Any], a: int) -> npt.NDArray[np.str_]: ... | ||||
|  | ||||
| def func2(ar: npt.NDArray[Any], a: float) -> float: ... | ||||
|  | ||||
| AR_b: npt.NDArray[np.bool] | ||||
| AR_m: npt.NDArray[np.timedelta64] | ||||
|  | ||||
| AR_LIKE_b: list[bool] | ||||
|  | ||||
| np.eye(10, M=20.0)  # type: ignore[call-overload] | ||||
| np.eye(10, k=2.5, dtype=int)  # type: ignore[call-overload] | ||||
|  | ||||
| np.diag(AR_b, k=0.5)  # type: ignore[call-overload] | ||||
| np.diagflat(AR_b, k=0.5)  # type: ignore[call-overload] | ||||
|  | ||||
| np.tri(10, M=20.0)  # type: ignore[call-overload] | ||||
| np.tri(10, k=2.5, dtype=int)  # type: ignore[call-overload] | ||||
|  | ||||
| np.tril(AR_b, k=0.5)  # type: ignore[call-overload] | ||||
| np.triu(AR_b, k=0.5)  # type: ignore[call-overload] | ||||
|  | ||||
| np.vander(AR_m)  # type: ignore[arg-type] | ||||
|  | ||||
| np.histogram2d(AR_m)  # type: ignore[call-overload] | ||||
|  | ||||
| np.mask_indices(10, func1)  # type: ignore[arg-type] | ||||
| np.mask_indices(10, func2, 10.5)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,13 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| DTYPE_i8: np.dtype[np.int64] | ||||
|  | ||||
| np.mintypecode(DTYPE_i8)  # type: ignore[arg-type] | ||||
| np.iscomplexobj(DTYPE_i8)  # type: ignore[arg-type] | ||||
| np.isrealobj(DTYPE_i8)  # type: ignore[arg-type] | ||||
|  | ||||
| np.typename(DTYPE_i8)  # type: ignore[call-overload] | ||||
| np.typename("invalid")  # type: ignore[call-overload] | ||||
|  | ||||
| np.common_type(np.timedelta64())  # type: ignore[arg-type] | ||||
| @ -0,0 +1,21 @@ | ||||
| """Typing tests for `numpy._core._ufunc_config`.""" | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
| def func1(a: str, b: int, c: float) -> None: ... | ||||
| def func2(a: str, *, b: int) -> None: ... | ||||
|  | ||||
| class Write1: | ||||
|     def write1(self, a: str) -> None: ... | ||||
|  | ||||
| class Write2: | ||||
|     def write(self, a: str, b: str) -> None: ... | ||||
|  | ||||
| class Write3: | ||||
|     def write(self, *, a: str) -> None: ... | ||||
|  | ||||
| np.seterrcall(func1)  # type: ignore[arg-type] | ||||
| np.seterrcall(func2)  # type: ignore[arg-type] | ||||
| np.seterrcall(Write1())  # type: ignore[arg-type] | ||||
| np.seterrcall(Write2())  # type: ignore[arg-type] | ||||
| np.seterrcall(Write3())  # type: ignore[arg-type] | ||||
| @ -0,0 +1,21 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_c: npt.NDArray[np.complex128] | ||||
| AR_m: npt.NDArray[np.timedelta64] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
| AR_O: npt.NDArray[np.object_] | ||||
|  | ||||
| np.fix(AR_c)  # type: ignore[arg-type] | ||||
| np.fix(AR_m)  # type: ignore[arg-type] | ||||
| np.fix(AR_M)  # type: ignore[arg-type] | ||||
|  | ||||
| np.isposinf(AR_c)  # type: ignore[arg-type] | ||||
| np.isposinf(AR_m)  # type: ignore[arg-type] | ||||
| np.isposinf(AR_M)  # type: ignore[arg-type] | ||||
| np.isposinf(AR_O)  # type: ignore[arg-type] | ||||
|  | ||||
| np.isneginf(AR_c)  # type: ignore[arg-type] | ||||
| np.isneginf(AR_m)  # type: ignore[arg-type] | ||||
| np.isneginf(AR_M)  # type: ignore[arg-type] | ||||
| np.isneginf(AR_O)  # type: ignore[arg-type] | ||||
| @ -0,0 +1,17 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
|  | ||||
| np.sin.nin + "foo"  # type: ignore[operator] | ||||
| np.sin(1, foo="bar")  # type: ignore[call-overload] | ||||
|  | ||||
| np.abs(None)  # type: ignore[call-overload] | ||||
|  | ||||
| np.add(1, 1, 1)  # type: ignore[call-overload] | ||||
| np.add(1, 1, axis=0)  # type: ignore[call-overload] | ||||
|  | ||||
| np.matmul(AR_f8, AR_f8, where=True)  # type: ignore[call-overload] | ||||
|  | ||||
| np.frexp(AR_f8, out=None)  # type: ignore[call-overload] | ||||
| np.frexp(AR_f8, out=AR_f8)  # type: ignore[call-overload] | ||||
| @ -0,0 +1,5 @@ | ||||
| import numpy.exceptions as ex | ||||
|  | ||||
| ex.AxisError(1.0)  # type: ignore[call-overload] | ||||
| ex.AxisError(1, ndim=2.0)  # type: ignore[call-overload] | ||||
| ex.AxisError(2, msg_prefix=404)  # type: ignore[call-overload] | ||||
| @ -0,0 +1,9 @@ | ||||
| import numpy as np | ||||
| from numpy._typing import _96Bit, _128Bit | ||||
|  | ||||
| from typing import assert_type | ||||
|  | ||||
| assert_type(np.float96(), np.floating[_96Bit]) | ||||
| assert_type(np.float128(), np.floating[_128Bit]) | ||||
| assert_type(np.complex192(), np.complexfloating[_96Bit, _96Bit]) | ||||
| assert_type(np.complex256(), np.complexfloating[_128Bit, _128Bit]) | ||||
| @ -0,0 +1,9 @@ | ||||
| [mypy] | ||||
| enable_error_code = deprecated, ignore-without-code, truthy-bool | ||||
| strict_bytes = True | ||||
| warn_unused_ignores = True | ||||
| implicit_reexport = False | ||||
| disallow_any_unimported = True | ||||
| disallow_any_generics = True | ||||
| show_absolute_path = True | ||||
| pretty = True | ||||
| @ -0,0 +1,612 @@ | ||||
| from __future__ import annotations | ||||
|  | ||||
| from typing import Any, cast | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| import pytest | ||||
|  | ||||
| c16 = np.complex128(1) | ||||
| f8 = np.float64(1) | ||||
| i8 = np.int64(1) | ||||
| u8 = np.uint64(1) | ||||
|  | ||||
| c8 = np.complex64(1) | ||||
| f4 = np.float32(1) | ||||
| i4 = np.int32(1) | ||||
| u4 = np.uint32(1) | ||||
|  | ||||
| dt = np.datetime64(1, "D") | ||||
| td = np.timedelta64(1, "D") | ||||
|  | ||||
| b_ = np.bool(1) | ||||
|  | ||||
| b = bool(1) | ||||
| c = complex(1) | ||||
| f = float(1) | ||||
| i = int(1) | ||||
|  | ||||
|  | ||||
| class Object: | ||||
|     def __array__(self, dtype: np.typing.DTypeLike = None, | ||||
|                   copy: bool | None = None) -> np.ndarray[Any, np.dtype[np.object_]]: | ||||
|         ret = np.empty((), dtype=object) | ||||
|         ret[()] = self | ||||
|         return ret | ||||
|  | ||||
|     def __sub__(self, value: Any) -> Object: | ||||
|         return self | ||||
|  | ||||
|     def __rsub__(self, value: Any) -> Object: | ||||
|         return self | ||||
|  | ||||
|     def __floordiv__(self, value: Any) -> Object: | ||||
|         return self | ||||
|  | ||||
|     def __rfloordiv__(self, value: Any) -> Object: | ||||
|         return self | ||||
|  | ||||
|     def __mul__(self, value: Any) -> Object: | ||||
|         return self | ||||
|  | ||||
|     def __rmul__(self, value: Any) -> Object: | ||||
|         return self | ||||
|  | ||||
|     def __pow__(self, value: Any) -> Object: | ||||
|         return self | ||||
|  | ||||
|     def __rpow__(self, value: Any) -> Object: | ||||
|         return self | ||||
|  | ||||
|  | ||||
| AR_b: npt.NDArray[np.bool] = np.array([True]) | ||||
| AR_u: npt.NDArray[np.uint32] = np.array([1], dtype=np.uint32) | ||||
| AR_i: npt.NDArray[np.int64] = np.array([1]) | ||||
| AR_integer: npt.NDArray[np.integer] = cast(npt.NDArray[np.integer], AR_i) | ||||
| AR_f: npt.NDArray[np.float64] = np.array([1.0]) | ||||
| AR_c: npt.NDArray[np.complex128] = np.array([1j]) | ||||
| AR_m: npt.NDArray[np.timedelta64] = np.array([np.timedelta64(1, "D")]) | ||||
| AR_M: npt.NDArray[np.datetime64] = np.array([np.datetime64(1, "D")]) | ||||
| AR_O: npt.NDArray[np.object_] = np.array([Object()]) | ||||
|  | ||||
| AR_LIKE_b = [True] | ||||
| AR_LIKE_u = [np.uint32(1)] | ||||
| AR_LIKE_i = [1] | ||||
| AR_LIKE_f = [1.0] | ||||
| AR_LIKE_c = [1j] | ||||
| AR_LIKE_m = [np.timedelta64(1, "D")] | ||||
| AR_LIKE_M = [np.datetime64(1, "D")] | ||||
| AR_LIKE_O = [Object()] | ||||
|  | ||||
| # Array subtractions | ||||
|  | ||||
| AR_b - AR_LIKE_u | ||||
| AR_b - AR_LIKE_i | ||||
| AR_b - AR_LIKE_f | ||||
| AR_b - AR_LIKE_c | ||||
| AR_b - AR_LIKE_m | ||||
| AR_b - AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_u - AR_b | ||||
| AR_LIKE_i - AR_b | ||||
| AR_LIKE_f - AR_b | ||||
| AR_LIKE_c - AR_b | ||||
| AR_LIKE_m - AR_b | ||||
| AR_LIKE_M - AR_b | ||||
| AR_LIKE_O - AR_b | ||||
|  | ||||
| AR_u - AR_LIKE_b | ||||
| AR_u - AR_LIKE_u | ||||
| AR_u - AR_LIKE_i | ||||
| AR_u - AR_LIKE_f | ||||
| AR_u - AR_LIKE_c | ||||
| AR_u - AR_LIKE_m | ||||
| AR_u - AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b - AR_u | ||||
| AR_LIKE_u - AR_u | ||||
| AR_LIKE_i - AR_u | ||||
| AR_LIKE_f - AR_u | ||||
| AR_LIKE_c - AR_u | ||||
| AR_LIKE_m - AR_u | ||||
| AR_LIKE_M - AR_u | ||||
| AR_LIKE_O - AR_u | ||||
|  | ||||
| AR_i - AR_LIKE_b | ||||
| AR_i - AR_LIKE_u | ||||
| AR_i - AR_LIKE_i | ||||
| AR_i - AR_LIKE_f | ||||
| AR_i - AR_LIKE_c | ||||
| AR_i - AR_LIKE_m | ||||
| AR_i - AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b - AR_i | ||||
| AR_LIKE_u - AR_i | ||||
| AR_LIKE_i - AR_i | ||||
| AR_LIKE_f - AR_i | ||||
| AR_LIKE_c - AR_i | ||||
| AR_LIKE_m - AR_i | ||||
| AR_LIKE_M - AR_i | ||||
| AR_LIKE_O - AR_i | ||||
|  | ||||
| AR_f - AR_LIKE_b | ||||
| AR_f - AR_LIKE_u | ||||
| AR_f - AR_LIKE_i | ||||
| AR_f - AR_LIKE_f | ||||
| AR_f - AR_LIKE_c | ||||
| AR_f - AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b - AR_f | ||||
| AR_LIKE_u - AR_f | ||||
| AR_LIKE_i - AR_f | ||||
| AR_LIKE_f - AR_f | ||||
| AR_LIKE_c - AR_f | ||||
| AR_LIKE_O - AR_f | ||||
|  | ||||
| AR_c - AR_LIKE_b | ||||
| AR_c - AR_LIKE_u | ||||
| AR_c - AR_LIKE_i | ||||
| AR_c - AR_LIKE_f | ||||
| AR_c - AR_LIKE_c | ||||
| AR_c - AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b - AR_c | ||||
| AR_LIKE_u - AR_c | ||||
| AR_LIKE_i - AR_c | ||||
| AR_LIKE_f - AR_c | ||||
| AR_LIKE_c - AR_c | ||||
| AR_LIKE_O - AR_c | ||||
|  | ||||
| AR_m - AR_LIKE_b | ||||
| AR_m - AR_LIKE_u | ||||
| AR_m - AR_LIKE_i | ||||
| AR_m - AR_LIKE_m | ||||
|  | ||||
| AR_LIKE_b - AR_m | ||||
| AR_LIKE_u - AR_m | ||||
| AR_LIKE_i - AR_m | ||||
| AR_LIKE_m - AR_m | ||||
| AR_LIKE_M - AR_m | ||||
|  | ||||
| AR_M - AR_LIKE_b | ||||
| AR_M - AR_LIKE_u | ||||
| AR_M - AR_LIKE_i | ||||
| AR_M - AR_LIKE_m | ||||
| AR_M - AR_LIKE_M | ||||
|  | ||||
| AR_LIKE_M - AR_M | ||||
|  | ||||
| AR_O - AR_LIKE_b | ||||
| AR_O - AR_LIKE_u | ||||
| AR_O - AR_LIKE_i | ||||
| AR_O - AR_LIKE_f | ||||
| AR_O - AR_LIKE_c | ||||
| AR_O - AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b - AR_O | ||||
| AR_LIKE_u - AR_O | ||||
| AR_LIKE_i - AR_O | ||||
| AR_LIKE_f - AR_O | ||||
| AR_LIKE_c - AR_O | ||||
| AR_LIKE_O - AR_O | ||||
|  | ||||
| AR_u += AR_b | ||||
| AR_u += AR_u | ||||
| AR_u += 1  # Allowed during runtime as long as the object is 0D and >=0 | ||||
|  | ||||
| # Array floor division | ||||
|  | ||||
| AR_b // AR_LIKE_b | ||||
| AR_b // AR_LIKE_u | ||||
| AR_b // AR_LIKE_i | ||||
| AR_b // AR_LIKE_f | ||||
| AR_b // AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b // AR_b | ||||
| AR_LIKE_u // AR_b | ||||
| AR_LIKE_i // AR_b | ||||
| AR_LIKE_f // AR_b | ||||
| AR_LIKE_O // AR_b | ||||
|  | ||||
| AR_u // AR_LIKE_b | ||||
| AR_u // AR_LIKE_u | ||||
| AR_u // AR_LIKE_i | ||||
| AR_u // AR_LIKE_f | ||||
| AR_u // AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b // AR_u | ||||
| AR_LIKE_u // AR_u | ||||
| AR_LIKE_i // AR_u | ||||
| AR_LIKE_f // AR_u | ||||
| AR_LIKE_m // AR_u | ||||
| AR_LIKE_O // AR_u | ||||
|  | ||||
| AR_i // AR_LIKE_b | ||||
| AR_i // AR_LIKE_u | ||||
| AR_i // AR_LIKE_i | ||||
| AR_i // AR_LIKE_f | ||||
| AR_i // AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b // AR_i | ||||
| AR_LIKE_u // AR_i | ||||
| AR_LIKE_i // AR_i | ||||
| AR_LIKE_f // AR_i | ||||
| AR_LIKE_m // AR_i | ||||
| AR_LIKE_O // AR_i | ||||
|  | ||||
| AR_f // AR_LIKE_b | ||||
| AR_f // AR_LIKE_u | ||||
| AR_f // AR_LIKE_i | ||||
| AR_f // AR_LIKE_f | ||||
| AR_f // AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b // AR_f | ||||
| AR_LIKE_u // AR_f | ||||
| AR_LIKE_i // AR_f | ||||
| AR_LIKE_f // AR_f | ||||
| AR_LIKE_m // AR_f | ||||
| AR_LIKE_O // AR_f | ||||
|  | ||||
| AR_m // AR_LIKE_u | ||||
| AR_m // AR_LIKE_i | ||||
| AR_m // AR_LIKE_f | ||||
| AR_m // AR_LIKE_m | ||||
|  | ||||
| AR_LIKE_m // AR_m | ||||
|  | ||||
| AR_m /= f | ||||
| AR_m //= f | ||||
| AR_m /= AR_f | ||||
| AR_m /= AR_LIKE_f | ||||
| AR_m //= AR_f | ||||
| AR_m //= AR_LIKE_f | ||||
|  | ||||
| AR_O // AR_LIKE_b | ||||
| AR_O // AR_LIKE_u | ||||
| AR_O // AR_LIKE_i | ||||
| AR_O // AR_LIKE_f | ||||
| AR_O // AR_LIKE_O | ||||
|  | ||||
| AR_LIKE_b // AR_O | ||||
| AR_LIKE_u // AR_O | ||||
| AR_LIKE_i // AR_O | ||||
| AR_LIKE_f // AR_O | ||||
| AR_LIKE_O // AR_O | ||||
|  | ||||
| # Inplace multiplication | ||||
|  | ||||
| AR_b *= AR_LIKE_b | ||||
|  | ||||
| AR_u *= AR_LIKE_b | ||||
| AR_u *= AR_LIKE_u | ||||
|  | ||||
| AR_i *= AR_LIKE_b | ||||
| AR_i *= AR_LIKE_u | ||||
| AR_i *= AR_LIKE_i | ||||
|  | ||||
| AR_integer *= AR_LIKE_b | ||||
| AR_integer *= AR_LIKE_u | ||||
| AR_integer *= AR_LIKE_i | ||||
|  | ||||
| AR_f *= AR_LIKE_b | ||||
| AR_f *= AR_LIKE_u | ||||
| AR_f *= AR_LIKE_i | ||||
| AR_f *= AR_LIKE_f | ||||
|  | ||||
| AR_c *= AR_LIKE_b | ||||
| AR_c *= AR_LIKE_u | ||||
| AR_c *= AR_LIKE_i | ||||
| AR_c *= AR_LIKE_f | ||||
| AR_c *= AR_LIKE_c | ||||
|  | ||||
| AR_m *= AR_LIKE_b | ||||
| AR_m *= AR_LIKE_u | ||||
| AR_m *= AR_LIKE_i | ||||
| AR_m *= AR_LIKE_f | ||||
|  | ||||
| AR_O *= AR_LIKE_b | ||||
| AR_O *= AR_LIKE_u | ||||
| AR_O *= AR_LIKE_i | ||||
| AR_O *= AR_LIKE_f | ||||
| AR_O *= AR_LIKE_c | ||||
| AR_O *= AR_LIKE_O | ||||
|  | ||||
| # Inplace power | ||||
|  | ||||
| AR_u **= AR_LIKE_b | ||||
| AR_u **= AR_LIKE_u | ||||
|  | ||||
| AR_i **= AR_LIKE_b | ||||
| AR_i **= AR_LIKE_u | ||||
| AR_i **= AR_LIKE_i | ||||
|  | ||||
| AR_integer **= AR_LIKE_b | ||||
| AR_integer **= AR_LIKE_u | ||||
| AR_integer **= AR_LIKE_i | ||||
|  | ||||
| AR_f **= AR_LIKE_b | ||||
| AR_f **= AR_LIKE_u | ||||
| AR_f **= AR_LIKE_i | ||||
| AR_f **= AR_LIKE_f | ||||
|  | ||||
| AR_c **= AR_LIKE_b | ||||
| AR_c **= AR_LIKE_u | ||||
| AR_c **= AR_LIKE_i | ||||
| AR_c **= AR_LIKE_f | ||||
| AR_c **= AR_LIKE_c | ||||
|  | ||||
| AR_O **= AR_LIKE_b | ||||
| AR_O **= AR_LIKE_u | ||||
| AR_O **= AR_LIKE_i | ||||
| AR_O **= AR_LIKE_f | ||||
| AR_O **= AR_LIKE_c | ||||
| AR_O **= AR_LIKE_O | ||||
|  | ||||
| # unary ops | ||||
|  | ||||
| -c16 | ||||
| -c8 | ||||
| -f8 | ||||
| -f4 | ||||
| -i8 | ||||
| -i4 | ||||
| with pytest.warns(RuntimeWarning): | ||||
|     -u8 | ||||
|     -u4 | ||||
| -td | ||||
| -AR_f | ||||
|  | ||||
| +c16 | ||||
| +c8 | ||||
| +f8 | ||||
| +f4 | ||||
| +i8 | ||||
| +i4 | ||||
| +u8 | ||||
| +u4 | ||||
| +td | ||||
| +AR_f | ||||
|  | ||||
| abs(c16) | ||||
| abs(c8) | ||||
| abs(f8) | ||||
| abs(f4) | ||||
| abs(i8) | ||||
| abs(i4) | ||||
| abs(u8) | ||||
| abs(u4) | ||||
| abs(td) | ||||
| abs(b_) | ||||
| abs(AR_f) | ||||
|  | ||||
| # Time structures | ||||
|  | ||||
| dt + td | ||||
| dt + i | ||||
| dt + i4 | ||||
| dt + i8 | ||||
| dt - dt | ||||
| dt - i | ||||
| dt - i4 | ||||
| dt - i8 | ||||
|  | ||||
| td + td | ||||
| td + i | ||||
| td + i4 | ||||
| td + i8 | ||||
| td - td | ||||
| td - i | ||||
| td - i4 | ||||
| td - i8 | ||||
| td / f | ||||
| td / f4 | ||||
| td / f8 | ||||
| td / td | ||||
| td // td | ||||
| td % td | ||||
|  | ||||
|  | ||||
| # boolean | ||||
|  | ||||
| b_ / b | ||||
| b_ / b_ | ||||
| b_ / i | ||||
| b_ / i8 | ||||
| b_ / i4 | ||||
| b_ / u8 | ||||
| b_ / u4 | ||||
| b_ / f | ||||
| b_ / f8 | ||||
| b_ / f4 | ||||
| b_ / c | ||||
| b_ / c16 | ||||
| b_ / c8 | ||||
|  | ||||
| b / b_ | ||||
| b_ / b_ | ||||
| i / b_ | ||||
| i8 / b_ | ||||
| i4 / b_ | ||||
| u8 / b_ | ||||
| u4 / b_ | ||||
| f / b_ | ||||
| f8 / b_ | ||||
| f4 / b_ | ||||
| c / b_ | ||||
| c16 / b_ | ||||
| c8 / b_ | ||||
|  | ||||
| # Complex | ||||
|  | ||||
| c16 + c16 | ||||
| c16 + f8 | ||||
| c16 + i8 | ||||
| c16 + c8 | ||||
| c16 + f4 | ||||
| c16 + i4 | ||||
| c16 + b_ | ||||
| c16 + b | ||||
| c16 + c | ||||
| c16 + f | ||||
| c16 + i | ||||
| c16 + AR_f | ||||
|  | ||||
| c16 + c16 | ||||
| f8 + c16 | ||||
| i8 + c16 | ||||
| c8 + c16 | ||||
| f4 + c16 | ||||
| i4 + c16 | ||||
| b_ + c16 | ||||
| b + c16 | ||||
| c + c16 | ||||
| f + c16 | ||||
| i + c16 | ||||
| AR_f + c16 | ||||
|  | ||||
| c8 + c16 | ||||
| c8 + f8 | ||||
| c8 + i8 | ||||
| c8 + c8 | ||||
| c8 + f4 | ||||
| c8 + i4 | ||||
| c8 + b_ | ||||
| c8 + b | ||||
| c8 + c | ||||
| c8 + f | ||||
| c8 + i | ||||
| c8 + AR_f | ||||
|  | ||||
| c16 + c8 | ||||
| f8 + c8 | ||||
| i8 + c8 | ||||
| c8 + c8 | ||||
| f4 + c8 | ||||
| i4 + c8 | ||||
| b_ + c8 | ||||
| b + c8 | ||||
| c + c8 | ||||
| f + c8 | ||||
| i + c8 | ||||
| AR_f + c8 | ||||
|  | ||||
| # Float | ||||
|  | ||||
| f8 + f8 | ||||
| f8 + i8 | ||||
| f8 + f4 | ||||
| f8 + i4 | ||||
| f8 + b_ | ||||
| f8 + b | ||||
| f8 + c | ||||
| f8 + f | ||||
| f8 + i | ||||
| f8 + AR_f | ||||
|  | ||||
| f8 + f8 | ||||
| i8 + f8 | ||||
| f4 + f8 | ||||
| i4 + f8 | ||||
| b_ + f8 | ||||
| b + f8 | ||||
| c + f8 | ||||
| f + f8 | ||||
| i + f8 | ||||
| AR_f + f8 | ||||
|  | ||||
| f4 + f8 | ||||
| f4 + i8 | ||||
| f4 + f4 | ||||
| f4 + i4 | ||||
| f4 + b_ | ||||
| f4 + b | ||||
| f4 + c | ||||
| f4 + f | ||||
| f4 + i | ||||
| f4 + AR_f | ||||
|  | ||||
| f8 + f4 | ||||
| i8 + f4 | ||||
| f4 + f4 | ||||
| i4 + f4 | ||||
| b_ + f4 | ||||
| b + f4 | ||||
| c + f4 | ||||
| f + f4 | ||||
| i + f4 | ||||
| AR_f + f4 | ||||
|  | ||||
| # Int | ||||
|  | ||||
| i8 + i8 | ||||
| i8 + u8 | ||||
| i8 + i4 | ||||
| i8 + u4 | ||||
| i8 + b_ | ||||
| i8 + b | ||||
| i8 + c | ||||
| i8 + f | ||||
| i8 + i | ||||
| i8 + AR_f | ||||
|  | ||||
| u8 + u8 | ||||
| u8 + i4 | ||||
| u8 + u4 | ||||
| u8 + b_ | ||||
| u8 + b | ||||
| u8 + c | ||||
| u8 + f | ||||
| u8 + i | ||||
| u8 + AR_f | ||||
|  | ||||
| i8 + i8 | ||||
| u8 + i8 | ||||
| i4 + i8 | ||||
| u4 + i8 | ||||
| b_ + i8 | ||||
| b + i8 | ||||
| c + i8 | ||||
| f + i8 | ||||
| i + i8 | ||||
| AR_f + i8 | ||||
|  | ||||
| u8 + u8 | ||||
| i4 + u8 | ||||
| u4 + u8 | ||||
| b_ + u8 | ||||
| b + u8 | ||||
| c + u8 | ||||
| f + u8 | ||||
| i + u8 | ||||
| AR_f + u8 | ||||
|  | ||||
| i4 + i8 | ||||
| i4 + i4 | ||||
| i4 + i | ||||
| i4 + b_ | ||||
| i4 + b | ||||
| i4 + AR_f | ||||
|  | ||||
| u4 + i8 | ||||
| u4 + i4 | ||||
| u4 + u8 | ||||
| u4 + u4 | ||||
| u4 + i | ||||
| u4 + b_ | ||||
| u4 + b | ||||
| u4 + AR_f | ||||
|  | ||||
| i8 + i4 | ||||
| i4 + i4 | ||||
| i + i4 | ||||
| b_ + i4 | ||||
| b + i4 | ||||
| AR_f + i4 | ||||
|  | ||||
| i8 + u4 | ||||
| i4 + u4 | ||||
| u8 + u4 | ||||
| u4 + u4 | ||||
| b_ + u4 | ||||
| b + u4 | ||||
| i + u4 | ||||
| AR_f + u4 | ||||
| @ -0,0 +1,137 @@ | ||||
| from typing import Any | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| class Index: | ||||
|     def __index__(self) -> int: | ||||
|         return 0 | ||||
|  | ||||
|  | ||||
| class SubClass(npt.NDArray[np.float64]): | ||||
|     pass | ||||
|  | ||||
|  | ||||
| def func(i: int, j: int, **kwargs: Any) -> SubClass: | ||||
|     return B | ||||
|  | ||||
|  | ||||
| i8 = np.int64(1) | ||||
|  | ||||
| A = np.array([1]) | ||||
| B = A.view(SubClass).copy() | ||||
| B_stack = np.array([[1], [1]]).view(SubClass) | ||||
| C = [1] | ||||
|  | ||||
| np.ndarray(Index()) | ||||
| np.ndarray([Index()]) | ||||
|  | ||||
| np.array(1, dtype=float) | ||||
| np.array(1, copy=None) | ||||
| np.array(1, order='F') | ||||
| np.array(1, order=None) | ||||
| np.array(1, subok=True) | ||||
| np.array(1, ndmin=3) | ||||
| np.array(1, str, copy=True, order='C', subok=False, ndmin=2) | ||||
|  | ||||
| np.asarray(A) | ||||
| np.asarray(B) | ||||
| np.asarray(C) | ||||
|  | ||||
| np.asanyarray(A) | ||||
| np.asanyarray(B) | ||||
| np.asanyarray(B, dtype=int) | ||||
| np.asanyarray(C) | ||||
|  | ||||
| np.ascontiguousarray(A) | ||||
| np.ascontiguousarray(B) | ||||
| np.ascontiguousarray(C) | ||||
|  | ||||
| np.asfortranarray(A) | ||||
| np.asfortranarray(B) | ||||
| np.asfortranarray(C) | ||||
|  | ||||
| np.require(A) | ||||
| np.require(B) | ||||
| np.require(B, dtype=int) | ||||
| np.require(B, requirements=None) | ||||
| np.require(B, requirements="E") | ||||
| np.require(B, requirements=["ENSUREARRAY"]) | ||||
| np.require(B, requirements={"F", "E"}) | ||||
| np.require(B, requirements=["C", "OWNDATA"]) | ||||
| np.require(B, requirements="W") | ||||
| np.require(B, requirements="A") | ||||
| np.require(C) | ||||
|  | ||||
| np.linspace(0, 2) | ||||
| np.linspace(0.5, [0, 1, 2]) | ||||
| np.linspace([0, 1, 2], 3) | ||||
| np.linspace(0j, 2) | ||||
| np.linspace(0, 2, num=10) | ||||
| np.linspace(0, 2, endpoint=True) | ||||
| np.linspace(0, 2, retstep=True) | ||||
| np.linspace(0j, 2j, retstep=True) | ||||
| np.linspace(0, 2, dtype=bool) | ||||
| np.linspace([0, 1], [2, 3], axis=Index()) | ||||
|  | ||||
| np.logspace(0, 2, base=2) | ||||
| np.logspace(0, 2, base=2) | ||||
| np.logspace(0, 2, base=[1j, 2j], num=2) | ||||
|  | ||||
| np.geomspace(1, 2) | ||||
|  | ||||
| np.zeros_like(A) | ||||
| np.zeros_like(C) | ||||
| np.zeros_like(B) | ||||
| np.zeros_like(B, dtype=np.int64) | ||||
|  | ||||
| np.ones_like(A) | ||||
| np.ones_like(C) | ||||
| np.ones_like(B) | ||||
| np.ones_like(B, dtype=np.int64) | ||||
|  | ||||
| np.empty_like(A) | ||||
| np.empty_like(C) | ||||
| np.empty_like(B) | ||||
| np.empty_like(B, dtype=np.int64) | ||||
|  | ||||
| np.full_like(A, i8) | ||||
| np.full_like(C, i8) | ||||
| np.full_like(B, i8) | ||||
| np.full_like(B, i8, dtype=np.int64) | ||||
|  | ||||
| np.ones(1) | ||||
| np.ones([1, 1, 1]) | ||||
|  | ||||
| np.full(1, i8) | ||||
| np.full([1, 1, 1], i8) | ||||
|  | ||||
| np.indices([1, 2, 3]) | ||||
| np.indices([1, 2, 3], sparse=True) | ||||
|  | ||||
| np.fromfunction(func, (3, 5)) | ||||
|  | ||||
| np.identity(10) | ||||
|  | ||||
| np.atleast_1d(C) | ||||
| np.atleast_1d(A) | ||||
| np.atleast_1d(C, C) | ||||
| np.atleast_1d(C, A) | ||||
| np.atleast_1d(A, A) | ||||
|  | ||||
| np.atleast_2d(C) | ||||
|  | ||||
| np.atleast_3d(C) | ||||
|  | ||||
| np.vstack([C, C]) | ||||
| np.vstack([C, A]) | ||||
| np.vstack([A, A]) | ||||
|  | ||||
| np.hstack([C, C]) | ||||
|  | ||||
| np.stack([C, C]) | ||||
| np.stack([C, C], axis=0) | ||||
| np.stack([C, C], out=B_stack) | ||||
|  | ||||
| np.block([[C, C], [C, C]]) | ||||
| np.block(A) | ||||
| @ -0,0 +1,43 @@ | ||||
| from __future__ import annotations | ||||
|  | ||||
| from typing import TYPE_CHECKING | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
| if TYPE_CHECKING: | ||||
|     from numpy._typing import NDArray, ArrayLike, _SupportsArray | ||||
|  | ||||
| x1: ArrayLike = True | ||||
| x2: ArrayLike = 5 | ||||
| x3: ArrayLike = 1.0 | ||||
| x4: ArrayLike = 1 + 1j | ||||
| x5: ArrayLike = np.int8(1) | ||||
| x6: ArrayLike = np.float64(1) | ||||
| x7: ArrayLike = np.complex128(1) | ||||
| x8: ArrayLike = np.array([1, 2, 3]) | ||||
| x9: ArrayLike = [1, 2, 3] | ||||
| x10: ArrayLike = (1, 2, 3) | ||||
| x11: ArrayLike = "foo" | ||||
| x12: ArrayLike = memoryview(b'foo') | ||||
|  | ||||
|  | ||||
| class A: | ||||
|     def __array__(self, dtype: np.dtype | None = None) -> NDArray[np.float64]: | ||||
|         return np.array([1.0, 2.0, 3.0]) | ||||
|  | ||||
|  | ||||
| x13: ArrayLike = A() | ||||
|  | ||||
| scalar: _SupportsArray[np.dtype[np.int64]] = np.int64(1) | ||||
| scalar.__array__() | ||||
| array: _SupportsArray[np.dtype[np.int_]] = np.array(1) | ||||
| array.__array__() | ||||
|  | ||||
| a: _SupportsArray[np.dtype[np.float64]] = A() | ||||
| a.__array__() | ||||
| a.__array__() | ||||
|  | ||||
| # Escape hatch for when you mean to make something like an object | ||||
| # array. | ||||
| object_array_scalar: object = (i for i in range(10)) | ||||
| np.array(object_array_scalar) | ||||
| @ -0,0 +1,37 @@ | ||||
| import numpy as np | ||||
|  | ||||
| AR = np.arange(10) | ||||
| AR.setflags(write=False) | ||||
|  | ||||
| with np.printoptions(): | ||||
|     np.set_printoptions( | ||||
|         precision=1, | ||||
|         threshold=2, | ||||
|         edgeitems=3, | ||||
|         linewidth=4, | ||||
|         suppress=False, | ||||
|         nanstr="Bob", | ||||
|         infstr="Bill", | ||||
|         formatter={}, | ||||
|         sign="+", | ||||
|         floatmode="unique", | ||||
|     ) | ||||
|     np.get_printoptions() | ||||
|     str(AR) | ||||
|  | ||||
|     np.array2string( | ||||
|         AR, | ||||
|         max_line_width=5, | ||||
|         precision=2, | ||||
|         suppress_small=True, | ||||
|         separator=";", | ||||
|         prefix="test", | ||||
|         threshold=5, | ||||
|         floatmode="fixed", | ||||
|         suffix="?", | ||||
|         legacy="1.13", | ||||
|     ) | ||||
|     np.format_float_scientific(1, precision=5) | ||||
|     np.format_float_positional(1, trim="k") | ||||
|     np.array_repr(AR) | ||||
|     np.array_str(AR) | ||||
| @ -0,0 +1,27 @@ | ||||
|  | ||||
| from __future__ import annotations | ||||
|  | ||||
| from typing import Any | ||||
| import numpy as np | ||||
|  | ||||
| AR_i8: np.ndarray[Any, np.dtype[np.int_]] = np.arange(10) | ||||
| ar_iter = np.lib.Arrayterator(AR_i8) | ||||
|  | ||||
| ar_iter.var | ||||
| ar_iter.buf_size | ||||
| ar_iter.start | ||||
| ar_iter.stop | ||||
| ar_iter.step | ||||
| ar_iter.shape | ||||
| ar_iter.flat | ||||
|  | ||||
| ar_iter.__array__() | ||||
|  | ||||
| for i in ar_iter: | ||||
|     pass | ||||
|  | ||||
| ar_iter[0] | ||||
| ar_iter[...] | ||||
| ar_iter[:] | ||||
| ar_iter[0, 0, 0] | ||||
| ar_iter[..., 0, :] | ||||
| @ -0,0 +1,131 @@ | ||||
| import numpy as np | ||||
|  | ||||
| i8 = np.int64(1) | ||||
| u8 = np.uint64(1) | ||||
|  | ||||
| i4 = np.int32(1) | ||||
| u4 = np.uint32(1) | ||||
|  | ||||
| b_ = np.bool(1) | ||||
|  | ||||
| b = bool(1) | ||||
| i = int(1) | ||||
|  | ||||
| AR = np.array([0, 1, 2], dtype=np.int32) | ||||
| AR.setflags(write=False) | ||||
|  | ||||
|  | ||||
| i8 << i8 | ||||
| i8 >> i8 | ||||
| i8 | i8 | ||||
| i8 ^ i8 | ||||
| i8 & i8 | ||||
|  | ||||
| i << AR | ||||
| i >> AR | ||||
| i | AR | ||||
| i ^ AR | ||||
| i & AR | ||||
|  | ||||
| i8 << AR | ||||
| i8 >> AR | ||||
| i8 | AR | ||||
| i8 ^ AR | ||||
| i8 & AR | ||||
|  | ||||
| i4 << i4 | ||||
| i4 >> i4 | ||||
| i4 | i4 | ||||
| i4 ^ i4 | ||||
| i4 & i4 | ||||
|  | ||||
| i8 << i4 | ||||
| i8 >> i4 | ||||
| i8 | i4 | ||||
| i8 ^ i4 | ||||
| i8 & i4 | ||||
|  | ||||
| i8 << i | ||||
| i8 >> i | ||||
| i8 | i | ||||
| i8 ^ i | ||||
| i8 & i | ||||
|  | ||||
| i8 << b_ | ||||
| i8 >> b_ | ||||
| i8 | b_ | ||||
| i8 ^ b_ | ||||
| i8 & b_ | ||||
|  | ||||
| i8 << b | ||||
| i8 >> b | ||||
| i8 | b | ||||
| i8 ^ b | ||||
| i8 & b | ||||
|  | ||||
| u8 << u8 | ||||
| u8 >> u8 | ||||
| u8 | u8 | ||||
| u8 ^ u8 | ||||
| u8 & u8 | ||||
|  | ||||
| u4 << u4 | ||||
| u4 >> u4 | ||||
| u4 | u4 | ||||
| u4 ^ u4 | ||||
| u4 & u4 | ||||
|  | ||||
| u4 << i4 | ||||
| u4 >> i4 | ||||
| u4 | i4 | ||||
| u4 ^ i4 | ||||
| u4 & i4 | ||||
|  | ||||
| u4 << i | ||||
| u4 >> i | ||||
| u4 | i | ||||
| u4 ^ i | ||||
| u4 & i | ||||
|  | ||||
| u8 << b_ | ||||
| u8 >> b_ | ||||
| u8 | b_ | ||||
| u8 ^ b_ | ||||
| u8 & b_ | ||||
|  | ||||
| u8 << b | ||||
| u8 >> b | ||||
| u8 | b | ||||
| u8 ^ b | ||||
| u8 & b | ||||
|  | ||||
| b_ << b_ | ||||
| b_ >> b_ | ||||
| b_ | b_ | ||||
| b_ ^ b_ | ||||
| b_ & b_ | ||||
|  | ||||
| b_ << AR | ||||
| b_ >> AR | ||||
| b_ | AR | ||||
| b_ ^ AR | ||||
| b_ & AR | ||||
|  | ||||
| b_ << b | ||||
| b_ >> b | ||||
| b_ | b | ||||
| b_ ^ b | ||||
| b_ & b | ||||
|  | ||||
| b_ << i | ||||
| b_ >> i | ||||
| b_ | i | ||||
| b_ ^ i | ||||
| b_ & i | ||||
|  | ||||
| ~i8 | ||||
| ~i4 | ||||
| ~u8 | ||||
| ~u4 | ||||
| ~b_ | ||||
| ~AR | ||||
| @ -0,0 +1,315 @@ | ||||
| from __future__ import annotations | ||||
|  | ||||
| from typing import cast, Any | ||||
| import numpy as np | ||||
|  | ||||
| c16 = np.complex128() | ||||
| f8 = np.float64() | ||||
| i8 = np.int64() | ||||
| u8 = np.uint64() | ||||
|  | ||||
| c8 = np.complex64() | ||||
| f4 = np.float32() | ||||
| i4 = np.int32() | ||||
| u4 = np.uint32() | ||||
|  | ||||
| dt = np.datetime64(0, "D") | ||||
| td = np.timedelta64(0, "D") | ||||
|  | ||||
| b_ = np.bool() | ||||
|  | ||||
| b = bool() | ||||
| c = complex() | ||||
| f = float() | ||||
| i = int() | ||||
|  | ||||
| SEQ = (0, 1, 2, 3, 4) | ||||
|  | ||||
| AR_b: np.ndarray[Any, np.dtype[np.bool]] = np.array([True]) | ||||
| AR_u: np.ndarray[Any, np.dtype[np.uint32]] = np.array([1], dtype=np.uint32) | ||||
| AR_i: np.ndarray[Any, np.dtype[np.int_]] = np.array([1]) | ||||
| AR_f: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0]) | ||||
| AR_c: np.ndarray[Any, np.dtype[np.complex128]] = np.array([1.0j]) | ||||
| AR_S: np.ndarray[Any, np.dtype[np.bytes_]] = np.array([b"a"], "S") | ||||
| AR_T = cast(np.ndarray[Any, np.dtypes.StringDType], np.array(["a"], "T")) | ||||
| AR_U: np.ndarray[Any, np.dtype[np.str_]] = np.array(["a"], "U") | ||||
| AR_m: np.ndarray[Any, np.dtype[np.timedelta64]] = np.array([np.timedelta64("1")]) | ||||
| AR_M: np.ndarray[Any, np.dtype[np.datetime64]] = np.array([np.datetime64("1")]) | ||||
| AR_O: np.ndarray[Any, np.dtype[np.object_]] = np.array([1], dtype=object) | ||||
|  | ||||
| # Arrays | ||||
|  | ||||
| AR_b > AR_b | ||||
| AR_b > AR_u | ||||
| AR_b > AR_i | ||||
| AR_b > AR_f | ||||
| AR_b > AR_c | ||||
|  | ||||
| AR_u > AR_b | ||||
| AR_u > AR_u | ||||
| AR_u > AR_i | ||||
| AR_u > AR_f | ||||
| AR_u > AR_c | ||||
|  | ||||
| AR_i > AR_b | ||||
| AR_i > AR_u | ||||
| AR_i > AR_i | ||||
| AR_i > AR_f | ||||
| AR_i > AR_c | ||||
|  | ||||
| AR_f > AR_b | ||||
| AR_f > AR_u | ||||
| AR_f > AR_i | ||||
| AR_f > AR_f | ||||
| AR_f > AR_c | ||||
|  | ||||
| AR_c > AR_b | ||||
| AR_c > AR_u | ||||
| AR_c > AR_i | ||||
| AR_c > AR_f | ||||
| AR_c > AR_c | ||||
|  | ||||
| AR_S > AR_S | ||||
| AR_S > b"" | ||||
|  | ||||
| AR_T > AR_T | ||||
| AR_T > AR_U | ||||
| AR_T > "" | ||||
|  | ||||
| AR_U > AR_U | ||||
| AR_U > AR_T | ||||
| AR_U > "" | ||||
|  | ||||
| AR_m > AR_b | ||||
| AR_m > AR_u | ||||
| AR_m > AR_i | ||||
| AR_b > AR_m | ||||
| AR_u > AR_m | ||||
| AR_i > AR_m | ||||
|  | ||||
| AR_M > AR_M | ||||
|  | ||||
| AR_O > AR_O | ||||
| 1 > AR_O | ||||
| AR_O > 1 | ||||
|  | ||||
| # Time structures | ||||
|  | ||||
| dt > dt | ||||
|  | ||||
| td > td | ||||
| td > i | ||||
| td > i4 | ||||
| td > i8 | ||||
| td > AR_i | ||||
| td > SEQ | ||||
|  | ||||
| # boolean | ||||
|  | ||||
| b_ > b | ||||
| b_ > b_ | ||||
| b_ > i | ||||
| b_ > i8 | ||||
| b_ > i4 | ||||
| b_ > u8 | ||||
| b_ > u4 | ||||
| b_ > f | ||||
| b_ > f8 | ||||
| b_ > f4 | ||||
| b_ > c | ||||
| b_ > c16 | ||||
| b_ > c8 | ||||
| b_ > AR_i | ||||
| b_ > SEQ | ||||
|  | ||||
| # Complex | ||||
|  | ||||
| c16 > c16 | ||||
| c16 > f8 | ||||
| c16 > i8 | ||||
| c16 > c8 | ||||
| c16 > f4 | ||||
| c16 > i4 | ||||
| c16 > b_ | ||||
| c16 > b | ||||
| c16 > c | ||||
| c16 > f | ||||
| c16 > i | ||||
| c16 > AR_i | ||||
| c16 > SEQ | ||||
|  | ||||
| c16 > c16 | ||||
| f8 > c16 | ||||
| i8 > c16 | ||||
| c8 > c16 | ||||
| f4 > c16 | ||||
| i4 > c16 | ||||
| b_ > c16 | ||||
| b > c16 | ||||
| c > c16 | ||||
| f > c16 | ||||
| i > c16 | ||||
| AR_i > c16 | ||||
| SEQ > c16 | ||||
|  | ||||
| c8 > c16 | ||||
| c8 > f8 | ||||
| c8 > i8 | ||||
| c8 > c8 | ||||
| c8 > f4 | ||||
| c8 > i4 | ||||
| c8 > b_ | ||||
| c8 > b | ||||
| c8 > c | ||||
| c8 > f | ||||
| c8 > i | ||||
| c8 > AR_i | ||||
| c8 > SEQ | ||||
|  | ||||
| c16 > c8 | ||||
| f8 > c8 | ||||
| i8 > c8 | ||||
| c8 > c8 | ||||
| f4 > c8 | ||||
| i4 > c8 | ||||
| b_ > c8 | ||||
| b > c8 | ||||
| c > c8 | ||||
| f > c8 | ||||
| i > c8 | ||||
| AR_i > c8 | ||||
| SEQ > c8 | ||||
|  | ||||
| # Float | ||||
|  | ||||
| f8 > f8 | ||||
| f8 > i8 | ||||
| f8 > f4 | ||||
| f8 > i4 | ||||
| f8 > b_ | ||||
| f8 > b | ||||
| f8 > c | ||||
| f8 > f | ||||
| f8 > i | ||||
| f8 > AR_i | ||||
| f8 > SEQ | ||||
|  | ||||
| f8 > f8 | ||||
| i8 > f8 | ||||
| f4 > f8 | ||||
| i4 > f8 | ||||
| b_ > f8 | ||||
| b > f8 | ||||
| c > f8 | ||||
| f > f8 | ||||
| i > f8 | ||||
| AR_i > f8 | ||||
| SEQ > f8 | ||||
|  | ||||
| f4 > f8 | ||||
| f4 > i8 | ||||
| f4 > f4 | ||||
| f4 > i4 | ||||
| f4 > b_ | ||||
| f4 > b | ||||
| f4 > c | ||||
| f4 > f | ||||
| f4 > i | ||||
| f4 > AR_i | ||||
| f4 > SEQ | ||||
|  | ||||
| f8 > f4 | ||||
| i8 > f4 | ||||
| f4 > f4 | ||||
| i4 > f4 | ||||
| b_ > f4 | ||||
| b > f4 | ||||
| c > f4 | ||||
| f > f4 | ||||
| i > f4 | ||||
| AR_i > f4 | ||||
| SEQ > f4 | ||||
|  | ||||
| # Int | ||||
|  | ||||
| i8 > i8 | ||||
| i8 > u8 | ||||
| i8 > i4 | ||||
| i8 > u4 | ||||
| i8 > b_ | ||||
| i8 > b | ||||
| i8 > c | ||||
| i8 > f | ||||
| i8 > i | ||||
| i8 > AR_i | ||||
| i8 > SEQ | ||||
|  | ||||
| u8 > u8 | ||||
| u8 > i4 | ||||
| u8 > u4 | ||||
| u8 > b_ | ||||
| u8 > b | ||||
| u8 > c | ||||
| u8 > f | ||||
| u8 > i | ||||
| u8 > AR_i | ||||
| u8 > SEQ | ||||
|  | ||||
| i8 > i8 | ||||
| u8 > i8 | ||||
| i4 > i8 | ||||
| u4 > i8 | ||||
| b_ > i8 | ||||
| b > i8 | ||||
| c > i8 | ||||
| f > i8 | ||||
| i > i8 | ||||
| AR_i > i8 | ||||
| SEQ > i8 | ||||
|  | ||||
| u8 > u8 | ||||
| i4 > u8 | ||||
| u4 > u8 | ||||
| b_ > u8 | ||||
| b > u8 | ||||
| c > u8 | ||||
| f > u8 | ||||
| i > u8 | ||||
| AR_i > u8 | ||||
| SEQ > u8 | ||||
|  | ||||
| i4 > i8 | ||||
| i4 > i4 | ||||
| i4 > i | ||||
| i4 > b_ | ||||
| i4 > b | ||||
| i4 > AR_i | ||||
| i4 > SEQ | ||||
|  | ||||
| u4 > i8 | ||||
| u4 > i4 | ||||
| u4 > u8 | ||||
| u4 > u4 | ||||
| u4 > i | ||||
| u4 > b_ | ||||
| u4 > b | ||||
| u4 > AR_i | ||||
| u4 > SEQ | ||||
|  | ||||
| i8 > i4 | ||||
| i4 > i4 | ||||
| i > i4 | ||||
| b_ > i4 | ||||
| b > i4 | ||||
| AR_i > i4 | ||||
| SEQ > i4 | ||||
|  | ||||
| i8 > u4 | ||||
| i4 > u4 | ||||
| u8 > u4 | ||||
| u4 > u4 | ||||
| b_ > u4 | ||||
| b > u4 | ||||
| i > u4 | ||||
| AR_i > u4 | ||||
| SEQ > u4 | ||||
| @ -0,0 +1,57 @@ | ||||
| import numpy as np | ||||
|  | ||||
| dtype_obj = np.dtype(np.str_) | ||||
| void_dtype_obj = np.dtype([("f0", np.float64), ("f1", np.float32)]) | ||||
|  | ||||
| np.dtype(dtype=np.int64) | ||||
| np.dtype(int) | ||||
| np.dtype("int") | ||||
| np.dtype(None) | ||||
|  | ||||
| np.dtype((int, 2)) | ||||
| np.dtype((int, (1,))) | ||||
|  | ||||
| np.dtype({"names": ["a", "b"], "formats": [int, float]}) | ||||
| np.dtype({"names": ["a"], "formats": [int], "titles": [object]}) | ||||
| np.dtype({"names": ["a"], "formats": [int], "titles": [object()]}) | ||||
|  | ||||
| np.dtype([("name", np.str_, 16), ("grades", np.float64, (2,)), ("age", "int32")]) | ||||
|  | ||||
| np.dtype( | ||||
|     { | ||||
|         "names": ["a", "b"], | ||||
|         "formats": [int, float], | ||||
|         "itemsize": 9, | ||||
|         "aligned": False, | ||||
|         "titles": ["x", "y"], | ||||
|         "offsets": [0, 1], | ||||
|     } | ||||
| ) | ||||
|  | ||||
| np.dtype((np.float64, float)) | ||||
|  | ||||
|  | ||||
| class Test: | ||||
|     dtype = np.dtype(float) | ||||
|  | ||||
|  | ||||
| np.dtype(Test()) | ||||
|  | ||||
| # Methods and attributes | ||||
| dtype_obj.base | ||||
| dtype_obj.subdtype | ||||
| dtype_obj.newbyteorder() | ||||
| dtype_obj.type | ||||
| dtype_obj.name | ||||
| dtype_obj.names | ||||
|  | ||||
| dtype_obj * 0 | ||||
| dtype_obj * 2 | ||||
|  | ||||
| 0 * dtype_obj | ||||
| 2 * dtype_obj | ||||
|  | ||||
| void_dtype_obj["f0"] | ||||
| void_dtype_obj[0] | ||||
| void_dtype_obj[["f0", "f1"]] | ||||
| void_dtype_obj[["f0"]] | ||||
| @ -0,0 +1,36 @@ | ||||
| from __future__ import annotations | ||||
|  | ||||
| from typing import Any | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
| AR_LIKE_b = [True, True, True] | ||||
| AR_LIKE_u = [np.uint32(1), np.uint32(2), np.uint32(3)] | ||||
| AR_LIKE_i = [1, 2, 3] | ||||
| AR_LIKE_f = [1.0, 2.0, 3.0] | ||||
| AR_LIKE_c = [1j, 2j, 3j] | ||||
| AR_LIKE_U = ["1", "2", "3"] | ||||
|  | ||||
| OUT_f: np.ndarray[Any, np.dtype[np.float64]] = np.empty(3, dtype=np.float64) | ||||
| OUT_c: np.ndarray[Any, np.dtype[np.complex128]] = np.empty(3, dtype=np.complex128) | ||||
|  | ||||
| np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_b) | ||||
| np.einsum("i,i->i", AR_LIKE_u, AR_LIKE_u) | ||||
| np.einsum("i,i->i", AR_LIKE_i, AR_LIKE_i) | ||||
| np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f) | ||||
| np.einsum("i,i->i", AR_LIKE_c, AR_LIKE_c) | ||||
| np.einsum("i,i->i", AR_LIKE_b, AR_LIKE_i) | ||||
| np.einsum("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c) | ||||
|  | ||||
| np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f, dtype="c16") | ||||
| np.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=bool, casting="unsafe") | ||||
| np.einsum("i,i->i", AR_LIKE_f, AR_LIKE_f, out=OUT_c) | ||||
| np.einsum("i,i->i", AR_LIKE_U, AR_LIKE_U, dtype=int, casting="unsafe", out=OUT_f) | ||||
|  | ||||
| np.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_b) | ||||
| np.einsum_path("i,i->i", AR_LIKE_u, AR_LIKE_u) | ||||
| np.einsum_path("i,i->i", AR_LIKE_i, AR_LIKE_i) | ||||
| np.einsum_path("i,i->i", AR_LIKE_f, AR_LIKE_f) | ||||
| np.einsum_path("i,i->i", AR_LIKE_c, AR_LIKE_c) | ||||
| np.einsum_path("i,i->i", AR_LIKE_b, AR_LIKE_i) | ||||
| np.einsum_path("i,i,i,i->i", AR_LIKE_b, AR_LIKE_u, AR_LIKE_i, AR_LIKE_c) | ||||
| @ -0,0 +1,19 @@ | ||||
| import numpy as np | ||||
|  | ||||
| a = np.empty((2, 2)).flat | ||||
|  | ||||
| a.base | ||||
| a.copy() | ||||
| a.coords | ||||
| a.index | ||||
| iter(a) | ||||
| next(a) | ||||
| a[0] | ||||
| a[[0, 1, 2]] | ||||
| a[...] | ||||
| a[:] | ||||
| a.__array__() | ||||
| a.__array__(np.dtype(np.float64)) | ||||
|  | ||||
| b = np.array([1]).flat | ||||
| a[b] | ||||
| @ -0,0 +1,272 @@ | ||||
| """Tests for :mod:`numpy._core.fromnumeric`.""" | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
| A = np.array(True, ndmin=2, dtype=bool) | ||||
| B = np.array(1.0, ndmin=2, dtype=np.float32) | ||||
| A.setflags(write=False) | ||||
| B.setflags(write=False) | ||||
|  | ||||
| a = np.bool(True) | ||||
| b = np.float32(1.0) | ||||
| c = 1.0 | ||||
| d = np.array(1.0, dtype=np.float32)  # writeable | ||||
|  | ||||
| np.take(a, 0) | ||||
| np.take(b, 0) | ||||
| np.take(c, 0) | ||||
| np.take(A, 0) | ||||
| np.take(B, 0) | ||||
| np.take(A, [0]) | ||||
| np.take(B, [0]) | ||||
|  | ||||
| np.reshape(a, 1) | ||||
| np.reshape(b, 1) | ||||
| np.reshape(c, 1) | ||||
| np.reshape(A, 1) | ||||
| np.reshape(B, 1) | ||||
|  | ||||
| np.choose(a, [True, True]) | ||||
| np.choose(A, [1.0, 1.0]) | ||||
|  | ||||
| np.repeat(a, 1) | ||||
| np.repeat(b, 1) | ||||
| np.repeat(c, 1) | ||||
| np.repeat(A, 1) | ||||
| np.repeat(B, 1) | ||||
|  | ||||
| np.swapaxes(A, 0, 0) | ||||
| np.swapaxes(B, 0, 0) | ||||
|  | ||||
| np.transpose(a) | ||||
| np.transpose(b) | ||||
| np.transpose(c) | ||||
| np.transpose(A) | ||||
| np.transpose(B) | ||||
|  | ||||
| np.partition(a, 0, axis=None) | ||||
| np.partition(b, 0, axis=None) | ||||
| np.partition(c, 0, axis=None) | ||||
| np.partition(A, 0) | ||||
| np.partition(B, 0) | ||||
|  | ||||
| np.argpartition(a, 0) | ||||
| np.argpartition(b, 0) | ||||
| np.argpartition(c, 0) | ||||
| np.argpartition(A, 0) | ||||
| np.argpartition(B, 0) | ||||
|  | ||||
| np.sort(A, 0) | ||||
| np.sort(B, 0) | ||||
|  | ||||
| np.argsort(A, 0) | ||||
| np.argsort(B, 0) | ||||
|  | ||||
| np.argmax(A) | ||||
| np.argmax(B) | ||||
| np.argmax(A, axis=0) | ||||
| np.argmax(B, axis=0) | ||||
|  | ||||
| np.argmin(A) | ||||
| np.argmin(B) | ||||
| np.argmin(A, axis=0) | ||||
| np.argmin(B, axis=0) | ||||
|  | ||||
| np.searchsorted(A[0], 0) | ||||
| np.searchsorted(B[0], 0) | ||||
| np.searchsorted(A[0], [0]) | ||||
| np.searchsorted(B[0], [0]) | ||||
|  | ||||
| np.resize(a, (5, 5)) | ||||
| np.resize(b, (5, 5)) | ||||
| np.resize(c, (5, 5)) | ||||
| np.resize(A, (5, 5)) | ||||
| np.resize(B, (5, 5)) | ||||
|  | ||||
| np.squeeze(a) | ||||
| np.squeeze(b) | ||||
| np.squeeze(c) | ||||
| np.squeeze(A) | ||||
| np.squeeze(B) | ||||
|  | ||||
| np.diagonal(A) | ||||
| np.diagonal(B) | ||||
|  | ||||
| np.trace(A) | ||||
| np.trace(B) | ||||
|  | ||||
| np.ravel(a) | ||||
| np.ravel(b) | ||||
| np.ravel(c) | ||||
| np.ravel(A) | ||||
| np.ravel(B) | ||||
|  | ||||
| np.nonzero(A) | ||||
| np.nonzero(B) | ||||
|  | ||||
| np.shape(a) | ||||
| np.shape(b) | ||||
| np.shape(c) | ||||
| np.shape(A) | ||||
| np.shape(B) | ||||
|  | ||||
| np.compress([True], a) | ||||
| np.compress([True], b) | ||||
| np.compress([True], c) | ||||
| np.compress([True], A) | ||||
| np.compress([True], B) | ||||
|  | ||||
| np.clip(a, 0, 1.0) | ||||
| np.clip(b, -1, 1) | ||||
| np.clip(a, 0, None) | ||||
| np.clip(b, None, 1) | ||||
| np.clip(c, 0, 1) | ||||
| np.clip(A, 0, 1) | ||||
| np.clip(B, 0, 1) | ||||
| np.clip(B, [0, 1], [1, 2]) | ||||
|  | ||||
| np.sum(a) | ||||
| np.sum(b) | ||||
| np.sum(c) | ||||
| np.sum(A) | ||||
| np.sum(B) | ||||
| np.sum(A, axis=0) | ||||
| np.sum(B, axis=0) | ||||
|  | ||||
| np.all(a) | ||||
| np.all(b) | ||||
| np.all(c) | ||||
| np.all(A) | ||||
| np.all(B) | ||||
| np.all(A, axis=0) | ||||
| np.all(B, axis=0) | ||||
| np.all(A, keepdims=True) | ||||
| np.all(B, keepdims=True) | ||||
|  | ||||
| np.any(a) | ||||
| np.any(b) | ||||
| np.any(c) | ||||
| np.any(A) | ||||
| np.any(B) | ||||
| np.any(A, axis=0) | ||||
| np.any(B, axis=0) | ||||
| np.any(A, keepdims=True) | ||||
| np.any(B, keepdims=True) | ||||
|  | ||||
| np.cumsum(a) | ||||
| np.cumsum(b) | ||||
| np.cumsum(c) | ||||
| np.cumsum(A) | ||||
| np.cumsum(B) | ||||
|  | ||||
| np.cumulative_sum(a) | ||||
| np.cumulative_sum(b) | ||||
| np.cumulative_sum(c) | ||||
| np.cumulative_sum(A, axis=0) | ||||
| np.cumulative_sum(B, axis=0) | ||||
|  | ||||
| np.ptp(b) | ||||
| np.ptp(c) | ||||
| np.ptp(B) | ||||
| np.ptp(B, axis=0) | ||||
| np.ptp(B, keepdims=True) | ||||
|  | ||||
| np.amax(a) | ||||
| np.amax(b) | ||||
| np.amax(c) | ||||
| np.amax(A) | ||||
| np.amax(B) | ||||
| np.amax(A, axis=0) | ||||
| np.amax(B, axis=0) | ||||
| np.amax(A, keepdims=True) | ||||
| np.amax(B, keepdims=True) | ||||
|  | ||||
| np.amin(a) | ||||
| np.amin(b) | ||||
| np.amin(c) | ||||
| np.amin(A) | ||||
| np.amin(B) | ||||
| np.amin(A, axis=0) | ||||
| np.amin(B, axis=0) | ||||
| np.amin(A, keepdims=True) | ||||
| np.amin(B, keepdims=True) | ||||
|  | ||||
| np.prod(a) | ||||
| np.prod(b) | ||||
| np.prod(c) | ||||
| np.prod(A) | ||||
| np.prod(B) | ||||
| np.prod(a, dtype=None) | ||||
| np.prod(A, dtype=None) | ||||
| np.prod(A, axis=0) | ||||
| np.prod(B, axis=0) | ||||
| np.prod(A, keepdims=True) | ||||
| np.prod(B, keepdims=True) | ||||
| np.prod(b, out=d) | ||||
| np.prod(B, out=d) | ||||
|  | ||||
| np.cumprod(a) | ||||
| np.cumprod(b) | ||||
| np.cumprod(c) | ||||
| np.cumprod(A) | ||||
| np.cumprod(B) | ||||
|  | ||||
| np.cumulative_prod(a) | ||||
| np.cumulative_prod(b) | ||||
| np.cumulative_prod(c) | ||||
| np.cumulative_prod(A, axis=0) | ||||
| np.cumulative_prod(B, axis=0) | ||||
|  | ||||
| np.ndim(a) | ||||
| np.ndim(b) | ||||
| np.ndim(c) | ||||
| np.ndim(A) | ||||
| np.ndim(B) | ||||
|  | ||||
| np.size(a) | ||||
| np.size(b) | ||||
| np.size(c) | ||||
| np.size(A) | ||||
| np.size(B) | ||||
|  | ||||
| np.around(a) | ||||
| np.around(b) | ||||
| np.around(c) | ||||
| np.around(A) | ||||
| np.around(B) | ||||
|  | ||||
| np.mean(a) | ||||
| np.mean(b) | ||||
| np.mean(c) | ||||
| np.mean(A) | ||||
| np.mean(B) | ||||
| np.mean(A, axis=0) | ||||
| np.mean(B, axis=0) | ||||
| np.mean(A, keepdims=True) | ||||
| np.mean(B, keepdims=True) | ||||
| np.mean(b, out=d) | ||||
| np.mean(B, out=d) | ||||
|  | ||||
| np.std(a) | ||||
| np.std(b) | ||||
| np.std(c) | ||||
| np.std(A) | ||||
| np.std(B) | ||||
| np.std(A, axis=0) | ||||
| np.std(B, axis=0) | ||||
| np.std(A, keepdims=True) | ||||
| np.std(B, keepdims=True) | ||||
| np.std(b, out=d) | ||||
| np.std(B, out=d) | ||||
|  | ||||
| np.var(a) | ||||
| np.var(b) | ||||
| np.var(c) | ||||
| np.var(A) | ||||
| np.var(B) | ||||
| np.var(A, axis=0) | ||||
| np.var(B, axis=0) | ||||
| np.var(A, keepdims=True) | ||||
| np.var(B, keepdims=True) | ||||
| np.var(b, out=d) | ||||
| np.var(B, out=d) | ||||
| @ -0,0 +1,60 @@ | ||||
| from __future__ import annotations | ||||
| from typing import Any | ||||
| import numpy as np | ||||
|  | ||||
| AR_LIKE_b = [[True, True], [True, True]] | ||||
| AR_LIKE_i = [[1, 2], [3, 4]] | ||||
| AR_LIKE_f = [[1.0, 2.0], [3.0, 4.0]] | ||||
| AR_LIKE_U = [["1", "2"], ["3", "4"]] | ||||
|  | ||||
| AR_i8: np.ndarray[Any, np.dtype[np.int64]] = np.array(AR_LIKE_i, dtype=np.int64) | ||||
|  | ||||
| np.ndenumerate(AR_i8) | ||||
| np.ndenumerate(AR_LIKE_f) | ||||
| np.ndenumerate(AR_LIKE_U) | ||||
|  | ||||
| next(np.ndenumerate(AR_i8)) | ||||
| next(np.ndenumerate(AR_LIKE_f)) | ||||
| next(np.ndenumerate(AR_LIKE_U)) | ||||
|  | ||||
| iter(np.ndenumerate(AR_i8)) | ||||
| iter(np.ndenumerate(AR_LIKE_f)) | ||||
| iter(np.ndenumerate(AR_LIKE_U)) | ||||
|  | ||||
| iter(np.ndindex(1, 2, 3)) | ||||
| next(np.ndindex(1, 2, 3)) | ||||
|  | ||||
| np.unravel_index([22, 41, 37], (7, 6)) | ||||
| np.unravel_index([31, 41, 13], (7, 6), order='F') | ||||
| np.unravel_index(1621, (6, 7, 8, 9)) | ||||
|  | ||||
| np.ravel_multi_index(AR_LIKE_i, (7, 6)) | ||||
| np.ravel_multi_index(AR_LIKE_i, (7, 6), order='F') | ||||
| np.ravel_multi_index(AR_LIKE_i, (4, 6), mode='clip') | ||||
| np.ravel_multi_index(AR_LIKE_i, (4, 4), mode=('clip', 'wrap')) | ||||
| np.ravel_multi_index((3, 1, 4, 1), (6, 7, 8, 9)) | ||||
|  | ||||
| np.mgrid[1:1:2] | ||||
| np.mgrid[1:1:2, None:10] | ||||
|  | ||||
| np.ogrid[1:1:2] | ||||
| np.ogrid[1:1:2, None:10] | ||||
|  | ||||
| np.index_exp[0:1] | ||||
| np.index_exp[0:1, None:3] | ||||
| np.index_exp[0, 0:1, ..., [0, 1, 3]] | ||||
|  | ||||
| np.s_[0:1] | ||||
| np.s_[0:1, None:3] | ||||
| np.s_[0, 0:1, ..., [0, 1, 3]] | ||||
|  | ||||
| np.ix_(AR_LIKE_b[0]) | ||||
| np.ix_(AR_LIKE_i[0], AR_LIKE_f[0]) | ||||
| np.ix_(AR_i8[0]) | ||||
|  | ||||
| np.fill_diagonal(AR_i8, 5) | ||||
|  | ||||
| np.diag_indices(4) | ||||
| np.diag_indices(2, 3) | ||||
|  | ||||
| np.diag_indices_from(AR_i8) | ||||
| @ -0,0 +1,22 @@ | ||||
| """Based on the `if __name__ == "__main__"` test code in `lib/_user_array_impl.py`.""" | ||||
|  | ||||
| from __future__ import annotations | ||||
|  | ||||
| import numpy as np | ||||
| from numpy.lib.user_array import container | ||||
|  | ||||
| N = 10_000 | ||||
| W = H = int(N**0.5) | ||||
|  | ||||
| a: np.ndarray[tuple[int, int], np.dtype[np.int32]] | ||||
| ua: container[tuple[int, int], np.dtype[np.int32]] | ||||
|  | ||||
| a = np.arange(N, dtype=np.int32).reshape(W, H) | ||||
| ua = container(a) | ||||
|  | ||||
| ua_small: container[tuple[int, int], np.dtype[np.int32]] = ua[:3, :5] | ||||
| ua_small[0, 0] = 10 | ||||
|  | ||||
| ua_bool: container[tuple[int, int], np.dtype[np.bool]] = ua_small > 1 | ||||
|  | ||||
| # shape: tuple[int, int] = np.shape(ua) | ||||
| @ -0,0 +1,19 @@ | ||||
| from __future__ import annotations | ||||
|  | ||||
| from io import StringIO | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.lib.array_utils as array_utils | ||||
|  | ||||
| FILE = StringIO() | ||||
| AR = np.arange(10, dtype=np.float64) | ||||
|  | ||||
|  | ||||
| def func(a: int) -> bool: | ||||
|     return True | ||||
|  | ||||
|  | ||||
| array_utils.byte_bounds(AR) | ||||
| array_utils.byte_bounds(np.float64()) | ||||
|  | ||||
| np.info(1, output=FILE) | ||||
| @ -0,0 +1,18 @@ | ||||
| from numpy.lib import NumpyVersion | ||||
|  | ||||
| version = NumpyVersion("1.8.0") | ||||
|  | ||||
| version.vstring | ||||
| version.version | ||||
| version.major | ||||
| version.minor | ||||
| version.bugfix | ||||
| version.pre_release | ||||
| version.is_devversion | ||||
|  | ||||
| version == version | ||||
| version != version | ||||
| version < "1.8.0" | ||||
| version <= version | ||||
| version > version | ||||
| version >= "1.8.0" | ||||
| @ -0,0 +1,51 @@ | ||||
| from __future__ import annotations | ||||
|  | ||||
| from typing import Any, TYPE_CHECKING | ||||
| from functools import partial | ||||
|  | ||||
| import pytest | ||||
| import numpy as np | ||||
|  | ||||
| if TYPE_CHECKING: | ||||
|     from collections.abc import Callable | ||||
|  | ||||
| AR = np.array(0) | ||||
| AR.setflags(write=False) | ||||
|  | ||||
| KACF = frozenset({None, "K", "A", "C", "F"}) | ||||
| ACF = frozenset({None, "A", "C", "F"}) | ||||
| CF = frozenset({None, "C", "F"}) | ||||
|  | ||||
| order_list: list[tuple[frozenset[str | None], Callable[..., Any]]] = [ | ||||
|     (KACF, AR.tobytes), | ||||
|     (KACF, partial(AR.astype, int)), | ||||
|     (KACF, AR.copy), | ||||
|     (ACF, partial(AR.reshape, 1)), | ||||
|     (KACF, AR.flatten), | ||||
|     (KACF, AR.ravel), | ||||
|     (KACF, partial(np.array, 1)), | ||||
|     # NOTE: __call__ is needed due to mypy bugs (#17620, #17631) | ||||
|     (KACF, partial(np.ndarray.__call__, 1)), | ||||
|     (CF, partial(np.zeros.__call__, 1)), | ||||
|     (CF, partial(np.ones.__call__, 1)), | ||||
|     (CF, partial(np.empty.__call__, 1)), | ||||
|     (CF, partial(np.full, 1, 1)), | ||||
|     (KACF, partial(np.zeros_like, AR)), | ||||
|     (KACF, partial(np.ones_like, AR)), | ||||
|     (KACF, partial(np.empty_like, AR)), | ||||
|     (KACF, partial(np.full_like, AR, 1)), | ||||
|     (KACF, partial(np.add.__call__, 1, 1)),  # i.e. np.ufunc.__call__ | ||||
|     (ACF, partial(np.reshape, AR, 1)), | ||||
|     (KACF, partial(np.ravel, AR)), | ||||
|     (KACF, partial(np.asarray, 1)), | ||||
|     (KACF, partial(np.asanyarray, 1)), | ||||
| ] | ||||
|  | ||||
| for order_set, func in order_list: | ||||
|     for order in order_set: | ||||
|         func(order=order) | ||||
|  | ||||
|     invalid_orders = KACF - order_set | ||||
|     for order in invalid_orders: | ||||
|         with pytest.raises(ValueError): | ||||
|             func(order=order) | ||||
							
								
								
									
										174
									
								
								lib/python3.11/site-packages/numpy/typing/tests/data/pass/ma.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										174
									
								
								lib/python3.11/site-packages/numpy/typing/tests/data/pass/ma.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,174 @@ | ||||
| from typing import Any, TypeAlias, TypeVar, cast | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| from numpy._typing import _Shape | ||||
|  | ||||
| _ScalarT = TypeVar("_ScalarT", bound=np.generic) | ||||
| MaskedArray: TypeAlias = np.ma.MaskedArray[_Shape, np.dtype[_ScalarT]] | ||||
|  | ||||
| MAR_b: MaskedArray[np.bool] = np.ma.MaskedArray([True]) | ||||
| MAR_u: MaskedArray[np.uint32] = np.ma.MaskedArray([1], dtype=np.uint32) | ||||
| MAR_i: MaskedArray[np.int64] = np.ma.MaskedArray([1]) | ||||
| MAR_f: MaskedArray[np.float64] = np.ma.MaskedArray([1.0]) | ||||
| MAR_c: MaskedArray[np.complex128] = np.ma.MaskedArray([1j]) | ||||
| MAR_td64: MaskedArray[np.timedelta64] = np.ma.MaskedArray([np.timedelta64(1, "D")]) | ||||
| MAR_M_dt64: MaskedArray[np.datetime64] = np.ma.MaskedArray([np.datetime64(1, "D")]) | ||||
| MAR_S: MaskedArray[np.bytes_] = np.ma.MaskedArray([b'foo'], dtype=np.bytes_) | ||||
| MAR_U: MaskedArray[np.str_] = np.ma.MaskedArray(['foo'], dtype=np.str_) | ||||
| MAR_T = cast(np.ma.MaskedArray[Any, np.dtypes.StringDType], | ||||
|              np.ma.MaskedArray(["a"], dtype="T")) | ||||
|  | ||||
| AR_b: npt.NDArray[np.bool] = np.array([True, False, True]) | ||||
|  | ||||
| AR_LIKE_b = [True] | ||||
| AR_LIKE_u = [np.uint32(1)] | ||||
| AR_LIKE_i = [1] | ||||
| AR_LIKE_f = [1.0] | ||||
| AR_LIKE_c = [1j] | ||||
| AR_LIKE_m = [np.timedelta64(1, "D")] | ||||
| AR_LIKE_M = [np.datetime64(1, "D")] | ||||
|  | ||||
| MAR_f.mask = AR_b | ||||
| MAR_f.mask = np.False_ | ||||
|  | ||||
| # Inplace addition | ||||
|  | ||||
| MAR_b += AR_LIKE_b | ||||
|  | ||||
| MAR_u += AR_LIKE_b | ||||
| MAR_u += AR_LIKE_u | ||||
|  | ||||
| MAR_i += AR_LIKE_b | ||||
| MAR_i += 2 | ||||
| MAR_i += AR_LIKE_i | ||||
|  | ||||
| MAR_f += AR_LIKE_b | ||||
| MAR_f += 2 | ||||
| MAR_f += AR_LIKE_u | ||||
| MAR_f += AR_LIKE_i | ||||
| MAR_f += AR_LIKE_f | ||||
|  | ||||
| MAR_c += AR_LIKE_b | ||||
| MAR_c += AR_LIKE_u | ||||
| MAR_c += AR_LIKE_i | ||||
| MAR_c += AR_LIKE_f | ||||
| MAR_c += AR_LIKE_c | ||||
|  | ||||
| MAR_td64 += AR_LIKE_b | ||||
| MAR_td64 += AR_LIKE_u | ||||
| MAR_td64 += AR_LIKE_i | ||||
| MAR_td64 += AR_LIKE_m | ||||
| MAR_M_dt64 += AR_LIKE_b | ||||
| MAR_M_dt64 += AR_LIKE_u | ||||
| MAR_M_dt64 += AR_LIKE_i | ||||
| MAR_M_dt64 += AR_LIKE_m | ||||
|  | ||||
| MAR_S += b'snakes' | ||||
| MAR_U += 'snakes' | ||||
| MAR_T += 'snakes' | ||||
|  | ||||
| # Inplace subtraction | ||||
|  | ||||
| MAR_u -= AR_LIKE_b | ||||
| MAR_u -= AR_LIKE_u | ||||
|  | ||||
| MAR_i -= AR_LIKE_b | ||||
| MAR_i -= AR_LIKE_i | ||||
|  | ||||
| MAR_f -= AR_LIKE_b | ||||
| MAR_f -= AR_LIKE_u | ||||
| MAR_f -= AR_LIKE_i | ||||
| MAR_f -= AR_LIKE_f | ||||
|  | ||||
| MAR_c -= AR_LIKE_b | ||||
| MAR_c -= AR_LIKE_u | ||||
| MAR_c -= AR_LIKE_i | ||||
| MAR_c -= AR_LIKE_f | ||||
| MAR_c -= AR_LIKE_c | ||||
|  | ||||
| MAR_td64 -= AR_LIKE_b | ||||
| MAR_td64 -= AR_LIKE_u | ||||
| MAR_td64 -= AR_LIKE_i | ||||
| MAR_td64 -= AR_LIKE_m | ||||
| MAR_M_dt64 -= AR_LIKE_b | ||||
| MAR_M_dt64 -= AR_LIKE_u | ||||
| MAR_M_dt64 -= AR_LIKE_i | ||||
| MAR_M_dt64 -= AR_LIKE_m | ||||
|  | ||||
| # Inplace floor division | ||||
|  | ||||
| MAR_f //= AR_LIKE_b | ||||
| MAR_f //= 2 | ||||
| MAR_f //= AR_LIKE_u | ||||
| MAR_f //= AR_LIKE_i | ||||
| MAR_f //= AR_LIKE_f | ||||
|  | ||||
| MAR_td64 //= AR_LIKE_i | ||||
|  | ||||
| # Inplace true division | ||||
|  | ||||
| MAR_f /= AR_LIKE_b | ||||
| MAR_f /= 2 | ||||
| MAR_f /= AR_LIKE_u | ||||
| MAR_f /= AR_LIKE_i | ||||
| MAR_f /= AR_LIKE_f | ||||
|  | ||||
| MAR_c /= AR_LIKE_b | ||||
| MAR_c /= AR_LIKE_u | ||||
| MAR_c /= AR_LIKE_i | ||||
| MAR_c /= AR_LIKE_f | ||||
| MAR_c /= AR_LIKE_c | ||||
|  | ||||
| MAR_td64 /= AR_LIKE_i | ||||
|  | ||||
| # Inplace multiplication | ||||
|  | ||||
| MAR_b *= AR_LIKE_b | ||||
|  | ||||
| MAR_u *= AR_LIKE_b | ||||
| MAR_u *= AR_LIKE_u | ||||
|  | ||||
| MAR_i *= AR_LIKE_b | ||||
| MAR_i *= 2 | ||||
| MAR_i *= AR_LIKE_i | ||||
|  | ||||
| MAR_f *= AR_LIKE_b | ||||
| MAR_f *= 2 | ||||
| MAR_f *= AR_LIKE_u | ||||
| MAR_f *= AR_LIKE_i | ||||
| MAR_f *= AR_LIKE_f | ||||
|  | ||||
| MAR_c *= AR_LIKE_b | ||||
| MAR_c *= AR_LIKE_u | ||||
| MAR_c *= AR_LIKE_i | ||||
| MAR_c *= AR_LIKE_f | ||||
| MAR_c *= AR_LIKE_c | ||||
|  | ||||
| MAR_td64 *= AR_LIKE_b | ||||
| MAR_td64 *= AR_LIKE_u | ||||
| MAR_td64 *= AR_LIKE_i | ||||
| MAR_td64 *= AR_LIKE_f | ||||
|  | ||||
| MAR_S *= 2 | ||||
| MAR_U *= 2 | ||||
| MAR_T *= 2 | ||||
|  | ||||
| # Inplace power | ||||
|  | ||||
| MAR_u **= AR_LIKE_b | ||||
| MAR_u **= AR_LIKE_u | ||||
|  | ||||
| MAR_i **= AR_LIKE_b | ||||
| MAR_i **= AR_LIKE_i | ||||
|  | ||||
| MAR_f **= AR_LIKE_b | ||||
| MAR_f **= AR_LIKE_u | ||||
| MAR_f **= AR_LIKE_i | ||||
| MAR_f **= AR_LIKE_f | ||||
|  | ||||
| MAR_c **= AR_LIKE_b | ||||
| MAR_c **= AR_LIKE_u | ||||
| MAR_c **= AR_LIKE_i | ||||
| MAR_c **= AR_LIKE_f | ||||
| MAR_c **= AR_LIKE_c | ||||
							
								
								
									
										149
									
								
								lib/python3.11/site-packages/numpy/typing/tests/data/pass/mod.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										149
									
								
								lib/python3.11/site-packages/numpy/typing/tests/data/pass/mod.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,149 @@ | ||||
| import numpy as np | ||||
|  | ||||
| f8 = np.float64(1) | ||||
| i8 = np.int64(1) | ||||
| u8 = np.uint64(1) | ||||
|  | ||||
| f4 = np.float32(1) | ||||
| i4 = np.int32(1) | ||||
| u4 = np.uint32(1) | ||||
|  | ||||
| td = np.timedelta64(1, "D") | ||||
| b_ = np.bool(1) | ||||
|  | ||||
| b = bool(1) | ||||
| f = float(1) | ||||
| i = int(1) | ||||
|  | ||||
| AR = np.array([1], dtype=np.bool) | ||||
| AR.setflags(write=False) | ||||
|  | ||||
| AR2 = np.array([1], dtype=np.timedelta64) | ||||
| AR2.setflags(write=False) | ||||
|  | ||||
| # Time structures | ||||
|  | ||||
| td % td | ||||
| td % AR2 | ||||
| AR2 % td | ||||
|  | ||||
| divmod(td, td) | ||||
| divmod(td, AR2) | ||||
| divmod(AR2, td) | ||||
|  | ||||
| # Bool | ||||
|  | ||||
| b_ % b | ||||
| b_ % i | ||||
| b_ % f | ||||
| b_ % b_ | ||||
| b_ % i8 | ||||
| b_ % u8 | ||||
| b_ % f8 | ||||
| b_ % AR | ||||
|  | ||||
| divmod(b_, b) | ||||
| divmod(b_, i) | ||||
| divmod(b_, f) | ||||
| divmod(b_, b_) | ||||
| divmod(b_, i8) | ||||
| divmod(b_, u8) | ||||
| divmod(b_, f8) | ||||
| divmod(b_, AR) | ||||
|  | ||||
| b % b_ | ||||
| i % b_ | ||||
| f % b_ | ||||
| b_ % b_ | ||||
| i8 % b_ | ||||
| u8 % b_ | ||||
| f8 % b_ | ||||
| AR % b_ | ||||
|  | ||||
| divmod(b, b_) | ||||
| divmod(i, b_) | ||||
| divmod(f, b_) | ||||
| divmod(b_, b_) | ||||
| divmod(i8, b_) | ||||
| divmod(u8, b_) | ||||
| divmod(f8, b_) | ||||
| divmod(AR, b_) | ||||
|  | ||||
| # int | ||||
|  | ||||
| i8 % b | ||||
| i8 % i | ||||
| i8 % f | ||||
| i8 % i8 | ||||
| i8 % f8 | ||||
| i4 % i8 | ||||
| i4 % f8 | ||||
| i4 % i4 | ||||
| i4 % f4 | ||||
| i8 % AR | ||||
|  | ||||
| divmod(i8, b) | ||||
| divmod(i8, i) | ||||
| divmod(i8, f) | ||||
| divmod(i8, i8) | ||||
| divmod(i8, f8) | ||||
| divmod(i8, i4) | ||||
| divmod(i8, f4) | ||||
| divmod(i4, i4) | ||||
| divmod(i4, f4) | ||||
| divmod(i8, AR) | ||||
|  | ||||
| b % i8 | ||||
| i % i8 | ||||
| f % i8 | ||||
| i8 % i8 | ||||
| f8 % i8 | ||||
| i8 % i4 | ||||
| f8 % i4 | ||||
| i4 % i4 | ||||
| f4 % i4 | ||||
| AR % i8 | ||||
|  | ||||
| divmod(b, i8) | ||||
| divmod(i, i8) | ||||
| divmod(f, i8) | ||||
| divmod(i8, i8) | ||||
| divmod(f8, i8) | ||||
| divmod(i4, i8) | ||||
| divmod(f4, i8) | ||||
| divmod(i4, i4) | ||||
| divmod(f4, i4) | ||||
| divmod(AR, i8) | ||||
|  | ||||
| # float | ||||
|  | ||||
| f8 % b | ||||
| f8 % i | ||||
| f8 % f | ||||
| i8 % f4 | ||||
| f4 % f4 | ||||
| f8 % AR | ||||
|  | ||||
| divmod(f8, b) | ||||
| divmod(f8, i) | ||||
| divmod(f8, f) | ||||
| divmod(f8, f8) | ||||
| divmod(f8, f4) | ||||
| divmod(f4, f4) | ||||
| divmod(f8, AR) | ||||
|  | ||||
| b % f8 | ||||
| i % f8 | ||||
| f % f8 | ||||
| f8 % f8 | ||||
| f8 % f8 | ||||
| f4 % f4 | ||||
| AR % f8 | ||||
|  | ||||
| divmod(b, f8) | ||||
| divmod(i, f8) | ||||
| divmod(f, f8) | ||||
| divmod(f8, f8) | ||||
| divmod(f4, f8) | ||||
| divmod(f4, f4) | ||||
| divmod(AR, f8) | ||||
| @ -0,0 +1,45 @@ | ||||
| import numpy as np | ||||
| from numpy import f2py | ||||
|  | ||||
| np.char | ||||
| np.ctypeslib | ||||
| np.emath | ||||
| np.fft | ||||
| np.lib | ||||
| np.linalg | ||||
| np.ma | ||||
| np.matrixlib | ||||
| np.polynomial | ||||
| np.random | ||||
| np.rec | ||||
| np.strings | ||||
| np.testing | ||||
| np.version | ||||
|  | ||||
| np.lib.format | ||||
| np.lib.mixins | ||||
| np.lib.scimath | ||||
| np.lib.stride_tricks | ||||
| np.lib.array_utils | ||||
| np.ma.extras | ||||
| np.polynomial.chebyshev | ||||
| np.polynomial.hermite | ||||
| np.polynomial.hermite_e | ||||
| np.polynomial.laguerre | ||||
| np.polynomial.legendre | ||||
| np.polynomial.polynomial | ||||
|  | ||||
| np.__path__ | ||||
| np.__version__ | ||||
|  | ||||
| np.__all__ | ||||
| np.char.__all__ | ||||
| np.ctypeslib.__all__ | ||||
| np.emath.__all__ | ||||
| np.lib.__all__ | ||||
| np.ma.__all__ | ||||
| np.random.__all__ | ||||
| np.rec.__all__ | ||||
| np.strings.__all__ | ||||
| np.testing.__all__ | ||||
| f2py.__all__ | ||||
| @ -0,0 +1,76 @@ | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_f8: npt.NDArray[np.float64] = np.array([1.0]) | ||||
| AR_i4 = np.array([1], dtype=np.int32) | ||||
| AR_u1 = np.array([1], dtype=np.uint8) | ||||
|  | ||||
| AR_LIKE_f = [1.5] | ||||
| AR_LIKE_i = [1] | ||||
|  | ||||
| b_f8 = np.broadcast(AR_f8) | ||||
| b_i4_f8_f8 = np.broadcast(AR_i4, AR_f8, AR_f8) | ||||
|  | ||||
| next(b_f8) | ||||
| b_f8.reset() | ||||
| b_f8.index | ||||
| b_f8.iters | ||||
| b_f8.nd | ||||
| b_f8.ndim | ||||
| b_f8.numiter | ||||
| b_f8.shape | ||||
| b_f8.size | ||||
|  | ||||
| next(b_i4_f8_f8) | ||||
| b_i4_f8_f8.reset() | ||||
| b_i4_f8_f8.ndim | ||||
| b_i4_f8_f8.index | ||||
| b_i4_f8_f8.iters | ||||
| b_i4_f8_f8.nd | ||||
| b_i4_f8_f8.numiter | ||||
| b_i4_f8_f8.shape | ||||
| b_i4_f8_f8.size | ||||
|  | ||||
| np.inner(AR_f8, AR_i4) | ||||
|  | ||||
| np.where([True, True, False]) | ||||
| np.where([True, True, False], 1, 0) | ||||
|  | ||||
| np.lexsort([0, 1, 2]) | ||||
|  | ||||
| np.can_cast(np.dtype("i8"), int) | ||||
| np.can_cast(AR_f8, "f8") | ||||
| np.can_cast(AR_f8, np.complex128, casting="unsafe") | ||||
|  | ||||
| np.min_scalar_type([1]) | ||||
| np.min_scalar_type(AR_f8) | ||||
|  | ||||
| np.result_type(int, AR_i4) | ||||
| np.result_type(AR_f8, AR_u1) | ||||
| np.result_type(AR_f8, np.complex128) | ||||
|  | ||||
| np.dot(AR_LIKE_f, AR_i4) | ||||
| np.dot(AR_u1, 1) | ||||
| np.dot(1.5j, 1) | ||||
| np.dot(AR_u1, 1, out=AR_f8) | ||||
|  | ||||
| np.vdot(AR_LIKE_f, AR_i4) | ||||
| np.vdot(AR_u1, 1) | ||||
| np.vdot(1.5j, 1) | ||||
|  | ||||
| np.bincount(AR_i4) | ||||
|  | ||||
| np.copyto(AR_f8, [1.6]) | ||||
|  | ||||
| np.putmask(AR_f8, [True], 1.5) | ||||
|  | ||||
| np.packbits(AR_i4) | ||||
| np.packbits(AR_u1) | ||||
|  | ||||
| np.unpackbits(AR_u1) | ||||
|  | ||||
| np.shares_memory(1, 2) | ||||
| np.shares_memory(AR_f8, AR_f8, max_work=1) | ||||
|  | ||||
| np.may_share_memory(1, 2) | ||||
| np.may_share_memory(AR_f8, AR_f8, max_work=1) | ||||
| @ -0,0 +1,87 @@ | ||||
| import os | ||||
| import tempfile | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
| nd = np.array([[1, 2], [3, 4]]) | ||||
| scalar_array = np.array(1) | ||||
|  | ||||
| # item | ||||
| scalar_array.item() | ||||
| nd.item(1) | ||||
| nd.item(0, 1) | ||||
| nd.item((0, 1)) | ||||
|  | ||||
| # tobytes | ||||
| nd.tobytes() | ||||
| nd.tobytes("C") | ||||
| nd.tobytes(None) | ||||
|  | ||||
| # tofile | ||||
| if os.name != "nt": | ||||
|     with tempfile.NamedTemporaryFile(suffix=".txt") as tmp: | ||||
|         nd.tofile(tmp.name) | ||||
|         nd.tofile(tmp.name, "") | ||||
|         nd.tofile(tmp.name, sep="") | ||||
|  | ||||
|         nd.tofile(tmp.name, "", "%s") | ||||
|         nd.tofile(tmp.name, format="%s") | ||||
|  | ||||
|         nd.tofile(tmp) | ||||
|  | ||||
| # dump is pretty simple | ||||
| # dumps is pretty simple | ||||
|  | ||||
| # astype | ||||
| nd.astype("float") | ||||
| nd.astype(float) | ||||
|  | ||||
| nd.astype(float, "K") | ||||
| nd.astype(float, order="K") | ||||
|  | ||||
| nd.astype(float, "K", "unsafe") | ||||
| nd.astype(float, casting="unsafe") | ||||
|  | ||||
| nd.astype(float, "K", "unsafe", True) | ||||
| nd.astype(float, subok=True) | ||||
|  | ||||
| nd.astype(float, "K", "unsafe", True, True) | ||||
| nd.astype(float, copy=True) | ||||
|  | ||||
| # byteswap | ||||
| nd.byteswap() | ||||
| nd.byteswap(True) | ||||
|  | ||||
| # copy | ||||
| nd.copy() | ||||
| nd.copy("C") | ||||
|  | ||||
| # view | ||||
| nd.view() | ||||
| nd.view(np.int64) | ||||
| nd.view(dtype=np.int64) | ||||
| nd.view(np.int64, np.matrix) | ||||
| nd.view(type=np.matrix) | ||||
|  | ||||
| # getfield | ||||
| complex_array = np.array([[1 + 1j, 0], [0, 1 - 1j]], dtype=np.complex128) | ||||
|  | ||||
| complex_array.getfield("float") | ||||
| complex_array.getfield(float) | ||||
|  | ||||
| complex_array.getfield("float", 8) | ||||
| complex_array.getfield(float, offset=8) | ||||
|  | ||||
| # setflags | ||||
| nd.setflags() | ||||
|  | ||||
| nd.setflags(True) | ||||
| nd.setflags(write=True) | ||||
|  | ||||
| nd.setflags(True, True) | ||||
| nd.setflags(write=True, align=True) | ||||
|  | ||||
| nd.setflags(True, True, False) | ||||
| nd.setflags(write=True, align=True, uic=False) | ||||
|  | ||||
| # fill is pretty simple | ||||
| @ -0,0 +1,198 @@ | ||||
| """ | ||||
| Tests for miscellaneous (non-magic) ``np.ndarray``/``np.generic`` methods. | ||||
|  | ||||
| More extensive tests are performed for the methods' | ||||
| function-based counterpart in `../from_numeric.py`. | ||||
|  | ||||
| """ | ||||
|  | ||||
| from __future__ import annotations | ||||
|  | ||||
| import operator | ||||
| from typing import cast, Any | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| class SubClass(npt.NDArray[np.float64]): ... | ||||
| class IntSubClass(npt.NDArray[np.intp]): ... | ||||
|  | ||||
| i4 = np.int32(1) | ||||
| A: np.ndarray[Any, np.dtype[np.int32]] = np.array([[1]], dtype=np.int32) | ||||
| B0 = np.empty((), dtype=np.int32).view(SubClass) | ||||
| B1 = np.empty((1,), dtype=np.int32).view(SubClass) | ||||
| B2 = np.empty((1, 1), dtype=np.int32).view(SubClass) | ||||
| B_int0: IntSubClass = np.empty((), dtype=np.intp).view(IntSubClass) | ||||
| C: np.ndarray[Any, np.dtype[np.int32]] = np.array([0, 1, 2], dtype=np.int32) | ||||
| D = np.ones(3).view(SubClass) | ||||
|  | ||||
| ctypes_obj = A.ctypes | ||||
|  | ||||
| i4.all() | ||||
| A.all() | ||||
| A.all(axis=0) | ||||
| A.all(keepdims=True) | ||||
| A.all(out=B0) | ||||
|  | ||||
| i4.any() | ||||
| A.any() | ||||
| A.any(axis=0) | ||||
| A.any(keepdims=True) | ||||
| A.any(out=B0) | ||||
|  | ||||
| i4.argmax() | ||||
| A.argmax() | ||||
| A.argmax(axis=0) | ||||
| A.argmax(out=B_int0) | ||||
|  | ||||
| i4.argmin() | ||||
| A.argmin() | ||||
| A.argmin(axis=0) | ||||
| A.argmin(out=B_int0) | ||||
|  | ||||
| i4.argsort() | ||||
| A.argsort() | ||||
|  | ||||
| i4.choose([()]) | ||||
| _choices = np.array([[0, 1, 2], [3, 4, 5], [6, 7, 8]], dtype=np.int32) | ||||
| C.choose(_choices) | ||||
| C.choose(_choices, out=D) | ||||
|  | ||||
| i4.clip(1) | ||||
| A.clip(1) | ||||
| A.clip(None, 1) | ||||
| A.clip(1, out=B2) | ||||
| A.clip(None, 1, out=B2) | ||||
|  | ||||
| i4.compress([1]) | ||||
| A.compress([1]) | ||||
| A.compress([1], out=B1) | ||||
|  | ||||
| i4.conj() | ||||
| A.conj() | ||||
| B0.conj() | ||||
|  | ||||
| i4.conjugate() | ||||
| A.conjugate() | ||||
| B0.conjugate() | ||||
|  | ||||
| i4.cumprod() | ||||
| A.cumprod() | ||||
| A.cumprod(out=B1) | ||||
|  | ||||
| i4.cumsum() | ||||
| A.cumsum() | ||||
| A.cumsum(out=B1) | ||||
|  | ||||
| i4.max() | ||||
| A.max() | ||||
| A.max(axis=0) | ||||
| A.max(keepdims=True) | ||||
| A.max(out=B0) | ||||
|  | ||||
| i4.mean() | ||||
| A.mean() | ||||
| A.mean(axis=0) | ||||
| A.mean(keepdims=True) | ||||
| A.mean(out=B0) | ||||
|  | ||||
| i4.min() | ||||
| A.min() | ||||
| A.min(axis=0) | ||||
| A.min(keepdims=True) | ||||
| A.min(out=B0) | ||||
|  | ||||
| i4.prod() | ||||
| A.prod() | ||||
| A.prod(axis=0) | ||||
| A.prod(keepdims=True) | ||||
| A.prod(out=B0) | ||||
|  | ||||
| i4.round() | ||||
| A.round() | ||||
| A.round(out=B2) | ||||
|  | ||||
| i4.repeat(1) | ||||
| A.repeat(1) | ||||
| B0.repeat(1) | ||||
|  | ||||
| i4.std() | ||||
| A.std() | ||||
| A.std(axis=0) | ||||
| A.std(keepdims=True) | ||||
| A.std(out=B0.astype(np.float64)) | ||||
|  | ||||
| i4.sum() | ||||
| A.sum() | ||||
| A.sum(axis=0) | ||||
| A.sum(keepdims=True) | ||||
| A.sum(out=B0) | ||||
|  | ||||
| i4.take(0) | ||||
| A.take(0) | ||||
| A.take([0]) | ||||
| A.take(0, out=B0) | ||||
| A.take([0], out=B1) | ||||
|  | ||||
| i4.var() | ||||
| A.var() | ||||
| A.var(axis=0) | ||||
| A.var(keepdims=True) | ||||
| A.var(out=B0) | ||||
|  | ||||
| A.argpartition([0]) | ||||
|  | ||||
| A.diagonal() | ||||
|  | ||||
| A.dot(1) | ||||
| A.dot(1, out=B2) | ||||
|  | ||||
| A.nonzero() | ||||
|  | ||||
| C.searchsorted(1) | ||||
|  | ||||
| A.trace() | ||||
| A.trace(out=B0) | ||||
|  | ||||
| void = cast(np.void, np.array(1, dtype=[("f", np.float64)]).take(0)) | ||||
| void.setfield(10, np.float64) | ||||
|  | ||||
| A.item(0) | ||||
| C.item(0) | ||||
|  | ||||
| A.ravel() | ||||
| C.ravel() | ||||
|  | ||||
| A.flatten() | ||||
| C.flatten() | ||||
|  | ||||
| A.reshape(1) | ||||
| C.reshape(3) | ||||
|  | ||||
| int(np.array(1.0, dtype=np.float64)) | ||||
| int(np.array("1", dtype=np.str_)) | ||||
|  | ||||
| float(np.array(1.0, dtype=np.float64)) | ||||
| float(np.array("1", dtype=np.str_)) | ||||
|  | ||||
| complex(np.array(1.0, dtype=np.float64)) | ||||
|  | ||||
| operator.index(np.array(1, dtype=np.int64)) | ||||
|  | ||||
| # this fails on numpy 2.2.1 | ||||
| # https://github.com/scipy/scipy/blob/a755ee77ec47a64849abe42c349936475a6c2f24/scipy/io/arff/tests/test_arffread.py#L41-L44 | ||||
| A_float = np.array([[1, 5], [2, 4], [np.nan, np.nan]]) | ||||
| A_void: npt.NDArray[np.void] = np.empty(3, [("yop", float), ("yap", float)]) | ||||
| A_void["yop"] = A_float[:, 0] | ||||
| A_void["yap"] = A_float[:, 1] | ||||
|  | ||||
| # deprecated | ||||
|  | ||||
| with np.testing.assert_warns(DeprecationWarning): | ||||
|     ctypes_obj.get_data()  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated] | ||||
| with np.testing.assert_warns(DeprecationWarning): | ||||
|     ctypes_obj.get_shape()  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated] | ||||
| with np.testing.assert_warns(DeprecationWarning): | ||||
|     ctypes_obj.get_strides()  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated] | ||||
| with np.testing.assert_warns(DeprecationWarning): | ||||
|     ctypes_obj.get_as_parameter()  # type: ignore[deprecated]  # pyright: ignore[reportDeprecated] | ||||
| @ -0,0 +1,47 @@ | ||||
| import numpy as np | ||||
|  | ||||
| nd1 = np.array([[1, 2], [3, 4]]) | ||||
|  | ||||
| # reshape | ||||
| nd1.reshape(4) | ||||
| nd1.reshape(2, 2) | ||||
| nd1.reshape((2, 2)) | ||||
|  | ||||
| nd1.reshape((2, 2), order="C") | ||||
| nd1.reshape(4, order="C") | ||||
|  | ||||
| # resize | ||||
| nd1.resize() | ||||
| nd1.resize(4) | ||||
| nd1.resize(2, 2) | ||||
| nd1.resize((2, 2)) | ||||
|  | ||||
| nd1.resize((2, 2), refcheck=True) | ||||
| nd1.resize(4, refcheck=True) | ||||
|  | ||||
| nd2 = np.array([[1, 2], [3, 4]]) | ||||
|  | ||||
| # transpose | ||||
| nd2.transpose() | ||||
| nd2.transpose(1, 0) | ||||
| nd2.transpose((1, 0)) | ||||
|  | ||||
| # swapaxes | ||||
| nd2.swapaxes(0, 1) | ||||
|  | ||||
| # flatten | ||||
| nd2.flatten() | ||||
| nd2.flatten("C") | ||||
|  | ||||
| # ravel | ||||
| nd2.ravel() | ||||
| nd2.ravel("C") | ||||
|  | ||||
| # squeeze | ||||
| nd2.squeeze() | ||||
|  | ||||
| nd3 = np.array([[1, 2]]) | ||||
| nd3.squeeze(0) | ||||
|  | ||||
| nd4 = np.array([[[1, 2]]]) | ||||
| nd4.squeeze((0, 1)) | ||||
| @ -0,0 +1,4 @@ | ||||
| import numpy as np | ||||
|  | ||||
| arr = np.array([1]) | ||||
| np.nditer([arr, None]) | ||||
| @ -0,0 +1,95 @@ | ||||
| """ | ||||
| Tests for :mod:`numpy._core.numeric`. | ||||
|  | ||||
| Does not include tests which fall under ``array_constructors``. | ||||
|  | ||||
| """ | ||||
|  | ||||
| from __future__ import annotations | ||||
| from typing import cast | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| class SubClass(npt.NDArray[np.float64]): ... | ||||
|  | ||||
|  | ||||
| i8 = np.int64(1) | ||||
|  | ||||
| A = cast( | ||||
|     np.ndarray[tuple[int, int, int], np.dtype[np.intp]], | ||||
|     np.arange(27).reshape(3, 3, 3), | ||||
| ) | ||||
| B: list[list[list[int]]] = A.tolist() | ||||
| C = np.empty((27, 27)).view(SubClass) | ||||
|  | ||||
| np.count_nonzero(i8) | ||||
| np.count_nonzero(A) | ||||
| np.count_nonzero(B) | ||||
| np.count_nonzero(A, keepdims=True) | ||||
| np.count_nonzero(A, axis=0) | ||||
|  | ||||
| np.isfortran(i8) | ||||
| np.isfortran(A) | ||||
|  | ||||
| np.argwhere(i8) | ||||
| np.argwhere(A) | ||||
|  | ||||
| np.flatnonzero(i8) | ||||
| np.flatnonzero(A) | ||||
|  | ||||
| np.correlate(B[0][0], A.ravel(), mode="valid") | ||||
| np.correlate(A.ravel(), A.ravel(), mode="same") | ||||
|  | ||||
| np.convolve(B[0][0], A.ravel(), mode="valid") | ||||
| np.convolve(A.ravel(), A.ravel(), mode="same") | ||||
|  | ||||
| np.outer(i8, A) | ||||
| np.outer(B, A) | ||||
| np.outer(A, A) | ||||
| np.outer(A, A, out=C) | ||||
|  | ||||
| np.tensordot(B, A) | ||||
| np.tensordot(A, A) | ||||
| np.tensordot(A, A, axes=0) | ||||
| np.tensordot(A, A, axes=(0, 1)) | ||||
|  | ||||
| np.isscalar(i8) | ||||
| np.isscalar(A) | ||||
| np.isscalar(B) | ||||
|  | ||||
| np.roll(A, 1) | ||||
| np.roll(A, (1, 2)) | ||||
| np.roll(B, 1) | ||||
|  | ||||
| np.rollaxis(A, 0, 1) | ||||
|  | ||||
| np.moveaxis(A, 0, 1) | ||||
| np.moveaxis(A, (0, 1), (1, 2)) | ||||
|  | ||||
| np.cross(B, A) | ||||
| np.cross(A, A) | ||||
|  | ||||
| np.indices([0, 1, 2]) | ||||
| np.indices([0, 1, 2], sparse=False) | ||||
| np.indices([0, 1, 2], sparse=True) | ||||
|  | ||||
| np.binary_repr(1) | ||||
|  | ||||
| np.base_repr(1) | ||||
|  | ||||
| np.allclose(i8, A) | ||||
| np.allclose(B, A) | ||||
| np.allclose(A, A) | ||||
|  | ||||
| np.isclose(i8, A) | ||||
| np.isclose(B, A) | ||||
| np.isclose(A, A) | ||||
|  | ||||
| np.array_equal(i8, A) | ||||
| np.array_equal(B, A) | ||||
| np.array_equal(A, A) | ||||
|  | ||||
| np.array_equiv(i8, A) | ||||
| np.array_equiv(B, A) | ||||
| np.array_equiv(A, A) | ||||
| @ -0,0 +1,17 @@ | ||||
| import numpy as np | ||||
|  | ||||
| np.isdtype(np.float64, (np.int64, np.float64)) | ||||
| np.isdtype(np.int64, "signed integer") | ||||
|  | ||||
| np.issubdtype("S1", np.bytes_) | ||||
| np.issubdtype(np.float64, np.float32) | ||||
|  | ||||
| np.ScalarType | ||||
| np.ScalarType[0] | ||||
| np.ScalarType[3] | ||||
| np.ScalarType[8] | ||||
| np.ScalarType[10] | ||||
|  | ||||
| np.typecodes["Character"] | ||||
| np.typecodes["Complex"] | ||||
| np.typecodes["All"] | ||||
							
								
								
									
										1497
									
								
								lib/python3.11/site-packages/numpy/typing/tests/data/pass/random.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1497
									
								
								lib/python3.11/site-packages/numpy/typing/tests/data/pass/random.py
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -0,0 +1,161 @@ | ||||
| """These tests are based on the doctests from `numpy/lib/recfunctions.py`.""" | ||||
|  | ||||
| from typing import Any, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| from numpy.lib import recfunctions as rfn | ||||
|  | ||||
|  | ||||
| def test_recursive_fill_fields() -> None: | ||||
|     a: npt.NDArray[np.void] = np.array( | ||||
|         [(1, 10.0), (2, 20.0)], | ||||
|         dtype=[("A", np.int64), ("B", np.float64)], | ||||
|     ) | ||||
|     b = np.zeros((int(3),), dtype=a.dtype) | ||||
|     out = rfn.recursive_fill_fields(a, b) | ||||
|     assert_type(out, np.ndarray[tuple[int], np.dtype[np.void]]) | ||||
|  | ||||
|  | ||||
| def test_get_names() -> None: | ||||
|     names: tuple[str | Any, ...] | ||||
|     names = rfn.get_names(np.empty((1,), dtype=[("A", int)]).dtype) | ||||
|     names = rfn.get_names(np.empty((1,), dtype=[("A", int), ("B", float)]).dtype) | ||||
|  | ||||
|     adtype = np.dtype([("a", int), ("b", [("b_a", int), ("b_b", int)])]) | ||||
|     names = rfn.get_names(adtype) | ||||
|  | ||||
|  | ||||
| def test_get_names_flat() -> None: | ||||
|     names: tuple[str, ...] | ||||
|     names = rfn.get_names_flat(np.empty((1,), dtype=[("A", int)]).dtype) | ||||
|     names = rfn.get_names_flat(np.empty((1,), dtype=[("A", int), ("B", float)]).dtype) | ||||
|  | ||||
|     adtype = np.dtype([("a", int), ("b", [("b_a", int), ("b_b", int)])]) | ||||
|     names = rfn.get_names_flat(adtype) | ||||
|  | ||||
|  | ||||
| def test_flatten_descr() -> None: | ||||
|     ndtype = np.dtype([("a", "<i4"), ("b", [("b_a", "<f8"), ("b_b", "<i4")])]) | ||||
|     assert_type(rfn.flatten_descr(ndtype), tuple[tuple[str, np.dtype]]) | ||||
|  | ||||
|  | ||||
| def test_get_fieldstructure() -> None: | ||||
|     ndtype = np.dtype([ | ||||
|         ("A", int), | ||||
|         ("B", [("B_A", int), ("B_B", [("B_B_A", int), ("B_B_B", int)])]), | ||||
|     ]) | ||||
|     assert_type(rfn.get_fieldstructure(ndtype), dict[str, list[str]]) | ||||
|  | ||||
|  | ||||
| def test_merge_arrays() -> None: | ||||
|     assert_type( | ||||
|         rfn.merge_arrays(( | ||||
|             np.ones((int(2),), np.int_), | ||||
|             np.ones((int(3),), np.float64), | ||||
|         )), | ||||
|         np.recarray[tuple[int], np.dtype[np.void]], | ||||
|     ) | ||||
|  | ||||
|  | ||||
| def test_drop_fields() -> None: | ||||
|     ndtype = [("a", np.int64), ("b", [("b_a", np.double), ("b_b", np.int64)])] | ||||
|     a = np.ones((int(3),), dtype=ndtype) | ||||
|  | ||||
|     assert_type( | ||||
|         rfn.drop_fields(a, "a"), | ||||
|         np.ndarray[tuple[int], np.dtype[np.void]], | ||||
|     ) | ||||
|     assert_type( | ||||
|         rfn.drop_fields(a, "a", asrecarray=True), | ||||
|         np.rec.recarray[tuple[int], np.dtype[np.void]], | ||||
|     ) | ||||
|     assert_type( | ||||
|         rfn.rec_drop_fields(a, "a"), | ||||
|         np.rec.recarray[tuple[int], np.dtype[np.void]], | ||||
|     ) | ||||
|  | ||||
|  | ||||
| def test_rename_fields() -> None: | ||||
|     ndtype = [("a", np.int64), ("b", [("b_a", np.double), ("b_b", np.int64)])] | ||||
|     a = np.ones((int(3),), dtype=ndtype) | ||||
|  | ||||
|     assert_type( | ||||
|         rfn.rename_fields(a, {"a": "A", "b_b": "B_B"}), | ||||
|         np.ndarray[tuple[int], np.dtype[np.void]], | ||||
|     ) | ||||
|  | ||||
|  | ||||
| def test_repack_fields() -> None: | ||||
|     dt: np.dtype[np.void] = np.dtype("u1, <i8, <f8", align=True) | ||||
|  | ||||
|     assert_type(rfn.repack_fields(dt), np.dtype[np.void]) | ||||
|     assert_type(rfn.repack_fields(dt.type(0)), np.void) | ||||
|     assert_type( | ||||
|         rfn.repack_fields(np.ones((int(3),), dtype=dt)), | ||||
|         np.ndarray[tuple[int], np.dtype[np.void]], | ||||
|     ) | ||||
|  | ||||
|  | ||||
| def test_structured_to_unstructured() -> None: | ||||
|     a = np.zeros(4, dtype=[("a", "i4"), ("b", "f4,u2"), ("c", "f4", 2)]) | ||||
|     assert_type(rfn.structured_to_unstructured(a), npt.NDArray[Any]) | ||||
|  | ||||
|  | ||||
| def unstructured_to_structured() -> None: | ||||
|     dt: np.dtype[np.void] = np.dtype([("a", "i4"), ("b", "f4,u2"), ("c", "f4", 2)]) | ||||
|     a = np.arange(20, dtype=np.int32).reshape((4, 5)) | ||||
|     assert_type(rfn.unstructured_to_structured(a, dt), npt.NDArray[np.void]) | ||||
|  | ||||
|  | ||||
| def test_apply_along_fields() -> None: | ||||
|     b = np.ones(4, dtype=[("x", "i4"), ("y", "f4"), ("z", "f8")]) | ||||
|     assert_type( | ||||
|         rfn.apply_along_fields(np.mean, b), | ||||
|         np.ndarray[tuple[int], np.dtype[np.void]], | ||||
|     ) | ||||
|  | ||||
|  | ||||
| def test_assign_fields_by_name() -> None: | ||||
|     b = np.ones(4, dtype=[("x", "i4"), ("y", "f4"), ("z", "f8")]) | ||||
|     assert_type( | ||||
|         rfn.apply_along_fields(np.mean, b), | ||||
|         np.ndarray[tuple[int], np.dtype[np.void]], | ||||
|     ) | ||||
|  | ||||
|  | ||||
| def test_require_fields() -> None: | ||||
|     a = np.ones(4, dtype=[("a", "i4"), ("b", "f8"), ("c", "u1")]) | ||||
|     assert_type( | ||||
|         rfn.require_fields(a, [("b", "f4"), ("c", "u1")]), | ||||
|         np.ndarray[tuple[int], np.dtype[np.void]], | ||||
|     ) | ||||
|  | ||||
|  | ||||
| def test_stack_arrays() -> None: | ||||
|     x = np.zeros((int(2),), np.int32) | ||||
|     assert_type( | ||||
|         rfn.stack_arrays(x), | ||||
|         np.ndarray[tuple[int], np.dtype[np.int32]], | ||||
|     ) | ||||
|  | ||||
|     z = np.ones((int(2),), [("A", "|S3"), ("B", float)]) | ||||
|     zz = np.ones((int(2),), [("A", "|S3"), ("B", np.float64), ("C", np.float64)]) | ||||
|     assert_type( | ||||
|         rfn.stack_arrays((z, zz)), | ||||
|         np.ma.MaskedArray[tuple[Any, ...], np.dtype[np.void]], | ||||
|     ) | ||||
|  | ||||
|  | ||||
| def test_find_duplicates() -> None: | ||||
|     ndtype = np.dtype([("a", int)]) | ||||
|  | ||||
|     a = np.ma.ones(7, mask=[0, 0, 1, 0, 0, 0, 1]).view(ndtype) | ||||
|     assert_type(rfn.find_duplicates(a), np.ma.MaskedArray[Any, np.dtype[np.void]]) | ||||
|     assert_type( | ||||
|         rfn.find_duplicates(a, ignoremask=True, return_index=True), | ||||
|         tuple[ | ||||
|             np.ma.MaskedArray[Any, np.dtype[np.void]], | ||||
|             np.ndarray[Any, np.dtype[np.int_]], | ||||
|         ], | ||||
|     ) | ||||
| @ -0,0 +1,248 @@ | ||||
| import datetime as dt | ||||
|  | ||||
| import pytest | ||||
| import numpy as np | ||||
|  | ||||
| b = np.bool() | ||||
| b_ = np.bool_() | ||||
| u8 = np.uint64() | ||||
| i8 = np.int64() | ||||
| f8 = np.float64() | ||||
| c16 = np.complex128() | ||||
| U = np.str_() | ||||
| S = np.bytes_() | ||||
|  | ||||
|  | ||||
| # Construction | ||||
| class D: | ||||
|     def __index__(self) -> int: | ||||
|         return 0 | ||||
|  | ||||
|  | ||||
| class C: | ||||
|     def __complex__(self) -> complex: | ||||
|         return 3j | ||||
|  | ||||
|  | ||||
| class B: | ||||
|     def __int__(self) -> int: | ||||
|         return 4 | ||||
|  | ||||
|  | ||||
| class A: | ||||
|     def __float__(self) -> float: | ||||
|         return 4.0 | ||||
|  | ||||
|  | ||||
| np.complex64(3j) | ||||
| np.complex64(A()) | ||||
| np.complex64(C()) | ||||
| np.complex128(3j) | ||||
| np.complex128(C()) | ||||
| np.complex128(None) | ||||
| np.complex64("1.2") | ||||
| np.complex128(b"2j") | ||||
|  | ||||
| np.int8(4) | ||||
| np.int16(3.4) | ||||
| np.int32(4) | ||||
| np.int64(-1) | ||||
| np.uint8(B()) | ||||
| np.uint32() | ||||
| np.int32("1") | ||||
| np.int64(b"2") | ||||
|  | ||||
| np.float16(A()) | ||||
| np.float32(16) | ||||
| np.float64(3.0) | ||||
| np.float64(None) | ||||
| np.float32("1") | ||||
| np.float16(b"2.5") | ||||
|  | ||||
| np.uint64(D()) | ||||
| np.float32(D()) | ||||
| np.complex64(D()) | ||||
|  | ||||
| np.bytes_(b"hello") | ||||
| np.bytes_("hello", 'utf-8') | ||||
| np.bytes_("hello", encoding='utf-8') | ||||
| np.str_("hello") | ||||
| np.str_(b"hello", 'utf-8') | ||||
| np.str_(b"hello", encoding='utf-8') | ||||
|  | ||||
| # Array-ish semantics | ||||
| np.int8().real | ||||
| np.int16().imag | ||||
| np.int32().data | ||||
| np.int64().flags | ||||
|  | ||||
| np.uint8().itemsize * 2 | ||||
| np.uint16().ndim + 1 | ||||
| np.uint32().strides | ||||
| np.uint64().shape | ||||
|  | ||||
| # Time structures | ||||
| np.datetime64() | ||||
| np.datetime64(0, "D") | ||||
| np.datetime64(0, b"D") | ||||
| np.datetime64(0, ('ms', 3)) | ||||
| np.datetime64("2019") | ||||
| np.datetime64(b"2019") | ||||
| np.datetime64("2019", "D") | ||||
| np.datetime64("2019", "us") | ||||
| np.datetime64("2019", "as") | ||||
| np.datetime64(np.datetime64()) | ||||
| np.datetime64(np.datetime64()) | ||||
| np.datetime64(dt.datetime(2000, 5, 3)) | ||||
| np.datetime64(dt.datetime(2000, 5, 3), "D") | ||||
| np.datetime64(dt.datetime(2000, 5, 3), "us") | ||||
| np.datetime64(dt.datetime(2000, 5, 3), "as") | ||||
| np.datetime64(dt.date(2000, 5, 3)) | ||||
| np.datetime64(dt.date(2000, 5, 3), "D") | ||||
| np.datetime64(dt.date(2000, 5, 3), "us") | ||||
| np.datetime64(dt.date(2000, 5, 3), "as") | ||||
| np.datetime64(None) | ||||
| np.datetime64(None, "D") | ||||
|  | ||||
| np.timedelta64() | ||||
| np.timedelta64(0) | ||||
| np.timedelta64(0, "D") | ||||
| np.timedelta64(0, ('ms', 3)) | ||||
| np.timedelta64(0, b"D") | ||||
| np.timedelta64("3") | ||||
| np.timedelta64(b"5") | ||||
| np.timedelta64(np.timedelta64(2)) | ||||
| np.timedelta64(dt.timedelta(2)) | ||||
| np.timedelta64(None) | ||||
| np.timedelta64(None, "D") | ||||
|  | ||||
| np.void(1) | ||||
| np.void(np.int64(1)) | ||||
| np.void(True) | ||||
| np.void(np.bool(True)) | ||||
| np.void(b"test") | ||||
| np.void(np.bytes_("test")) | ||||
| np.void(object(), [("a", "O"), ("b", "O")]) | ||||
| np.void(object(), dtype=[("a", "O"), ("b", "O")]) | ||||
|  | ||||
| # Protocols | ||||
| i8 = np.int64() | ||||
| u8 = np.uint64() | ||||
| f8 = np.float64() | ||||
| c16 = np.complex128() | ||||
| b = np.bool() | ||||
| td = np.timedelta64() | ||||
| U = np.str_("1") | ||||
| S = np.bytes_("1") | ||||
| AR = np.array(1, dtype=np.float64) | ||||
|  | ||||
| int(i8) | ||||
| int(u8) | ||||
| int(f8) | ||||
| int(b) | ||||
| int(td) | ||||
| int(U) | ||||
| int(S) | ||||
| int(AR) | ||||
| with pytest.warns(np.exceptions.ComplexWarning): | ||||
|     int(c16) | ||||
|  | ||||
| float(i8) | ||||
| float(u8) | ||||
| float(f8) | ||||
| float(b_) | ||||
| float(td) | ||||
| float(U) | ||||
| float(S) | ||||
| float(AR) | ||||
| with pytest.warns(np.exceptions.ComplexWarning): | ||||
|     float(c16) | ||||
|  | ||||
| complex(i8) | ||||
| complex(u8) | ||||
| complex(f8) | ||||
| complex(c16) | ||||
| complex(b_) | ||||
| complex(td) | ||||
| complex(U) | ||||
| complex(AR) | ||||
|  | ||||
|  | ||||
| # Misc | ||||
| c16.dtype | ||||
| c16.real | ||||
| c16.imag | ||||
| c16.real.real | ||||
| c16.real.imag | ||||
| c16.ndim | ||||
| c16.size | ||||
| c16.itemsize | ||||
| c16.shape | ||||
| c16.strides | ||||
| c16.squeeze() | ||||
| c16.byteswap() | ||||
| c16.transpose() | ||||
|  | ||||
| # Aliases | ||||
| np.byte() | ||||
| np.short() | ||||
| np.intc() | ||||
| np.intp() | ||||
| np.int_() | ||||
| np.longlong() | ||||
|  | ||||
| np.ubyte() | ||||
| np.ushort() | ||||
| np.uintc() | ||||
| np.uintp() | ||||
| np.uint() | ||||
| np.ulonglong() | ||||
|  | ||||
| np.half() | ||||
| np.single() | ||||
| np.double() | ||||
| np.longdouble() | ||||
|  | ||||
| np.csingle() | ||||
| np.cdouble() | ||||
| np.clongdouble() | ||||
|  | ||||
| b.item() | ||||
| i8.item() | ||||
| u8.item() | ||||
| f8.item() | ||||
| c16.item() | ||||
| U.item() | ||||
| S.item() | ||||
|  | ||||
| b.tolist() | ||||
| i8.tolist() | ||||
| u8.tolist() | ||||
| f8.tolist() | ||||
| c16.tolist() | ||||
| U.tolist() | ||||
| S.tolist() | ||||
|  | ||||
| b.ravel() | ||||
| i8.ravel() | ||||
| u8.ravel() | ||||
| f8.ravel() | ||||
| c16.ravel() | ||||
| U.ravel() | ||||
| S.ravel() | ||||
|  | ||||
| b.flatten() | ||||
| i8.flatten() | ||||
| u8.flatten() | ||||
| f8.flatten() | ||||
| c16.flatten() | ||||
| U.flatten() | ||||
| S.flatten() | ||||
|  | ||||
| b.reshape(1) | ||||
| i8.reshape(1) | ||||
| u8.reshape(1) | ||||
| f8.reshape(1) | ||||
| c16.reshape(1) | ||||
| U.reshape(1) | ||||
| S.reshape(1) | ||||
| @ -0,0 +1,19 @@ | ||||
| from typing import Any, NamedTuple, cast | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
|  | ||||
| # Subtype of tuple[int, int] | ||||
| class XYGrid(NamedTuple): | ||||
|     x_axis: int | ||||
|     y_axis: int | ||||
|  | ||||
| # Test variance of _ShapeT_co | ||||
| def accepts_2d(a: np.ndarray[tuple[int, int], Any]) -> None: | ||||
|     return None | ||||
|  | ||||
|  | ||||
| accepts_2d(np.empty(XYGrid(2, 2))) | ||||
| accepts_2d(np.zeros(XYGrid(2, 2), dtype=int)) | ||||
| accepts_2d(np.ones(XYGrid(2, 2), dtype=int)) | ||||
| accepts_2d(np.full(XYGrid(2, 2), fill_value=5, dtype=int)) | ||||
| @ -0,0 +1,168 @@ | ||||
| """Simple expression that should pass with mypy.""" | ||||
| import operator | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| from collections.abc import Iterable | ||||
|  | ||||
| # Basic checks | ||||
| array = np.array([1, 2]) | ||||
|  | ||||
|  | ||||
| def ndarray_func(x: npt.NDArray[np.float64]) -> npt.NDArray[np.float64]: | ||||
|     return x | ||||
|  | ||||
|  | ||||
| ndarray_func(np.array([1, 2], dtype=np.float64)) | ||||
| array == 1 | ||||
| array.dtype == float | ||||
|  | ||||
| # Dtype construction | ||||
| np.dtype(float) | ||||
| np.dtype(np.float64) | ||||
| np.dtype(None) | ||||
| np.dtype("float64") | ||||
| np.dtype(np.dtype(float)) | ||||
| np.dtype(("U", 10)) | ||||
| np.dtype((np.int32, (2, 2))) | ||||
| # Define the arguments on the previous line to prevent bidirectional | ||||
| # type inference in mypy from broadening the types. | ||||
| two_tuples_dtype = [("R", "u1"), ("G", "u1"), ("B", "u1")] | ||||
| np.dtype(two_tuples_dtype) | ||||
|  | ||||
| three_tuples_dtype = [("R", "u1", 2)] | ||||
| np.dtype(three_tuples_dtype) | ||||
|  | ||||
| mixed_tuples_dtype = [("R", "u1"), ("G", np.str_, 1)] | ||||
| np.dtype(mixed_tuples_dtype) | ||||
|  | ||||
| shape_tuple_dtype = [("R", "u1", (2, 2))] | ||||
| np.dtype(shape_tuple_dtype) | ||||
|  | ||||
| shape_like_dtype = [("R", "u1", (2, 2)), ("G", np.str_, 1)] | ||||
| np.dtype(shape_like_dtype) | ||||
|  | ||||
| object_dtype = [("field1", object)] | ||||
| np.dtype(object_dtype) | ||||
|  | ||||
| np.dtype((np.int32, (np.int8, 4))) | ||||
|  | ||||
| # Dtype comparison | ||||
| np.dtype(float) == float | ||||
| np.dtype(float) != np.float64 | ||||
| np.dtype(float) < None | ||||
| np.dtype(float) <= "float64" | ||||
| np.dtype(float) > np.dtype(float) | ||||
| np.dtype(float) >= np.dtype(("U", 10)) | ||||
|  | ||||
| # Iteration and indexing | ||||
| def iterable_func(x: Iterable[object]) -> Iterable[object]: | ||||
|     return x | ||||
|  | ||||
|  | ||||
| iterable_func(array) | ||||
| list(array) | ||||
| iter(array) | ||||
| zip(array, array) | ||||
| array[1] | ||||
| array[:] | ||||
| array[...] | ||||
| array[:] = 0 | ||||
|  | ||||
| array_2d = np.ones((3, 3)) | ||||
| array_2d[:2, :2] | ||||
| array_2d[:2, :2] = 0 | ||||
| array_2d[..., 0] | ||||
| array_2d[..., 0] = 2 | ||||
| array_2d[-1, -1] = None | ||||
|  | ||||
| array_obj = np.zeros(1, dtype=np.object_) | ||||
| array_obj[0] = slice(None) | ||||
|  | ||||
| # Other special methods | ||||
| len(array) | ||||
| str(array) | ||||
| array_scalar = np.array(1) | ||||
| int(array_scalar) | ||||
| float(array_scalar) | ||||
| complex(array_scalar) | ||||
| bytes(array_scalar) | ||||
| operator.index(array_scalar) | ||||
| bool(array_scalar) | ||||
|  | ||||
| # comparisons | ||||
| array < 1 | ||||
| array <= 1 | ||||
| array == 1 | ||||
| array != 1 | ||||
| array > 1 | ||||
| array >= 1 | ||||
| 1 < array | ||||
| 1 <= array | ||||
| 1 == array | ||||
| 1 != array | ||||
| 1 > array | ||||
| 1 >= array | ||||
|  | ||||
| # binary arithmetic | ||||
| array + 1 | ||||
| 1 + array | ||||
| array += 1 | ||||
|  | ||||
| array - 1 | ||||
| 1 - array | ||||
| array -= 1 | ||||
|  | ||||
| array * 1 | ||||
| 1 * array | ||||
| array *= 1 | ||||
|  | ||||
| nonzero_array = np.array([1, 2]) | ||||
| array / 1 | ||||
| 1 / nonzero_array | ||||
| float_array = np.array([1.0, 2.0]) | ||||
| float_array /= 1 | ||||
|  | ||||
| array // 1 | ||||
| 1 // nonzero_array | ||||
| array //= 1 | ||||
|  | ||||
| array % 1 | ||||
| 1 % nonzero_array | ||||
| array %= 1 | ||||
|  | ||||
| divmod(array, 1) | ||||
| divmod(1, nonzero_array) | ||||
|  | ||||
| array ** 1 | ||||
| 1 ** array | ||||
| array **= 1 | ||||
|  | ||||
| array << 1 | ||||
| 1 << array | ||||
| array <<= 1 | ||||
|  | ||||
| array >> 1 | ||||
| 1 >> array | ||||
| array >>= 1 | ||||
|  | ||||
| array & 1 | ||||
| 1 & array | ||||
| array &= 1 | ||||
|  | ||||
| array ^ 1 | ||||
| 1 ^ array | ||||
| array ^= 1 | ||||
|  | ||||
| array | 1 | ||||
| 1 | array | ||||
| array |= 1 | ||||
|  | ||||
| # unary arithmetic | ||||
| -array | ||||
| +array | ||||
| abs(array) | ||||
| ~array | ||||
|  | ||||
| # Other methods | ||||
| np.array([1, 2]).transpose() | ||||
| @ -0,0 +1,6 @@ | ||||
| import numpy as np | ||||
|  | ||||
| array = np.array([1, 2]) | ||||
|  | ||||
| # The @ operator is not in python 2 | ||||
| array @ array | ||||
| @ -0,0 +1,64 @@ | ||||
| """Typing tests for `numpy._core._ufunc_config`.""" | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
|  | ||||
| def func1(a: str, b: int) -> None: | ||||
|     return None | ||||
|  | ||||
|  | ||||
| def func2(a: str, b: int, c: float = 1.0) -> None: | ||||
|     return None | ||||
|  | ||||
|  | ||||
| def func3(a: str, b: int) -> int: | ||||
|     return 0 | ||||
|  | ||||
|  | ||||
| class Write1: | ||||
|     def write(self, a: str) -> None: | ||||
|         return None | ||||
|  | ||||
|  | ||||
| class Write2: | ||||
|     def write(self, a: str, b: int = 1) -> None: | ||||
|         return None | ||||
|  | ||||
|  | ||||
| class Write3: | ||||
|     def write(self, a: str) -> int: | ||||
|         return 0 | ||||
|  | ||||
|  | ||||
| _err_default = np.geterr() | ||||
| _bufsize_default = np.getbufsize() | ||||
| _errcall_default = np.geterrcall() | ||||
|  | ||||
| try: | ||||
|     np.seterr(all=None) | ||||
|     np.seterr(divide="ignore") | ||||
|     np.seterr(over="warn") | ||||
|     np.seterr(under="call") | ||||
|     np.seterr(invalid="raise") | ||||
|     np.geterr() | ||||
|  | ||||
|     np.setbufsize(4096) | ||||
|     np.getbufsize() | ||||
|  | ||||
|     np.seterrcall(func1) | ||||
|     np.seterrcall(func2) | ||||
|     np.seterrcall(func3) | ||||
|     np.seterrcall(Write1()) | ||||
|     np.seterrcall(Write2()) | ||||
|     np.seterrcall(Write3()) | ||||
|     np.geterrcall() | ||||
|  | ||||
|     with np.errstate(call=func1, all="call"): | ||||
|         pass | ||||
|     with np.errstate(call=Write1(), divide="log", over="log"): | ||||
|         pass | ||||
|  | ||||
| finally: | ||||
|     np.seterr(**_err_default) | ||||
|     np.setbufsize(_bufsize_default) | ||||
|     np.seterrcall(_errcall_default) | ||||
| @ -0,0 +1,47 @@ | ||||
| from __future__ import annotations | ||||
| from typing import Any | ||||
| import numpy as np | ||||
|  | ||||
|  | ||||
| class Object: | ||||
|     def __ceil__(self) -> Object: | ||||
|         return self | ||||
|  | ||||
|     def __floor__(self) -> Object: | ||||
|         return self | ||||
|  | ||||
|     def __ge__(self, value: object) -> bool: | ||||
|         return True | ||||
|  | ||||
|     def __array__(self, dtype: np.typing.DTypeLike | None = None, | ||||
|                   copy: bool | None = None) -> np.ndarray[Any, np.dtype[np.object_]]: | ||||
|         ret = np.empty((), dtype=object) | ||||
|         ret[()] = self | ||||
|         return ret | ||||
|  | ||||
|  | ||||
| AR_LIKE_b = [True, True, False] | ||||
| AR_LIKE_u = [np.uint32(1), np.uint32(2), np.uint32(3)] | ||||
| AR_LIKE_i = [1, 2, 3] | ||||
| AR_LIKE_f = [1.0, 2.0, 3.0] | ||||
| AR_LIKE_O = [Object(), Object(), Object()] | ||||
| AR_U: np.ndarray[Any, np.dtype[np.str_]] = np.zeros(3, dtype="U5") | ||||
|  | ||||
| np.fix(AR_LIKE_b) | ||||
| np.fix(AR_LIKE_u) | ||||
| np.fix(AR_LIKE_i) | ||||
| np.fix(AR_LIKE_f) | ||||
| np.fix(AR_LIKE_O) | ||||
| np.fix(AR_LIKE_f, out=AR_U) | ||||
|  | ||||
| np.isposinf(AR_LIKE_b) | ||||
| np.isposinf(AR_LIKE_u) | ||||
| np.isposinf(AR_LIKE_i) | ||||
| np.isposinf(AR_LIKE_f) | ||||
| np.isposinf(AR_LIKE_f, out=AR_U) | ||||
|  | ||||
| np.isneginf(AR_LIKE_b) | ||||
| np.isneginf(AR_LIKE_u) | ||||
| np.isneginf(AR_LIKE_i) | ||||
| np.isneginf(AR_LIKE_f) | ||||
| np.isneginf(AR_LIKE_f, out=AR_U) | ||||
| @ -0,0 +1,16 @@ | ||||
| import numpy as np | ||||
|  | ||||
| np.sin(1) | ||||
| np.sin([1, 2, 3]) | ||||
| np.sin(1, out=np.empty(1)) | ||||
| np.matmul(np.ones((2, 2, 2)), np.ones((2, 2, 2)), axes=[(0, 1), (0, 1), (0, 1)]) | ||||
| np.sin(1, signature="D->D") | ||||
| # NOTE: `np.generic` subclasses are not guaranteed to support addition; | ||||
| # re-enable this we can infer the exact return type of `np.sin(...)`. | ||||
| # | ||||
| # np.sin(1) + np.sin(1) | ||||
| np.sin.types[0] | ||||
| np.sin.__name__ | ||||
| np.sin.__doc__ | ||||
|  | ||||
| np.abs(np.array([1])) | ||||
| @ -0,0 +1,6 @@ | ||||
| import numpy.exceptions as ex | ||||
|  | ||||
| ex.AxisError("test") | ||||
| ex.AxisError(1, ndim=2) | ||||
| ex.AxisError(1, ndim=2, msg_prefix="error") | ||||
| ex.AxisError(1, ndim=2, msg_prefix=None) | ||||
| @ -0,0 +1,720 @@ | ||||
| import datetime as dt | ||||
| from typing import Any, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| from numpy._typing import _32Bit, _64Bit, _128Bit | ||||
|  | ||||
| b: bool | ||||
| c: complex | ||||
| f: float | ||||
| i: int | ||||
|  | ||||
| c16: np.complex128 | ||||
| c8: np.complex64 | ||||
|  | ||||
| # Can't directly import `np.float128` as it is not available on all platforms | ||||
| f16: np.floating[_128Bit] | ||||
| f8: np.float64 | ||||
| f4: np.float32 | ||||
|  | ||||
| i8: np.int64 | ||||
| i4: np.int32 | ||||
|  | ||||
| u8: np.uint64 | ||||
| u4: np.uint32 | ||||
|  | ||||
| b_: np.bool | ||||
|  | ||||
| M8: np.datetime64 | ||||
| M8_none: np.datetime64[None] | ||||
| M8_date: np.datetime64[dt.date] | ||||
| M8_time: np.datetime64[dt.datetime] | ||||
| M8_int: np.datetime64[int] | ||||
| date: dt.date | ||||
| time: dt.datetime | ||||
|  | ||||
| m8: np.timedelta64 | ||||
| m8_none: np.timedelta64[None] | ||||
| m8_int: np.timedelta64[int] | ||||
| m8_delta: np.timedelta64[dt.timedelta] | ||||
| delta: dt.timedelta | ||||
|  | ||||
| AR_b: npt.NDArray[np.bool] | ||||
| AR_u: npt.NDArray[np.uint32] | ||||
| AR_i: npt.NDArray[np.int64] | ||||
| AR_f: npt.NDArray[np.float64] | ||||
| AR_c: npt.NDArray[np.complex128] | ||||
| AR_m: npt.NDArray[np.timedelta64] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
| AR_O: npt.NDArray[np.object_] | ||||
| AR_S: npt.NDArray[np.bytes_] | ||||
| AR_U: npt.NDArray[np.str_] | ||||
| AR_T: np.ndarray[tuple[Any, ...], np.dtypes.StringDType] | ||||
| AR_floating: npt.NDArray[np.floating] | ||||
| AR_number: npt.NDArray[np.number] | ||||
| AR_Any: npt.NDArray[Any] | ||||
|  | ||||
| AR_LIKE_b: list[bool] | ||||
| AR_LIKE_u: list[np.uint32] | ||||
| AR_LIKE_i: list[int] | ||||
| AR_LIKE_f: list[float] | ||||
| AR_LIKE_c: list[complex] | ||||
| AR_LIKE_m: list[np.timedelta64] | ||||
| AR_LIKE_M: list[np.datetime64] | ||||
| AR_LIKE_O: list[np.object_] | ||||
|  | ||||
|  | ||||
| # Array subtraction | ||||
|  | ||||
| assert_type(AR_number - AR_number, npt.NDArray[np.number]) | ||||
|  | ||||
| assert_type(AR_b - AR_LIKE_u, npt.NDArray[np.uint32]) | ||||
| assert_type(AR_b - AR_LIKE_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_b - AR_LIKE_f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_b - AR_LIKE_c, npt.NDArray[np.complexfloating]) | ||||
| assert_type(AR_b - AR_LIKE_m, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_b - AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_u - AR_b, npt.NDArray[np.uint32]) | ||||
| assert_type(AR_LIKE_i - AR_b, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_LIKE_f - AR_b, npt.NDArray[np.floating]) | ||||
| assert_type(AR_LIKE_c - AR_b, npt.NDArray[np.complexfloating]) | ||||
| assert_type(AR_LIKE_m - AR_b, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_M - AR_b, npt.NDArray[np.datetime64]) | ||||
| assert_type(AR_LIKE_O - AR_b, Any) | ||||
|  | ||||
| assert_type(AR_u - AR_LIKE_b, npt.NDArray[np.uint32]) | ||||
| assert_type(AR_u - AR_LIKE_u, npt.NDArray[np.unsignedinteger]) | ||||
| assert_type(AR_u - AR_LIKE_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_u - AR_LIKE_f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_u - AR_LIKE_c, npt.NDArray[np.complexfloating]) | ||||
| assert_type(AR_u - AR_LIKE_m, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_u - AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b - AR_u, npt.NDArray[np.uint32]) | ||||
| assert_type(AR_LIKE_u - AR_u, npt.NDArray[np.unsignedinteger]) | ||||
| assert_type(AR_LIKE_i - AR_u, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_LIKE_f - AR_u, npt.NDArray[np.floating]) | ||||
| assert_type(AR_LIKE_c - AR_u, npt.NDArray[np.complexfloating]) | ||||
| assert_type(AR_LIKE_m - AR_u, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_M - AR_u, npt.NDArray[np.datetime64]) | ||||
| assert_type(AR_LIKE_O - AR_u, Any) | ||||
|  | ||||
| assert_type(AR_i - AR_LIKE_b, npt.NDArray[np.int64]) | ||||
| assert_type(AR_i - AR_LIKE_u, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_i - AR_LIKE_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_i - AR_LIKE_f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_i - AR_LIKE_c, npt.NDArray[np.complexfloating]) | ||||
| assert_type(AR_i - AR_LIKE_m, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_i - AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b - AR_i, npt.NDArray[np.int64]) | ||||
| assert_type(AR_LIKE_u - AR_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_LIKE_i - AR_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_LIKE_f - AR_i, npt.NDArray[np.floating]) | ||||
| assert_type(AR_LIKE_c - AR_i, npt.NDArray[np.complexfloating]) | ||||
| assert_type(AR_LIKE_m - AR_i, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_M - AR_i, npt.NDArray[np.datetime64]) | ||||
| assert_type(AR_LIKE_O - AR_i, Any) | ||||
|  | ||||
| assert_type(AR_f - AR_LIKE_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f - AR_LIKE_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f - AR_LIKE_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f - AR_LIKE_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f - AR_LIKE_c, npt.NDArray[np.complexfloating]) | ||||
| assert_type(AR_f - AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b - AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_u - AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_i - AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_f - AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_c - AR_f, npt.NDArray[np.complexfloating]) | ||||
| assert_type(AR_LIKE_O - AR_f, Any) | ||||
|  | ||||
| assert_type(AR_c - AR_LIKE_b, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_c - AR_LIKE_u, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_c - AR_LIKE_i, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_c - AR_LIKE_f, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_c - AR_LIKE_c, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_c - AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b - AR_c, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_LIKE_u - AR_c, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_LIKE_i - AR_c, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_LIKE_f - AR_c, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_LIKE_c - AR_c, npt.NDArray[np.complex128]) | ||||
| assert_type(AR_LIKE_O - AR_c, Any) | ||||
|  | ||||
| assert_type(AR_m - AR_LIKE_b, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m - AR_LIKE_u, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m - AR_LIKE_i, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m - AR_LIKE_m, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m - AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b - AR_m, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_u - AR_m, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_i - AR_m, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_m - AR_m, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_M - AR_m, npt.NDArray[np.datetime64]) | ||||
| assert_type(AR_LIKE_O - AR_m, Any) | ||||
|  | ||||
| assert_type(AR_M - AR_LIKE_b, npt.NDArray[np.datetime64]) | ||||
| assert_type(AR_M - AR_LIKE_u, npt.NDArray[np.datetime64]) | ||||
| assert_type(AR_M - AR_LIKE_i, npt.NDArray[np.datetime64]) | ||||
| assert_type(AR_M - AR_LIKE_m, npt.NDArray[np.datetime64]) | ||||
| assert_type(AR_M - AR_LIKE_M, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_M - AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_M - AR_M, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_O - AR_M, Any) | ||||
|  | ||||
| assert_type(AR_O - AR_LIKE_b, Any) | ||||
| assert_type(AR_O - AR_LIKE_u, Any) | ||||
| assert_type(AR_O - AR_LIKE_i, Any) | ||||
| assert_type(AR_O - AR_LIKE_f, Any) | ||||
| assert_type(AR_O - AR_LIKE_c, Any) | ||||
| assert_type(AR_O - AR_LIKE_m, Any) | ||||
| assert_type(AR_O - AR_LIKE_M, Any) | ||||
| assert_type(AR_O - AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b - AR_O, Any) | ||||
| assert_type(AR_LIKE_u - AR_O, Any) | ||||
| assert_type(AR_LIKE_i - AR_O, Any) | ||||
| assert_type(AR_LIKE_f - AR_O, Any) | ||||
| assert_type(AR_LIKE_c - AR_O, Any) | ||||
| assert_type(AR_LIKE_m - AR_O, Any) | ||||
| assert_type(AR_LIKE_M - AR_O, Any) | ||||
| assert_type(AR_LIKE_O - AR_O, Any) | ||||
|  | ||||
| # Array "true" division | ||||
|  | ||||
| assert_type(AR_f / b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f / i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f / f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(b / AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(i / AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(f / AR_f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(AR_b / AR_LIKE_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_b / AR_LIKE_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_b / AR_LIKE_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_b / AR_LIKE_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_b / AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b / AR_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_u / AR_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_i / AR_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_f / AR_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_O / AR_b, Any) | ||||
|  | ||||
| assert_type(AR_u / AR_LIKE_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_u / AR_LIKE_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_u / AR_LIKE_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_u / AR_LIKE_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_u / AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b / AR_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_u / AR_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_i / AR_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_f / AR_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_m / AR_u, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_O / AR_u, Any) | ||||
|  | ||||
| assert_type(AR_i / AR_LIKE_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_i / AR_LIKE_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_i / AR_LIKE_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_i / AR_LIKE_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_i / AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b / AR_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_u / AR_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_i / AR_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_f / AR_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_m / AR_i, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_O / AR_i, Any) | ||||
|  | ||||
| assert_type(AR_f / AR_LIKE_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f / AR_LIKE_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f / AR_LIKE_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f / AR_LIKE_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f / AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b / AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_u / AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_i / AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_f / AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_m / AR_f, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_O / AR_f, Any) | ||||
|  | ||||
| assert_type(AR_m / AR_LIKE_u, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m / AR_LIKE_i, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m / AR_LIKE_f, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m / AR_LIKE_m, npt.NDArray[np.float64]) | ||||
| assert_type(AR_m / AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_m / AR_m, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_O / AR_m, Any) | ||||
|  | ||||
| assert_type(AR_O / AR_LIKE_b, Any) | ||||
| assert_type(AR_O / AR_LIKE_u, Any) | ||||
| assert_type(AR_O / AR_LIKE_i, Any) | ||||
| assert_type(AR_O / AR_LIKE_f, Any) | ||||
| assert_type(AR_O / AR_LIKE_m, Any) | ||||
| assert_type(AR_O / AR_LIKE_M, Any) | ||||
| assert_type(AR_O / AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b / AR_O, Any) | ||||
| assert_type(AR_LIKE_u / AR_O, Any) | ||||
| assert_type(AR_LIKE_i / AR_O, Any) | ||||
| assert_type(AR_LIKE_f / AR_O, Any) | ||||
| assert_type(AR_LIKE_m / AR_O, Any) | ||||
| assert_type(AR_LIKE_M / AR_O, Any) | ||||
| assert_type(AR_LIKE_O / AR_O, Any) | ||||
|  | ||||
| # Array floor division | ||||
|  | ||||
| assert_type(AR_b // AR_LIKE_b, npt.NDArray[np.int8]) | ||||
| assert_type(AR_b // AR_LIKE_u, npt.NDArray[np.uint32]) | ||||
| assert_type(AR_b // AR_LIKE_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_b // AR_LIKE_f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_b // AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b // AR_b, npt.NDArray[np.int8]) | ||||
| assert_type(AR_LIKE_u // AR_b, npt.NDArray[np.uint32]) | ||||
| assert_type(AR_LIKE_i // AR_b, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_LIKE_f // AR_b, npt.NDArray[np.floating]) | ||||
| assert_type(AR_LIKE_O // AR_b, Any) | ||||
|  | ||||
| assert_type(AR_u // AR_LIKE_b, npt.NDArray[np.uint32]) | ||||
| assert_type(AR_u // AR_LIKE_u, npt.NDArray[np.unsignedinteger]) | ||||
| assert_type(AR_u // AR_LIKE_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_u // AR_LIKE_f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_u // AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b // AR_u, npt.NDArray[np.uint32]) | ||||
| assert_type(AR_LIKE_u // AR_u, npt.NDArray[np.unsignedinteger]) | ||||
| assert_type(AR_LIKE_i // AR_u, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_LIKE_f // AR_u, npt.NDArray[np.floating]) | ||||
| assert_type(AR_LIKE_m // AR_u, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_O // AR_u, Any) | ||||
|  | ||||
| assert_type(AR_i // AR_LIKE_b, npt.NDArray[np.int64]) | ||||
| assert_type(AR_i // AR_LIKE_u, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_i // AR_LIKE_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_i // AR_LIKE_f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_i // AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b // AR_i, npt.NDArray[np.int64]) | ||||
| assert_type(AR_LIKE_u // AR_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_LIKE_i // AR_i, npt.NDArray[np.signedinteger]) | ||||
| assert_type(AR_LIKE_f // AR_i, npt.NDArray[np.floating]) | ||||
| assert_type(AR_LIKE_m // AR_i, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_O // AR_i, Any) | ||||
|  | ||||
| assert_type(AR_f // AR_LIKE_b, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f // AR_LIKE_u, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f // AR_LIKE_i, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f // AR_LIKE_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_f // AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b // AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_u // AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_i // AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_f // AR_f, npt.NDArray[np.float64]) | ||||
| assert_type(AR_LIKE_m // AR_f, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_LIKE_O // AR_f, Any) | ||||
|  | ||||
| assert_type(AR_m // AR_LIKE_u, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m // AR_LIKE_i, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m // AR_LIKE_f, npt.NDArray[np.timedelta64]) | ||||
| assert_type(AR_m // AR_LIKE_m, npt.NDArray[np.int64]) | ||||
| assert_type(AR_m // AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_m // AR_m, npt.NDArray[np.int64]) | ||||
| assert_type(AR_LIKE_O // AR_m, Any) | ||||
|  | ||||
| assert_type(AR_O // AR_LIKE_b, Any) | ||||
| assert_type(AR_O // AR_LIKE_u, Any) | ||||
| assert_type(AR_O // AR_LIKE_i, Any) | ||||
| assert_type(AR_O // AR_LIKE_f, Any) | ||||
| assert_type(AR_O // AR_LIKE_m, Any) | ||||
| assert_type(AR_O // AR_LIKE_M, Any) | ||||
| assert_type(AR_O // AR_LIKE_O, Any) | ||||
|  | ||||
| assert_type(AR_LIKE_b // AR_O, Any) | ||||
| assert_type(AR_LIKE_u // AR_O, Any) | ||||
| assert_type(AR_LIKE_i // AR_O, Any) | ||||
| assert_type(AR_LIKE_f // AR_O, Any) | ||||
| assert_type(AR_LIKE_m // AR_O, Any) | ||||
| assert_type(AR_LIKE_M // AR_O, Any) | ||||
| assert_type(AR_LIKE_O // AR_O, Any) | ||||
|  | ||||
| # unary ops | ||||
|  | ||||
| assert_type(-f16, np.floating[_128Bit]) | ||||
| assert_type(-c16, np.complex128) | ||||
| assert_type(-c8, np.complex64) | ||||
| assert_type(-f8, np.float64) | ||||
| assert_type(-f4, np.float32) | ||||
| assert_type(-i8, np.int64) | ||||
| assert_type(-i4, np.int32) | ||||
| assert_type(-u8, np.uint64) | ||||
| assert_type(-u4, np.uint32) | ||||
| assert_type(-m8, np.timedelta64) | ||||
| assert_type(-m8_none, np.timedelta64[None]) | ||||
| assert_type(-m8_int, np.timedelta64[int]) | ||||
| assert_type(-m8_delta, np.timedelta64[dt.timedelta]) | ||||
| assert_type(-AR_f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(+f16, np.floating[_128Bit]) | ||||
| assert_type(+c16, np.complex128) | ||||
| assert_type(+c8, np.complex64) | ||||
| assert_type(+f8, np.float64) | ||||
| assert_type(+f4, np.float32) | ||||
| assert_type(+i8, np.int64) | ||||
| assert_type(+i4, np.int32) | ||||
| assert_type(+u8, np.uint64) | ||||
| assert_type(+u4, np.uint32) | ||||
| assert_type(+m8_none, np.timedelta64[None]) | ||||
| assert_type(+m8_int, np.timedelta64[int]) | ||||
| assert_type(+m8_delta, np.timedelta64[dt.timedelta]) | ||||
| assert_type(+AR_f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(abs(f16), np.floating[_128Bit]) | ||||
| assert_type(abs(c16), np.float64) | ||||
| assert_type(abs(c8), np.float32) | ||||
| assert_type(abs(f8), np.float64) | ||||
| assert_type(abs(f4), np.float32) | ||||
| assert_type(abs(i8), np.int64) | ||||
| assert_type(abs(i4), np.int32) | ||||
| assert_type(abs(u8), np.uint64) | ||||
| assert_type(abs(u4), np.uint32) | ||||
| assert_type(abs(m8), np.timedelta64) | ||||
| assert_type(abs(m8_none), np.timedelta64[None]) | ||||
| assert_type(abs(m8_int), np.timedelta64[int]) | ||||
| assert_type(abs(m8_delta), np.timedelta64[dt.timedelta]) | ||||
| assert_type(abs(b_), np.bool) | ||||
| assert_type(abs(AR_O), npt.NDArray[np.object_]) | ||||
|  | ||||
| # Time structures | ||||
|  | ||||
| assert_type(M8 + m8, np.datetime64) | ||||
| assert_type(M8 + i, np.datetime64) | ||||
| assert_type(M8 + i8, np.datetime64) | ||||
| assert_type(M8 - M8, np.timedelta64) | ||||
| assert_type(M8 - i, np.datetime64) | ||||
| assert_type(M8 - i8, np.datetime64) | ||||
|  | ||||
| assert_type(M8_none + m8, np.datetime64[None]) | ||||
| assert_type(M8_none + i, np.datetime64[None]) | ||||
| assert_type(M8_none + i8, np.datetime64[None]) | ||||
| assert_type(M8_none - M8, np.timedelta64[None]) | ||||
| assert_type(M8_none - m8, np.datetime64[None]) | ||||
| assert_type(M8_none - i, np.datetime64[None]) | ||||
| assert_type(M8_none - i8, np.datetime64[None]) | ||||
|  | ||||
| assert_type(m8 + m8, np.timedelta64) | ||||
| assert_type(m8 + i, np.timedelta64) | ||||
| assert_type(m8 + i8, np.timedelta64) | ||||
| assert_type(m8 - m8, np.timedelta64) | ||||
| assert_type(m8 - i, np.timedelta64) | ||||
| assert_type(m8 - i8, np.timedelta64) | ||||
| assert_type(m8 * f, np.timedelta64) | ||||
| assert_type(m8 * f4, np.timedelta64) | ||||
| assert_type(m8 * np.True_, np.timedelta64) | ||||
| assert_type(m8 / f, np.timedelta64) | ||||
| assert_type(m8 / f4, np.timedelta64) | ||||
| assert_type(m8 / m8, np.float64) | ||||
| assert_type(m8 // m8, np.int64) | ||||
| assert_type(m8 % m8, np.timedelta64) | ||||
| assert_type(divmod(m8, m8), tuple[np.int64, np.timedelta64]) | ||||
|  | ||||
| assert_type(m8_none + m8, np.timedelta64[None]) | ||||
| assert_type(m8_none + i, np.timedelta64[None]) | ||||
| assert_type(m8_none + i8, np.timedelta64[None]) | ||||
| assert_type(m8_none - i, np.timedelta64[None]) | ||||
| assert_type(m8_none - i8, np.timedelta64[None]) | ||||
|  | ||||
| assert_type(m8_int + i, np.timedelta64[int]) | ||||
| assert_type(m8_int + m8_delta, np.timedelta64[int]) | ||||
| assert_type(m8_int + m8, np.timedelta64[int | None]) | ||||
| assert_type(m8_int - i, np.timedelta64[int]) | ||||
| assert_type(m8_int - m8_delta, np.timedelta64[int]) | ||||
| assert_type(m8_int - m8, np.timedelta64[int | None]) | ||||
|  | ||||
| assert_type(m8_delta + date, dt.date) | ||||
| assert_type(m8_delta + time, dt.datetime) | ||||
| assert_type(m8_delta + delta, dt.timedelta) | ||||
| assert_type(m8_delta - delta, dt.timedelta) | ||||
| assert_type(m8_delta / delta, float) | ||||
| assert_type(m8_delta // delta, int) | ||||
| assert_type(m8_delta % delta, dt.timedelta) | ||||
| assert_type(divmod(m8_delta, delta), tuple[int, dt.timedelta]) | ||||
|  | ||||
| # boolean | ||||
|  | ||||
| assert_type(b_ / b, np.float64) | ||||
| assert_type(b_ / b_, np.float64) | ||||
| assert_type(b_ / i, np.float64) | ||||
| assert_type(b_ / i8, np.float64) | ||||
| assert_type(b_ / i4, np.float64) | ||||
| assert_type(b_ / u8, np.float64) | ||||
| assert_type(b_ / u4, np.float64) | ||||
| assert_type(b_ / f, np.float64) | ||||
| assert_type(b_ / f16, np.floating[_128Bit]) | ||||
| assert_type(b_ / f8, np.float64) | ||||
| assert_type(b_ / f4, np.float32) | ||||
| assert_type(b_ / c, np.complex128) | ||||
| assert_type(b_ / c16, np.complex128) | ||||
| assert_type(b_ / c8, np.complex64) | ||||
|  | ||||
| assert_type(b / b_, np.float64) | ||||
| assert_type(b_ / b_, np.float64) | ||||
| assert_type(i / b_, np.float64) | ||||
| assert_type(i8 / b_, np.float64) | ||||
| assert_type(i4 / b_, np.float64) | ||||
| assert_type(u8 / b_, np.float64) | ||||
| assert_type(u4 / b_, np.float64) | ||||
| assert_type(f / b_, np.float64) | ||||
| assert_type(f16 / b_, np.floating[_128Bit]) | ||||
| assert_type(f8 / b_, np.float64) | ||||
| assert_type(f4 / b_, np.float32) | ||||
| assert_type(c / b_, np.complex128) | ||||
| assert_type(c16 / b_, np.complex128) | ||||
| assert_type(c8 / b_, np.complex64) | ||||
|  | ||||
| # Complex | ||||
|  | ||||
| assert_type(c16 + f16, np.complex128 | np.complexfloating[_128Bit, _128Bit]) | ||||
| assert_type(c16 + c16, np.complex128) | ||||
| assert_type(c16 + f8, np.complex128) | ||||
| assert_type(c16 + i8, np.complex128) | ||||
| assert_type(c16 + c8, np.complex128) | ||||
| assert_type(c16 + f4, np.complex128) | ||||
| assert_type(c16 + i4, np.complex128) | ||||
| assert_type(c16 + b_, np.complex128) | ||||
| assert_type(c16 + b, np.complex128) | ||||
| assert_type(c16 + c, np.complex128) | ||||
| assert_type(c16 + f, np.complex128) | ||||
| assert_type(c16 + AR_f, npt.NDArray[np.complex128]) | ||||
|  | ||||
| assert_type(f16 + c16, np.complex128 | np.complexfloating[_128Bit, _128Bit]) | ||||
| assert_type(c16 + c16, np.complex128) | ||||
| assert_type(f8 + c16, np.complex128) | ||||
| assert_type(i8 + c16, np.complex128) | ||||
| assert_type(c8 + c16, np.complex128 | np.complex64) | ||||
| assert_type(f4 + c16, np.complex128 | np.complex64) | ||||
| assert_type(i4 + c16, np.complex128) | ||||
| assert_type(b_ + c16, np.complex128) | ||||
| assert_type(b + c16, np.complex128) | ||||
| assert_type(c + c16, np.complex128) | ||||
| assert_type(f + c16, np.complex128) | ||||
| assert_type(AR_f + c16, npt.NDArray[np.complex128]) | ||||
|  | ||||
| assert_type(c8 + f16, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_128Bit, _128Bit]) | ||||
| assert_type(c8 + c16, np.complex64 | np.complex128) | ||||
| assert_type(c8 + f8, np.complex64 | np.complex128) | ||||
| assert_type(c8 + i8, np.complexfloating[_32Bit, _32Bit] | np.complexfloating[_64Bit, _64Bit]) | ||||
| assert_type(c8 + c8, np.complex64) | ||||
| assert_type(c8 + f4, np.complex64) | ||||
| assert_type(c8 + i4, np.complex64) | ||||
| assert_type(c8 + b_, np.complex64) | ||||
| assert_type(c8 + b, np.complex64) | ||||
| assert_type(c8 + c, np.complex64 | np.complex128) | ||||
| assert_type(c8 + f, np.complex64 | np.complex128) | ||||
| assert_type(c8 + AR_f, npt.NDArray[np.complexfloating]) | ||||
|  | ||||
| assert_type(f16 + c8, np.complexfloating[_128Bit, _128Bit] | np.complex64) | ||||
| assert_type(c16 + c8, np.complex128) | ||||
| assert_type(f8 + c8, np.complexfloating[_64Bit, _64Bit]) | ||||
| assert_type(i8 + c8, np.complexfloating[_64Bit, _64Bit] | np.complex64) | ||||
| assert_type(c8 + c8, np.complex64) | ||||
| assert_type(f4 + c8, np.complex64) | ||||
| assert_type(i4 + c8, np.complex64) | ||||
| assert_type(b_ + c8, np.complex64) | ||||
| assert_type(b + c8, np.complex64) | ||||
| assert_type(c + c8, np.complex64 | np.complex128) | ||||
| assert_type(f + c8, np.complex64 | np.complex128) | ||||
| assert_type(AR_f + c8, npt.NDArray[np.complexfloating]) | ||||
|  | ||||
| # Float | ||||
|  | ||||
| assert_type(f8 + f16, np.float64 | np.floating[_128Bit]) | ||||
| assert_type(f8 + f8, np.float64) | ||||
| assert_type(f8 + i8, np.float64) | ||||
| assert_type(f8 + f4, np.float64) | ||||
| assert_type(f8 + i4, np.float64) | ||||
| assert_type(f8 + b_, np.float64) | ||||
| assert_type(f8 + b, np.float64) | ||||
| assert_type(f8 + c, np.float64 | np.complex128) | ||||
| assert_type(f8 + f, np.float64) | ||||
| assert_type(f8 + AR_f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(f16 + f8, np.floating[_128Bit] | np.float64) | ||||
| assert_type(f8 + f8, np.float64) | ||||
| assert_type(i8 + f8, np.float64) | ||||
| assert_type(f4 + f8, np.float32 | np.float64) | ||||
| assert_type(i4 + f8,np.float64) | ||||
| assert_type(b_ + f8, np.float64) | ||||
| assert_type(b + f8, np.float64) | ||||
| assert_type(c + f8, np.complex128 | np.float64) | ||||
| assert_type(f + f8, np.float64) | ||||
| assert_type(AR_f + f8, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(f4 + f16, np.float32 | np.floating[_128Bit]) | ||||
| assert_type(f4 + f8, np.float32 | np.float64) | ||||
| assert_type(f4 + i8, np.float32 | np.floating[_64Bit]) | ||||
| assert_type(f4 + f4, np.float32) | ||||
| assert_type(f4 + i4, np.float32) | ||||
| assert_type(f4 + b_, np.float32) | ||||
| assert_type(f4 + b, np.float32) | ||||
| assert_type(f4 + c, np.complex64 | np.complex128) | ||||
| assert_type(f4 + f, np.float32 | np.float64) | ||||
| assert_type(f4 + AR_f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(f16 + f4, np.floating[_128Bit] | np.float32) | ||||
| assert_type(f8 + f4, np.float64) | ||||
| assert_type(i8 + f4, np.floating[_32Bit] | np.floating[_64Bit]) | ||||
| assert_type(f4 + f4, np.float32) | ||||
| assert_type(i4 + f4, np.float32) | ||||
| assert_type(b_ + f4, np.float32) | ||||
| assert_type(b + f4, np.float32) | ||||
| assert_type(c + f4, np.complex64 | np.complex128) | ||||
| assert_type(f + f4, np.float64 | np.float32) | ||||
| assert_type(AR_f + f4, npt.NDArray[np.float64]) | ||||
|  | ||||
| # Int | ||||
|  | ||||
| assert_type(i8 + i8, np.int64) | ||||
| assert_type(i8 + u8, Any) | ||||
| assert_type(i8 + i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) | ||||
| assert_type(i8 + u4, Any) | ||||
| assert_type(i8 + b_, np.int64) | ||||
| assert_type(i8 + b, np.int64) | ||||
| assert_type(i8 + c, np.complex128) | ||||
| assert_type(i8 + f, np.float64) | ||||
| assert_type(i8 + AR_f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(u8 + u8, np.uint64) | ||||
| assert_type(u8 + i4, Any) | ||||
| assert_type(u8 + u4, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit]) | ||||
| assert_type(u8 + b_, np.uint64) | ||||
| assert_type(u8 + b, np.uint64) | ||||
| assert_type(u8 + c, np.complex128) | ||||
| assert_type(u8 + f, np.float64) | ||||
| assert_type(u8 + AR_f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(i8 + i8, np.int64) | ||||
| assert_type(u8 + i8, Any) | ||||
| assert_type(i4 + i8, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) | ||||
| assert_type(u4 + i8, Any) | ||||
| assert_type(b_ + i8, np.int64) | ||||
| assert_type(b + i8, np.int64) | ||||
| assert_type(c + i8, np.complex128) | ||||
| assert_type(f + i8, np.float64) | ||||
| assert_type(AR_f + i8, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(u8 + u8, np.uint64) | ||||
| assert_type(i4 + u8, Any) | ||||
| assert_type(u4 + u8, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit]) | ||||
| assert_type(b_ + u8, np.uint64) | ||||
| assert_type(b + u8, np.uint64) | ||||
| assert_type(c + u8, np.complex128) | ||||
| assert_type(f + u8, np.float64) | ||||
| assert_type(AR_f + u8, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(i4 + i8, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) | ||||
| assert_type(i4 + i4, np.int32) | ||||
| assert_type(i4 + b_, np.int32) | ||||
| assert_type(i4 + b, np.int32) | ||||
| assert_type(i4 + AR_f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(u4 + i8, Any) | ||||
| assert_type(u4 + i4, Any) | ||||
| assert_type(u4 + u8, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit]) | ||||
| assert_type(u4 + u4, np.uint32) | ||||
| assert_type(u4 + b_, np.uint32) | ||||
| assert_type(u4 + b, np.uint32) | ||||
| assert_type(u4 + AR_f, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(i8 + i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) | ||||
| assert_type(i4 + i4, np.int32) | ||||
| assert_type(b_ + i4, np.int32) | ||||
| assert_type(b + i4, np.int32) | ||||
| assert_type(AR_f + i4, npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(i8 + u4, Any) | ||||
| assert_type(i4 + u4, Any) | ||||
| assert_type(u8 + u4, np.unsignedinteger[_32Bit] | np.unsignedinteger[_64Bit]) | ||||
| assert_type(u4 + u4, np.uint32) | ||||
| assert_type(b_ + u4, np.uint32) | ||||
| assert_type(b + u4, np.uint32) | ||||
| assert_type(AR_f + u4, npt.NDArray[np.float64]) | ||||
|  | ||||
| # Any | ||||
|  | ||||
| assert_type(AR_Any + 2, npt.NDArray[Any]) | ||||
|  | ||||
| # regression tests for https://github.com/numpy/numpy/issues/28805 | ||||
|  | ||||
| assert_type(AR_floating + f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_floating - f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_floating * f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_floating ** f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_floating / f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_floating // f, npt.NDArray[np.floating]) | ||||
| assert_type(AR_floating % f, npt.NDArray[np.floating]) | ||||
| assert_type(divmod(AR_floating, f), tuple[npt.NDArray[np.floating], npt.NDArray[np.floating]]) | ||||
|  | ||||
| assert_type(f + AR_floating, npt.NDArray[np.floating]) | ||||
| assert_type(f - AR_floating, npt.NDArray[np.floating]) | ||||
| assert_type(f * AR_floating, npt.NDArray[np.floating]) | ||||
| assert_type(f ** AR_floating, npt.NDArray[np.floating]) | ||||
| assert_type(f / AR_floating, npt.NDArray[np.floating]) | ||||
| assert_type(f // AR_floating, npt.NDArray[np.floating]) | ||||
| assert_type(f % AR_floating, npt.NDArray[np.floating]) | ||||
| assert_type(divmod(f, AR_floating), tuple[npt.NDArray[np.floating], npt.NDArray[np.floating]]) | ||||
|  | ||||
| # character-like | ||||
|  | ||||
| assert_type(AR_S + b"", npt.NDArray[np.bytes_]) | ||||
| assert_type(AR_S + [b""], npt.NDArray[np.bytes_]) | ||||
| assert_type([b""] + AR_S, npt.NDArray[np.bytes_]) | ||||
| assert_type(AR_S + AR_S, npt.NDArray[np.bytes_]) | ||||
|  | ||||
| assert_type(AR_U + "", npt.NDArray[np.str_]) | ||||
| assert_type(AR_U + [""], npt.NDArray[np.str_]) | ||||
| assert_type("" + AR_U, npt.NDArray[np.str_]) | ||||
| assert_type([""] + AR_U, npt.NDArray[np.str_]) | ||||
| assert_type(AR_U + AR_U, npt.NDArray[np.str_]) | ||||
|  | ||||
| assert_type(AR_T + "", np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| assert_type(AR_T + [""], np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| assert_type("" + AR_T, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| assert_type([""] + AR_T, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| assert_type(AR_T + AR_T, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| assert_type(AR_T + AR_U, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| assert_type(AR_U + AR_T, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
|  | ||||
| assert_type(AR_S * i, np.ndarray[tuple[Any, ...], np.dtype[np.bytes_]]) | ||||
| assert_type(AR_S * AR_LIKE_i, np.ndarray[tuple[Any, ...], np.dtype[np.bytes_]]) | ||||
| assert_type(AR_S * AR_i, np.ndarray[tuple[Any, ...], np.dtype[np.bytes_]]) | ||||
| assert_type(i * AR_S, np.ndarray[tuple[Any, ...], np.dtype[np.bytes_]]) | ||||
| # mypy incorrectly infers `AR_LIKE_i * AR_S` as `list[int]` | ||||
| assert_type(AR_i * AR_S, np.ndarray[tuple[Any, ...], np.dtype[np.bytes_]]) | ||||
|  | ||||
| assert_type(AR_U * i, np.ndarray[tuple[Any, ...], np.dtype[np.str_]]) | ||||
| assert_type(AR_U * AR_LIKE_i, np.ndarray[tuple[Any, ...], np.dtype[np.str_]]) | ||||
| assert_type(AR_U * AR_i, np.ndarray[tuple[Any, ...], np.dtype[np.str_]]) | ||||
| assert_type(i * AR_U, np.ndarray[tuple[Any, ...], np.dtype[np.str_]]) | ||||
| # mypy incorrectly infers `AR_LIKE_i * AR_U` as `list[int]` | ||||
| assert_type(AR_i * AR_U, np.ndarray[tuple[Any, ...], np.dtype[np.str_]]) | ||||
|  | ||||
| assert_type(AR_T * i, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| assert_type(AR_T * AR_LIKE_i, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| assert_type(AR_T * AR_i, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| assert_type(i * AR_T, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| # mypy incorrectly infers `AR_LIKE_i * AR_T` as `list[int]` | ||||
| assert_type(AR_i * AR_T, np.ndarray[tuple[Any, ...], np.dtypes.StringDType]) | ||||
| @ -0,0 +1,70 @@ | ||||
| from typing import Literal, Never, assert_type | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
| info = np.__array_namespace_info__() | ||||
|  | ||||
| assert_type(info.__module__, Literal["numpy"]) | ||||
|  | ||||
| assert_type(info.default_device(), Literal["cpu"]) | ||||
| assert_type(info.devices()[0], Literal["cpu"]) | ||||
| assert_type(info.devices()[-1], Literal["cpu"]) | ||||
|  | ||||
| assert_type(info.capabilities()["boolean indexing"], Literal[True]) | ||||
| assert_type(info.capabilities()["data-dependent shapes"], Literal[True]) | ||||
|  | ||||
| assert_type(info.default_dtypes()["real floating"], np.dtype[np.float64]) | ||||
| assert_type(info.default_dtypes()["complex floating"], np.dtype[np.complex128]) | ||||
| assert_type(info.default_dtypes()["integral"], np.dtype[np.int_]) | ||||
| assert_type(info.default_dtypes()["indexing"], np.dtype[np.intp]) | ||||
|  | ||||
| assert_type(info.dtypes()["bool"], np.dtype[np.bool]) | ||||
| assert_type(info.dtypes()["int8"], np.dtype[np.int8]) | ||||
| assert_type(info.dtypes()["uint8"], np.dtype[np.uint8]) | ||||
| assert_type(info.dtypes()["float32"], np.dtype[np.float32]) | ||||
| assert_type(info.dtypes()["complex64"], np.dtype[np.complex64]) | ||||
|  | ||||
| assert_type(info.dtypes(kind="bool")["bool"], np.dtype[np.bool]) | ||||
| assert_type(info.dtypes(kind="signed integer")["int64"], np.dtype[np.int64]) | ||||
| assert_type(info.dtypes(kind="unsigned integer")["uint64"], np.dtype[np.uint64]) | ||||
| assert_type(info.dtypes(kind="integral")["int32"], np.dtype[np.int32]) | ||||
| assert_type(info.dtypes(kind="integral")["uint32"], np.dtype[np.uint32]) | ||||
| assert_type(info.dtypes(kind="real floating")["float64"], np.dtype[np.float64]) | ||||
| assert_type(info.dtypes(kind="complex floating")["complex128"], np.dtype[np.complex128]) | ||||
| assert_type(info.dtypes(kind="numeric")["int16"], np.dtype[np.int16]) | ||||
| assert_type(info.dtypes(kind="numeric")["uint16"], np.dtype[np.uint16]) | ||||
| assert_type(info.dtypes(kind="numeric")["float64"], np.dtype[np.float64]) | ||||
| assert_type(info.dtypes(kind="numeric")["complex128"], np.dtype[np.complex128]) | ||||
|  | ||||
| assert_type(info.dtypes(kind=()), dict[Never, Never]) | ||||
|  | ||||
| assert_type(info.dtypes(kind=("bool",))["bool"], np.dtype[np.bool]) | ||||
| assert_type(info.dtypes(kind=("signed integer",))["int64"], np.dtype[np.int64]) | ||||
| assert_type(info.dtypes(kind=("integral",))["uint32"], np.dtype[np.uint32]) | ||||
| assert_type(info.dtypes(kind=("complex floating",))["complex128"], np.dtype[np.complex128]) | ||||
| assert_type(info.dtypes(kind=("numeric",))["float64"], np.dtype[np.float64]) | ||||
|  | ||||
| assert_type( | ||||
|     info.dtypes(kind=("signed integer", "unsigned integer"))["int8"], | ||||
|     np.dtype[np.int8], | ||||
| ) | ||||
| assert_type( | ||||
|     info.dtypes(kind=("signed integer", "unsigned integer"))["uint8"], | ||||
|     np.dtype[np.uint8], | ||||
| ) | ||||
| assert_type( | ||||
|     info.dtypes(kind=("integral", "real floating", "complex floating"))["int16"], | ||||
|     np.dtype[np.int16], | ||||
| ) | ||||
| assert_type( | ||||
|     info.dtypes(kind=("integral", "real floating", "complex floating"))["uint16"], | ||||
|     np.dtype[np.uint16], | ||||
| ) | ||||
| assert_type( | ||||
|     info.dtypes(kind=("integral", "real floating", "complex floating"))["float32"], | ||||
|     np.dtype[np.float32], | ||||
| ) | ||||
| assert_type( | ||||
|     info.dtypes(kind=("integral", "real floating", "complex floating"))["complex64"], | ||||
|     np.dtype[np.complex64], | ||||
| ) | ||||
| @ -0,0 +1,249 @@ | ||||
| import sys | ||||
| from collections import deque | ||||
| from pathlib import Path | ||||
| from typing import Any, TypeVar, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| _ScalarT_co = TypeVar("_ScalarT_co", bound=np.generic, covariant=True) | ||||
|  | ||||
| class SubClass(npt.NDArray[_ScalarT_co]): ... | ||||
|  | ||||
| i8: np.int64 | ||||
|  | ||||
| A: npt.NDArray[np.float64] | ||||
| B: SubClass[np.float64] | ||||
| C: list[int] | ||||
| D: SubClass[np.float64 | np.int64] | ||||
|  | ||||
| mixed_shape: tuple[int, np.int64] | ||||
|  | ||||
| def func(i: int, j: int, **kwargs: Any) -> SubClass[np.float64]: ... | ||||
|  | ||||
| assert_type(np.empty_like(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.empty_like(B), SubClass[np.float64]) | ||||
| assert_type(np.empty_like([1, 1.0]), npt.NDArray[Any]) | ||||
| assert_type(np.empty_like(A, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.empty_like(A, dtype='c16'), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.array(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.array(B), npt.NDArray[np.float64]) | ||||
| assert_type(np.array([1, 1.0]), npt.NDArray[Any]) | ||||
| assert_type(np.array(deque([1, 2, 3])), npt.NDArray[Any]) | ||||
| assert_type(np.array(A, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.array(A, dtype='c16'), npt.NDArray[Any]) | ||||
| assert_type(np.array(A, like=A), npt.NDArray[np.float64]) | ||||
| assert_type(np.array(A, subok=True), npt.NDArray[np.float64]) | ||||
| assert_type(np.array(B, subok=True), SubClass[np.float64]) | ||||
| assert_type(np.array(B, subok=True, ndmin=0), SubClass[np.float64]) | ||||
| assert_type(np.array(B, subok=True, ndmin=1), SubClass[np.float64]) | ||||
| assert_type(np.array(D), npt.NDArray[np.float64 | np.int64]) | ||||
| # https://github.com/numpy/numpy/issues/29245 | ||||
| assert_type(np.array([], dtype=np.bool), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.zeros([1, 5, 6]), npt.NDArray[np.float64]) | ||||
| assert_type(np.zeros([1, 5, 6], dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.zeros([1, 5, 6], dtype='c16'), npt.NDArray[Any]) | ||||
| assert_type(np.zeros(mixed_shape), npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(np.empty([1, 5, 6]), npt.NDArray[np.float64]) | ||||
| assert_type(np.empty([1, 5, 6], dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.empty([1, 5, 6], dtype='c16'), npt.NDArray[Any]) | ||||
| assert_type(np.empty(mixed_shape), npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(np.concatenate(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.concatenate([A, A]), Any)  # pyright correctly infers this as NDArray[float64] | ||||
| assert_type(np.concatenate([[1], A]), npt.NDArray[Any]) | ||||
| assert_type(np.concatenate([[1], [1]]), npt.NDArray[Any]) | ||||
| assert_type(np.concatenate((A, A)), npt.NDArray[np.float64]) | ||||
| assert_type(np.concatenate(([1], [1])), npt.NDArray[Any]) | ||||
| assert_type(np.concatenate([1, 1.0]), npt.NDArray[Any]) | ||||
| assert_type(np.concatenate(A, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.concatenate(A, dtype='c16'), npt.NDArray[Any]) | ||||
| assert_type(np.concatenate([1, 1.0], out=A), npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(np.asarray(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.asarray(B), npt.NDArray[np.float64]) | ||||
| assert_type(np.asarray([1, 1.0]), npt.NDArray[Any]) | ||||
| assert_type(np.asarray(A, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.asarray(A, dtype='c16'), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.asanyarray(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.asanyarray(B), SubClass[np.float64]) | ||||
| assert_type(np.asanyarray([1, 1.0]), npt.NDArray[Any]) | ||||
| assert_type(np.asanyarray(A, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.asanyarray(A, dtype='c16'), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.ascontiguousarray(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.ascontiguousarray(B), npt.NDArray[np.float64]) | ||||
| assert_type(np.ascontiguousarray([1, 1.0]), npt.NDArray[Any]) | ||||
| assert_type(np.ascontiguousarray(A, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.ascontiguousarray(A, dtype='c16'), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.asfortranarray(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.asfortranarray(B), npt.NDArray[np.float64]) | ||||
| assert_type(np.asfortranarray([1, 1.0]), npt.NDArray[Any]) | ||||
| assert_type(np.asfortranarray(A, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.asfortranarray(A, dtype='c16'), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.fromstring("1 1 1", sep=" "), npt.NDArray[np.float64]) | ||||
| assert_type(np.fromstring(b"1 1 1", sep=" "), npt.NDArray[np.float64]) | ||||
| assert_type(np.fromstring("1 1 1", dtype=np.int64, sep=" "), npt.NDArray[np.int64]) | ||||
| assert_type(np.fromstring(b"1 1 1", dtype=np.int64, sep=" "), npt.NDArray[np.int64]) | ||||
| assert_type(np.fromstring("1 1 1", dtype="c16", sep=" "), npt.NDArray[Any]) | ||||
| assert_type(np.fromstring(b"1 1 1", dtype="c16", sep=" "), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.fromfile("test.txt", sep=" "), npt.NDArray[np.float64]) | ||||
| assert_type(np.fromfile("test.txt", dtype=np.int64, sep=" "), npt.NDArray[np.int64]) | ||||
| assert_type(np.fromfile("test.txt", dtype="c16", sep=" "), npt.NDArray[Any]) | ||||
| with open("test.txt") as f: | ||||
|     assert_type(np.fromfile(f, sep=" "), npt.NDArray[np.float64]) | ||||
|     assert_type(np.fromfile(b"test.txt", sep=" "), npt.NDArray[np.float64]) | ||||
|     assert_type(np.fromfile(Path("test.txt"), sep=" "), npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(np.fromiter("12345", np.float64), npt.NDArray[np.float64]) | ||||
| assert_type(np.fromiter("12345", float), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.frombuffer(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.frombuffer(A, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.frombuffer(A, dtype="c16"), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.arange(False, True), np.ndarray[tuple[int], np.dtype[np.signedinteger]]) | ||||
| assert_type(np.arange(10), np.ndarray[tuple[int], np.dtype[np.signedinteger]]) | ||||
| assert_type(np.arange(0, 10, step=2), np.ndarray[tuple[int], np.dtype[np.signedinteger]]) | ||||
| assert_type(np.arange(10.0), np.ndarray[tuple[int], np.dtype[np.floating]]) | ||||
| assert_type(np.arange(start=0, stop=10.0), np.ndarray[tuple[int], np.dtype[np.floating]]) | ||||
| assert_type(np.arange(np.timedelta64(0)), np.ndarray[tuple[int], np.dtype[np.timedelta64]]) | ||||
| assert_type(np.arange(0, np.timedelta64(10)), np.ndarray[tuple[int], np.dtype[np.timedelta64]]) | ||||
| assert_type(np.arange(np.datetime64("0"), np.datetime64("10")), np.ndarray[tuple[int], np.dtype[np.datetime64]]) | ||||
| assert_type(np.arange(10, dtype=np.float64), np.ndarray[tuple[int], np.dtype[np.float64]]) | ||||
| assert_type(np.arange(0, 10, step=2, dtype=np.int16), np.ndarray[tuple[int], np.dtype[np.int16]]) | ||||
| assert_type(np.arange(10, dtype=int), np.ndarray[tuple[int], np.dtype]) | ||||
| assert_type(np.arange(0, 10, dtype="f8"), np.ndarray[tuple[int], np.dtype]) | ||||
|  | ||||
| assert_type(np.require(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.require(B), SubClass[np.float64]) | ||||
| assert_type(np.require(B, requirements=None), SubClass[np.float64]) | ||||
| assert_type(np.require(B, dtype=int), npt.NDArray[Any]) | ||||
| assert_type(np.require(B, requirements="E"), npt.NDArray[Any]) | ||||
| assert_type(np.require(B, requirements=["ENSUREARRAY"]), npt.NDArray[Any]) | ||||
| assert_type(np.require(B, requirements={"F", "E"}), npt.NDArray[Any]) | ||||
| assert_type(np.require(B, requirements=["C", "OWNDATA"]), SubClass[np.float64]) | ||||
| assert_type(np.require(B, requirements="W"), SubClass[np.float64]) | ||||
| assert_type(np.require(B, requirements="A"), SubClass[np.float64]) | ||||
| assert_type(np.require(C), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.linspace(0, 10), npt.NDArray[np.float64]) | ||||
| assert_type(np.linspace(0, 10j), npt.NDArray[np.complexfloating]) | ||||
| assert_type(np.linspace(0, 10, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.linspace(0, 10, dtype=int), npt.NDArray[Any]) | ||||
| assert_type(np.linspace(0, 10, retstep=True), tuple[npt.NDArray[np.float64], np.float64]) | ||||
| assert_type(np.linspace(0j, 10, retstep=True), tuple[npt.NDArray[np.complexfloating], np.complexfloating]) | ||||
| assert_type(np.linspace(0, 10, retstep=True, dtype=np.int64), tuple[npt.NDArray[np.int64], np.int64]) | ||||
| assert_type(np.linspace(0j, 10, retstep=True, dtype=int), tuple[npt.NDArray[Any], Any]) | ||||
|  | ||||
| assert_type(np.logspace(0, 10), npt.NDArray[np.float64]) | ||||
| assert_type(np.logspace(0, 10j), npt.NDArray[np.complexfloating]) | ||||
| assert_type(np.logspace(0, 10, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.logspace(0, 10, dtype=int), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.geomspace(0, 10), npt.NDArray[np.float64]) | ||||
| assert_type(np.geomspace(0, 10j), npt.NDArray[np.complexfloating]) | ||||
| assert_type(np.geomspace(0, 10, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.geomspace(0, 10, dtype=int), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.zeros_like(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.zeros_like(C), npt.NDArray[Any]) | ||||
| assert_type(np.zeros_like(A, dtype=float), npt.NDArray[Any]) | ||||
| assert_type(np.zeros_like(B), SubClass[np.float64]) | ||||
| assert_type(np.zeros_like(B, dtype=np.int64), npt.NDArray[np.int64]) | ||||
|  | ||||
| assert_type(np.ones_like(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.ones_like(C), npt.NDArray[Any]) | ||||
| assert_type(np.ones_like(A, dtype=float), npt.NDArray[Any]) | ||||
| assert_type(np.ones_like(B), SubClass[np.float64]) | ||||
| assert_type(np.ones_like(B, dtype=np.int64), npt.NDArray[np.int64]) | ||||
|  | ||||
| assert_type(np.full_like(A, i8), npt.NDArray[np.float64]) | ||||
| assert_type(np.full_like(C, i8), npt.NDArray[Any]) | ||||
| assert_type(np.full_like(A, i8, dtype=int), npt.NDArray[Any]) | ||||
| assert_type(np.full_like(B, i8), SubClass[np.float64]) | ||||
| assert_type(np.full_like(B, i8, dtype=np.int64), npt.NDArray[np.int64]) | ||||
|  | ||||
| _size: int | ||||
| _shape_0d: tuple[()] | ||||
| _shape_1d: tuple[int] | ||||
| _shape_2d: tuple[int, int] | ||||
| _shape_nd: tuple[int, ...] | ||||
| _shape_like: list[int] | ||||
|  | ||||
| assert_type(np.ones(_shape_0d), np.ndarray[tuple[()], np.dtype[np.float64]]) | ||||
| assert_type(np.ones(_size), np.ndarray[tuple[int], np.dtype[np.float64]]) | ||||
| assert_type(np.ones(_shape_2d), np.ndarray[tuple[int, int], np.dtype[np.float64]]) | ||||
| assert_type(np.ones(_shape_nd), np.ndarray[tuple[int, ...], np.dtype[np.float64]]) | ||||
| assert_type(np.ones(_shape_1d, dtype=np.int64), np.ndarray[tuple[int], np.dtype[np.int64]]) | ||||
| assert_type(np.ones(_shape_like), npt.NDArray[np.float64]) | ||||
| assert_type(np.ones(_shape_like, dtype=np.dtypes.Int64DType()), np.ndarray[Any, np.dtypes.Int64DType]) | ||||
| assert_type(np.ones(_shape_like, dtype=int), npt.NDArray[Any]) | ||||
| assert_type(np.ones(mixed_shape), npt.NDArray[np.float64]) | ||||
|  | ||||
| assert_type(np.full(_size, i8), np.ndarray[tuple[int], np.dtype[np.int64]]) | ||||
| assert_type(np.full(_shape_2d, i8), np.ndarray[tuple[int, int], np.dtype[np.int64]]) | ||||
| assert_type(np.full(_shape_like, i8), npt.NDArray[np.int64]) | ||||
| assert_type(np.full(_shape_like, 42), npt.NDArray[Any]) | ||||
| assert_type(np.full(_size, i8, dtype=np.float64), np.ndarray[tuple[int], np.dtype[np.float64]]) | ||||
| assert_type(np.full(_size, i8, dtype=float), np.ndarray[tuple[int], np.dtype]) | ||||
| assert_type(np.full(_shape_like, 42, dtype=float), npt.NDArray[Any]) | ||||
| assert_type(np.full(_shape_0d, i8, dtype=object), np.ndarray[tuple[()], np.dtype]) | ||||
|  | ||||
| assert_type(np.indices([1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(np.indices([1, 2, 3], sparse=True), tuple[npt.NDArray[np.int_], ...]) | ||||
|  | ||||
| assert_type(np.fromfunction(func, (3, 5)), SubClass[np.float64]) | ||||
|  | ||||
| assert_type(np.identity(10), npt.NDArray[np.float64]) | ||||
| assert_type(np.identity(10, dtype=np.int64), npt.NDArray[np.int64]) | ||||
| assert_type(np.identity(10, dtype=int), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.atleast_1d(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.atleast_1d(C), npt.NDArray[Any]) | ||||
| assert_type(np.atleast_1d(A, A), tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]) | ||||
| assert_type(np.atleast_1d(A, C), tuple[npt.NDArray[Any], npt.NDArray[Any]]) | ||||
| assert_type(np.atleast_1d(C, C), tuple[npt.NDArray[Any], npt.NDArray[Any]]) | ||||
| assert_type(np.atleast_1d(A, A, A), tuple[npt.NDArray[np.float64], ...]) | ||||
| assert_type(np.atleast_1d(C, C, C), tuple[npt.NDArray[Any], ...]) | ||||
|  | ||||
| assert_type(np.atleast_2d(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.atleast_2d(A, A), tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]) | ||||
| assert_type(np.atleast_2d(A, A, A), tuple[npt.NDArray[np.float64], ...]) | ||||
|  | ||||
| assert_type(np.atleast_3d(A), npt.NDArray[np.float64]) | ||||
| assert_type(np.atleast_3d(A, A), tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]) | ||||
| assert_type(np.atleast_3d(A, A, A), tuple[npt.NDArray[np.float64], ...]) | ||||
|  | ||||
| assert_type(np.vstack([A, A]), np.ndarray[Any, Any])  # pyright correctly infers this as NDArray[float64] | ||||
| assert_type(np.vstack([A, A], dtype=np.float32), npt.NDArray[np.float32]) | ||||
| assert_type(np.vstack([A, C]), npt.NDArray[Any]) | ||||
| assert_type(np.vstack([C, C]), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.hstack([A, A]), np.ndarray[Any, Any])  # pyright correctly infers this as NDArray[float64] | ||||
| assert_type(np.hstack([A, A], dtype=np.float32), npt.NDArray[np.float32]) | ||||
|  | ||||
| assert_type(np.stack([A, A]), np.ndarray[Any, Any])  # pyright correctly infers this as NDArray[float64] | ||||
| assert_type(np.stack([A, A], dtype=np.float32), npt.NDArray[np.float32]) | ||||
| assert_type(np.stack([A, C]), npt.NDArray[Any]) | ||||
| assert_type(np.stack([C, C]), npt.NDArray[Any]) | ||||
| assert_type(np.stack([A, A], axis=0), np.ndarray[Any, Any])  # pyright correctly infers this as NDArray[float64] | ||||
| assert_type(np.stack([A, A], out=B), SubClass[np.float64]) | ||||
|  | ||||
| assert_type(np.block([[A, A], [A, A]]), npt.NDArray[Any])  # pyright correctly infers this as NDArray[float64] | ||||
| assert_type(np.block(C), npt.NDArray[Any]) | ||||
|  | ||||
| if sys.version_info >= (3, 12): | ||||
|     from collections.abc import Buffer | ||||
|  | ||||
|     def create_array(obj: npt.ArrayLike) -> npt.NDArray[Any]: ... | ||||
|  | ||||
|     buffer: Buffer | ||||
|     assert_type(create_array(buffer), npt.NDArray[Any]) | ||||
| @ -0,0 +1,22 @@ | ||||
| from collections.abc import Mapping | ||||
| from typing import Any, SupportsIndex, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| def mode_func( | ||||
|     ar: npt.NDArray[np.number], | ||||
|     width: tuple[int, int], | ||||
|     iaxis: SupportsIndex, | ||||
|     kwargs: Mapping[str, Any], | ||||
| ) -> None: ... | ||||
|  | ||||
| AR_i8: npt.NDArray[np.int64] | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
| AR_LIKE: list[int] | ||||
|  | ||||
| assert_type(np.pad(AR_i8, (2, 3), "constant"), npt.NDArray[np.int64]) | ||||
| assert_type(np.pad(AR_LIKE, (2, 3), "constant"), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.pad(AR_f8, (2, 3), mode_func), npt.NDArray[np.float64]) | ||||
| assert_type(np.pad(AR_f8, (2, 3), mode_func, a=1, b=2), npt.NDArray[np.float64]) | ||||
| @ -0,0 +1,25 @@ | ||||
| import contextlib | ||||
| from collections.abc import Callable | ||||
| from typing import Any, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| from numpy._core.arrayprint import _FormatOptions | ||||
|  | ||||
| AR: npt.NDArray[np.int64] | ||||
| func_float: Callable[[np.floating], str] | ||||
| func_int: Callable[[np.integer], str] | ||||
|  | ||||
| assert_type(np.get_printoptions(), _FormatOptions) | ||||
| assert_type( | ||||
|     np.array2string(AR, formatter={'float_kind': func_float, 'int_kind': func_int}), | ||||
|     str, | ||||
| ) | ||||
| assert_type(np.format_float_scientific(1.0), str) | ||||
| assert_type(np.format_float_positional(1), str) | ||||
| assert_type(np.array_repr(AR), str) | ||||
| assert_type(np.array_str(AR), str) | ||||
|  | ||||
| assert_type(np.printoptions(), contextlib._GeneratorContextManager[_FormatOptions]) | ||||
| with np.printoptions() as dct: | ||||
|     assert_type(dct, _FormatOptions) | ||||
| @ -0,0 +1,74 @@ | ||||
| from typing import Any, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| from numpy.lib._arraysetops_impl import ( | ||||
|     UniqueAllResult, | ||||
|     UniqueCountsResult, | ||||
|     UniqueInverseResult, | ||||
| ) | ||||
|  | ||||
| AR_b: npt.NDArray[np.bool] | ||||
| AR_i8: npt.NDArray[np.int64] | ||||
| AR_f8: npt.NDArray[np.float64] | ||||
| AR_M: npt.NDArray[np.datetime64] | ||||
| AR_O: npt.NDArray[np.object_] | ||||
|  | ||||
| AR_LIKE_f8: list[float] | ||||
|  | ||||
| assert_type(np.ediff1d(AR_b), npt.NDArray[np.int8]) | ||||
| assert_type(np.ediff1d(AR_i8, to_end=[1, 2, 3]), npt.NDArray[np.int64]) | ||||
| assert_type(np.ediff1d(AR_M), npt.NDArray[np.timedelta64]) | ||||
| assert_type(np.ediff1d(AR_O), npt.NDArray[np.object_]) | ||||
| assert_type(np.ediff1d(AR_LIKE_f8, to_begin=[1, 1.5]), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.intersect1d(AR_i8, AR_i8), npt.NDArray[np.int64]) | ||||
| assert_type(np.intersect1d(AR_M, AR_M, assume_unique=True), npt.NDArray[np.datetime64]) | ||||
| assert_type(np.intersect1d(AR_f8, AR_i8), npt.NDArray[Any]) | ||||
| assert_type( | ||||
|     np.intersect1d(AR_f8, AR_f8, return_indices=True), | ||||
|     tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp]], | ||||
| ) | ||||
|  | ||||
| assert_type(np.setxor1d(AR_i8, AR_i8), npt.NDArray[np.int64]) | ||||
| assert_type(np.setxor1d(AR_M, AR_M, assume_unique=True), npt.NDArray[np.datetime64]) | ||||
| assert_type(np.setxor1d(AR_f8, AR_i8), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.isin(AR_i8, AR_i8), npt.NDArray[np.bool]) | ||||
| assert_type(np.isin(AR_M, AR_M, assume_unique=True), npt.NDArray[np.bool]) | ||||
| assert_type(np.isin(AR_f8, AR_i8), npt.NDArray[np.bool]) | ||||
| assert_type(np.isin(AR_f8, AR_LIKE_f8, invert=True), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.union1d(AR_i8, AR_i8), npt.NDArray[np.int64]) | ||||
| assert_type(np.union1d(AR_M, AR_M), npt.NDArray[np.datetime64]) | ||||
| assert_type(np.union1d(AR_f8, AR_i8), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.setdiff1d(AR_i8, AR_i8), npt.NDArray[np.int64]) | ||||
| assert_type(np.setdiff1d(AR_M, AR_M, assume_unique=True), npt.NDArray[np.datetime64]) | ||||
| assert_type(np.setdiff1d(AR_f8, AR_i8), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.unique(AR_f8), npt.NDArray[np.float64]) | ||||
| assert_type(np.unique(AR_LIKE_f8, axis=0), npt.NDArray[Any]) | ||||
| assert_type(np.unique(AR_f8, return_index=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_LIKE_f8, return_index=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_f8, return_inverse=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_LIKE_f8, return_inverse=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_f8, return_counts=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_LIKE_f8, return_counts=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_f8, return_index=True, return_inverse=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_LIKE_f8, return_index=True, return_inverse=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_f8, return_index=True, return_counts=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_LIKE_f8, return_index=True, return_counts=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_f8, return_inverse=True, return_counts=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_LIKE_f8, return_inverse=True, return_counts=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_f8, return_index=True, return_inverse=True, return_counts=True), tuple[npt.NDArray[np.float64], npt.NDArray[np.intp], npt.NDArray[np.intp], npt.NDArray[np.intp]]) | ||||
| assert_type(np.unique(AR_LIKE_f8, return_index=True, return_inverse=True, return_counts=True), tuple[npt.NDArray[Any], npt.NDArray[np.intp], npt.NDArray[np.intp], npt.NDArray[np.intp]]) | ||||
|  | ||||
| assert_type(np.unique_all(AR_f8), UniqueAllResult[np.float64]) | ||||
| assert_type(np.unique_all(AR_LIKE_f8), UniqueAllResult[Any]) | ||||
| assert_type(np.unique_counts(AR_f8), UniqueCountsResult[np.float64]) | ||||
| assert_type(np.unique_counts(AR_LIKE_f8), UniqueCountsResult[Any]) | ||||
| assert_type(np.unique_inverse(AR_f8), UniqueInverseResult[np.float64]) | ||||
| assert_type(np.unique_inverse(AR_LIKE_f8), UniqueInverseResult[Any]) | ||||
| assert_type(np.unique_values(AR_f8), npt.NDArray[np.float64]) | ||||
| assert_type(np.unique_values(AR_LIKE_f8), npt.NDArray[Any]) | ||||
| @ -0,0 +1,27 @@ | ||||
| from collections.abc import Generator | ||||
| from typing import Any, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_i8: npt.NDArray[np.int64] | ||||
| ar_iter = np.lib.Arrayterator(AR_i8) | ||||
|  | ||||
| assert_type(ar_iter.var, npt.NDArray[np.int64]) | ||||
| assert_type(ar_iter.buf_size, int | None) | ||||
| assert_type(ar_iter.start, list[int]) | ||||
| assert_type(ar_iter.stop, list[int]) | ||||
| assert_type(ar_iter.step, list[int]) | ||||
| assert_type(ar_iter.shape, tuple[Any, ...]) | ||||
| assert_type(ar_iter.flat, Generator[np.int64, None, None]) | ||||
|  | ||||
| assert_type(ar_iter.__array__(), npt.NDArray[np.int64]) | ||||
|  | ||||
| for i in ar_iter: | ||||
|     assert_type(i, npt.NDArray[np.int64]) | ||||
|  | ||||
| assert_type(ar_iter[0], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]]) | ||||
| assert_type(ar_iter[...], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]]) | ||||
| assert_type(ar_iter[:], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]]) | ||||
| assert_type(ar_iter[0, 0, 0], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]]) | ||||
| assert_type(ar_iter[..., 0, :], np.lib.Arrayterator[tuple[Any, ...], np.dtype[np.int64]]) | ||||
| @ -0,0 +1,168 @@ | ||||
| from typing import Any, TypeAlias, assert_type | ||||
| from typing import Literal as L | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| from numpy._typing import _32Bit, _64Bit | ||||
|  | ||||
| FalseType: TypeAlias = L[False] | ||||
| TrueType: TypeAlias = L[True] | ||||
|  | ||||
| i4: np.int32 | ||||
| i8: np.int64 | ||||
|  | ||||
| u4: np.uint32 | ||||
| u8: np.uint64 | ||||
|  | ||||
| b_: np.bool[bool] | ||||
| b0_: np.bool[FalseType] | ||||
| b1_: np.bool[TrueType] | ||||
|  | ||||
| b: bool | ||||
| b0: FalseType | ||||
| b1: TrueType | ||||
|  | ||||
| i: int | ||||
|  | ||||
| AR: npt.NDArray[np.int32] | ||||
|  | ||||
| assert_type(i8 << i8, np.int64) | ||||
| assert_type(i8 >> i8, np.int64) | ||||
| assert_type(i8 | i8, np.int64) | ||||
| assert_type(i8 ^ i8, np.int64) | ||||
| assert_type(i8 & i8, np.int64) | ||||
|  | ||||
| assert_type(i8 << AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(i8 >> AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(i8 | AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(i8 ^ AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(i8 & AR, npt.NDArray[np.signedinteger]) | ||||
|  | ||||
| assert_type(i4 << i4, np.int32) | ||||
| assert_type(i4 >> i4, np.int32) | ||||
| assert_type(i4 | i4, np.int32) | ||||
| assert_type(i4 ^ i4, np.int32) | ||||
| assert_type(i4 & i4, np.int32) | ||||
|  | ||||
| assert_type(i8 << i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) | ||||
| assert_type(i8 >> i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) | ||||
| assert_type(i8 | i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) | ||||
| assert_type(i8 ^ i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) | ||||
| assert_type(i8 & i4, np.signedinteger[_32Bit] | np.signedinteger[_64Bit]) | ||||
|  | ||||
| assert_type(i8 << b_, np.int64) | ||||
| assert_type(i8 >> b_, np.int64) | ||||
| assert_type(i8 | b_, np.int64) | ||||
| assert_type(i8 ^ b_, np.int64) | ||||
| assert_type(i8 & b_, np.int64) | ||||
|  | ||||
| assert_type(i8 << b, np.int64) | ||||
| assert_type(i8 >> b, np.int64) | ||||
| assert_type(i8 | b, np.int64) | ||||
| assert_type(i8 ^ b, np.int64) | ||||
| assert_type(i8 & b, np.int64) | ||||
|  | ||||
| assert_type(u8 << u8, np.uint64) | ||||
| assert_type(u8 >> u8, np.uint64) | ||||
| assert_type(u8 | u8, np.uint64) | ||||
| assert_type(u8 ^ u8, np.uint64) | ||||
| assert_type(u8 & u8, np.uint64) | ||||
|  | ||||
| assert_type(u8 << AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(u8 >> AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(u8 | AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(u8 ^ AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(u8 & AR, npt.NDArray[np.signedinteger]) | ||||
|  | ||||
| assert_type(u4 << u4, np.uint32) | ||||
| assert_type(u4 >> u4, np.uint32) | ||||
| assert_type(u4 | u4, np.uint32) | ||||
| assert_type(u4 ^ u4, np.uint32) | ||||
| assert_type(u4 & u4, np.uint32) | ||||
|  | ||||
| assert_type(u4 << i4, np.signedinteger) | ||||
| assert_type(u4 >> i4, np.signedinteger) | ||||
| assert_type(u4 | i4, np.signedinteger) | ||||
| assert_type(u4 ^ i4, np.signedinteger) | ||||
| assert_type(u4 & i4, np.signedinteger) | ||||
|  | ||||
| assert_type(u4 << i, np.signedinteger) | ||||
| assert_type(u4 >> i, np.signedinteger) | ||||
| assert_type(u4 | i, np.signedinteger) | ||||
| assert_type(u4 ^ i, np.signedinteger) | ||||
| assert_type(u4 & i, np.signedinteger) | ||||
|  | ||||
| assert_type(u8 << b_, np.uint64) | ||||
| assert_type(u8 >> b_, np.uint64) | ||||
| assert_type(u8 | b_, np.uint64) | ||||
| assert_type(u8 ^ b_, np.uint64) | ||||
| assert_type(u8 & b_, np.uint64) | ||||
|  | ||||
| assert_type(u8 << b, np.uint64) | ||||
| assert_type(u8 >> b, np.uint64) | ||||
| assert_type(u8 | b, np.uint64) | ||||
| assert_type(u8 ^ b, np.uint64) | ||||
| assert_type(u8 & b, np.uint64) | ||||
|  | ||||
| assert_type(b_ << b_, np.int8) | ||||
| assert_type(b_ >> b_, np.int8) | ||||
| assert_type(b_ | b_, np.bool) | ||||
| assert_type(b_ ^ b_, np.bool) | ||||
| assert_type(b_ & b_, np.bool) | ||||
|  | ||||
| assert_type(b_ << AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(b_ >> AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(b_ | AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(b_ ^ AR, npt.NDArray[np.signedinteger]) | ||||
| assert_type(b_ & AR, npt.NDArray[np.signedinteger]) | ||||
|  | ||||
| assert_type(b_ << b, np.int8) | ||||
| assert_type(b_ >> b, np.int8) | ||||
| assert_type(b_ | b, np.bool) | ||||
| assert_type(b_ ^ b, np.bool) | ||||
| assert_type(b_ & b, np.bool) | ||||
|  | ||||
| assert_type(b_ << i, np.int_) | ||||
| assert_type(b_ >> i, np.int_) | ||||
| assert_type(b_ | i, np.bool | np.int_) | ||||
| assert_type(b_ ^ i, np.bool | np.int_) | ||||
| assert_type(b_ & i, np.bool | np.int_) | ||||
|  | ||||
| assert_type(~i8, np.int64) | ||||
| assert_type(~i4, np.int32) | ||||
| assert_type(~u8, np.uint64) | ||||
| assert_type(~u4, np.uint32) | ||||
| assert_type(~b_, np.bool) | ||||
| assert_type(~b0_, np.bool[TrueType]) | ||||
| assert_type(~b1_, np.bool[FalseType]) | ||||
| assert_type(~AR, npt.NDArray[np.int32]) | ||||
|  | ||||
| assert_type(b_ | b0_, np.bool) | ||||
| assert_type(b0_ | b_, np.bool) | ||||
| assert_type(b_ | b1_, np.bool[TrueType]) | ||||
| assert_type(b1_ | b_, np.bool[TrueType]) | ||||
|  | ||||
| assert_type(b_ ^ b0_, np.bool) | ||||
| assert_type(b0_ ^ b_, np.bool) | ||||
| assert_type(b_ ^ b1_, np.bool) | ||||
| assert_type(b1_ ^ b_, np.bool) | ||||
|  | ||||
| assert_type(b_ & b0_, np.bool[FalseType]) | ||||
| assert_type(b0_ & b_, np.bool[FalseType]) | ||||
| assert_type(b_ & b1_, np.bool) | ||||
| assert_type(b1_ & b_, np.bool) | ||||
|  | ||||
| assert_type(b0_ | b0_, np.bool[FalseType]) | ||||
| assert_type(b0_ | b1_, np.bool[TrueType]) | ||||
| assert_type(b1_ | b0_, np.bool[TrueType]) | ||||
| assert_type(b1_ | b1_, np.bool[TrueType]) | ||||
|  | ||||
| assert_type(b0_ ^ b0_, np.bool[FalseType]) | ||||
| assert_type(b0_ ^ b1_, np.bool[TrueType]) | ||||
| assert_type(b1_ ^ b0_, np.bool[TrueType]) | ||||
| assert_type(b1_ ^ b1_, np.bool[FalseType]) | ||||
|  | ||||
| assert_type(b0_ & b0_, np.bool[FalseType]) | ||||
| assert_type(b0_ & b1_, np.bool[FalseType]) | ||||
| assert_type(b1_ & b0_, np.bool[FalseType]) | ||||
| assert_type(b1_ & b1_, np.bool[TrueType]) | ||||
| @ -0,0 +1,224 @@ | ||||
| from typing import TypeAlias, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy._typing as np_t | ||||
| import numpy.typing as npt | ||||
|  | ||||
| AR_T_alias: TypeAlias = np.ndarray[np_t._AnyShape, np.dtypes.StringDType] | ||||
| AR_TU_alias: TypeAlias = AR_T_alias | npt.NDArray[np.str_] | ||||
|  | ||||
| AR_U: npt.NDArray[np.str_] | ||||
| AR_S: npt.NDArray[np.bytes_] | ||||
| AR_T: AR_T_alias | ||||
|  | ||||
| assert_type(np.char.equal(AR_U, AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.equal(AR_S, AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.equal(AR_T, AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.not_equal(AR_U, AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.not_equal(AR_S, AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.not_equal(AR_T, AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.greater_equal(AR_U, AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.greater_equal(AR_S, AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.greater_equal(AR_T, AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.less_equal(AR_U, AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.less_equal(AR_S, AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.less_equal(AR_T, AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.greater(AR_U, AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.greater(AR_S, AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.greater(AR_T, AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.less(AR_U, AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.less(AR_S, AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.less(AR_T, AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.multiply(AR_U, 5), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.multiply(AR_S, [5, 4, 3]), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.multiply(AR_T, 5), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.mod(AR_U, "test"), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.mod(AR_S, "test"), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.mod(AR_T, "test"), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.capitalize(AR_U), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.capitalize(AR_S), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.capitalize(AR_T), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.center(AR_U, 5), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.center(AR_S, [2, 3, 4], b"a"), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.center(AR_T, 5), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.encode(AR_U), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.encode(AR_T), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.decode(AR_S), npt.NDArray[np.str_]) | ||||
|  | ||||
| assert_type(np.char.expandtabs(AR_U), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.expandtabs(AR_S, tabsize=4), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.expandtabs(AR_T), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.join(AR_U, "_"), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.join(AR_S, [b"_", b""]), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.join(AR_T, "_"), AR_TU_alias) | ||||
|  | ||||
| assert_type(np.char.ljust(AR_U, 5), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.ljust(AR_S, [4, 3, 1], fillchar=[b"a", b"b", b"c"]), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.ljust(AR_T, 5), AR_T_alias) | ||||
| assert_type(np.char.ljust(AR_T, [4, 2, 1], fillchar=["a", "b", "c"]), AR_TU_alias) | ||||
|  | ||||
| assert_type(np.char.rjust(AR_U, 5), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.rjust(AR_S, [4, 3, 1], fillchar=[b"a", b"b", b"c"]), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.rjust(AR_T, 5), AR_T_alias) | ||||
| assert_type(np.char.rjust(AR_T, [4, 2, 1], fillchar=["a", "b", "c"]), AR_TU_alias) | ||||
|  | ||||
| assert_type(np.char.lstrip(AR_U), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.lstrip(AR_S, b"_"), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.lstrip(AR_T), AR_T_alias) | ||||
| assert_type(np.char.lstrip(AR_T, "_"), AR_TU_alias) | ||||
|  | ||||
| assert_type(np.char.rstrip(AR_U), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.rstrip(AR_S, b"_"), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.rstrip(AR_T), AR_T_alias) | ||||
| assert_type(np.char.rstrip(AR_T, "_"), AR_TU_alias) | ||||
|  | ||||
| assert_type(np.char.strip(AR_U), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.strip(AR_S, b"_"), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.strip(AR_T), AR_T_alias) | ||||
| assert_type(np.char.strip(AR_T, "_"), AR_TU_alias) | ||||
|  | ||||
| assert_type(np.char.count(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.count(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.count(AR_T, AR_T, start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.count(AR_T, ["a", "b", "c"], end=9), npt.NDArray[np.int_]) | ||||
|  | ||||
| assert_type(np.char.partition(AR_U, "\n"), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.partition(AR_S, [b"a", b"b", b"c"]), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.partition(AR_T, "\n"), AR_TU_alias) | ||||
|  | ||||
| assert_type(np.char.rpartition(AR_U, "\n"), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.rpartition(AR_S, [b"a", b"b", b"c"]), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.rpartition(AR_T, "\n"), AR_TU_alias) | ||||
|  | ||||
| assert_type(np.char.replace(AR_U, "_", "-"), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.replace(AR_S, [b"_", b""], [b"a", b"b"]), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.replace(AR_T, "_", "_"), AR_TU_alias) | ||||
|  | ||||
| assert_type(np.char.split(AR_U, "_"), npt.NDArray[np.object_]) | ||||
| assert_type(np.char.split(AR_S, maxsplit=[1, 2, 3]), npt.NDArray[np.object_]) | ||||
| assert_type(np.char.split(AR_T, "_"), npt.NDArray[np.object_]) | ||||
|  | ||||
| assert_type(np.char.rsplit(AR_U, "_"), npt.NDArray[np.object_]) | ||||
| assert_type(np.char.rsplit(AR_S, maxsplit=[1, 2, 3]), npt.NDArray[np.object_]) | ||||
| assert_type(np.char.rsplit(AR_T, "_"), npt.NDArray[np.object_]) | ||||
|  | ||||
| assert_type(np.char.splitlines(AR_U), npt.NDArray[np.object_]) | ||||
| assert_type(np.char.splitlines(AR_S, keepends=[True, True, False]), npt.NDArray[np.object_]) | ||||
| assert_type(np.char.splitlines(AR_T), npt.NDArray[np.object_]) | ||||
|  | ||||
| assert_type(np.char.lower(AR_U), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.lower(AR_S), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.lower(AR_T), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.upper(AR_U), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.upper(AR_S), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.upper(AR_T), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.swapcase(AR_U), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.swapcase(AR_S), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.swapcase(AR_T), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.title(AR_U), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.title(AR_S), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.title(AR_T), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.zfill(AR_U, 5), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.zfill(AR_S, [2, 3, 4]), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.zfill(AR_T, 5), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.endswith(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.endswith(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.endswith(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.startswith(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.startswith(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.startswith(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.find(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.find(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.find(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
|  | ||||
| assert_type(np.char.rfind(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.rfind(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.rfind(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
|  | ||||
| assert_type(np.char.index(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.index(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.index(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
|  | ||||
| assert_type(np.char.rindex(AR_U, "a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.rindex(AR_S, [b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.rindex(AR_T, "a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
|  | ||||
| assert_type(np.char.isalpha(AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isalpha(AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isalpha(AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.isalnum(AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isalnum(AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isalnum(AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.isdecimal(AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isdecimal(AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.isdigit(AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isdigit(AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isdigit(AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.islower(AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.islower(AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.islower(AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.isnumeric(AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isnumeric(AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.isspace(AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isspace(AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isspace(AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.istitle(AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.istitle(AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.istitle(AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.isupper(AR_U), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isupper(AR_S), npt.NDArray[np.bool]) | ||||
| assert_type(np.char.isupper(AR_T), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(np.char.str_len(AR_U), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.str_len(AR_S), npt.NDArray[np.int_]) | ||||
| assert_type(np.char.str_len(AR_T), npt.NDArray[np.int_]) | ||||
|  | ||||
| assert_type(np.char.translate(AR_U, ""), npt.NDArray[np.str_]) | ||||
| assert_type(np.char.translate(AR_S, ""), npt.NDArray[np.bytes_]) | ||||
| assert_type(np.char.translate(AR_T, ""), AR_T_alias) | ||||
|  | ||||
| assert_type(np.char.array(AR_U), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]]) | ||||
| assert_type(np.char.array(AR_S, order="K"), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.array("bob", copy=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]]) | ||||
| assert_type(np.char.array(b"bob", itemsize=5), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.array(1, unicode=False), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.array(1, unicode=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]]) | ||||
| assert_type(np.char.array(1), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]] | np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.array(AR_U, unicode=False), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.array(AR_S, unicode=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]]) | ||||
|  | ||||
| assert_type(np.char.asarray(AR_U), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]]) | ||||
| assert_type(np.char.asarray(AR_S, order="K"), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.asarray("bob"), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]]) | ||||
| assert_type(np.char.asarray(b"bob", itemsize=5), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.asarray(1, unicode=False), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.asarray(1, unicode=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]]) | ||||
| assert_type(np.char.asarray(1), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]] | np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.asarray(AR_U, unicode=False), np.char.chararray[np_t._AnyShape, np.dtype[np.bytes_]]) | ||||
| assert_type(np.char.asarray(AR_S, unicode=True), np.char.chararray[np_t._AnyShape, np.dtype[np.str_]]) | ||||
| @ -0,0 +1,137 @@ | ||||
| from typing import Any, TypeAlias, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| _BytesCharArray: TypeAlias = np.char.chararray[tuple[Any, ...], np.dtype[np.bytes_]] | ||||
| _StrCharArray: TypeAlias = np.char.chararray[tuple[Any, ...], np.dtype[np.str_]] | ||||
|  | ||||
| AR_U: _StrCharArray | ||||
| AR_S: _BytesCharArray | ||||
|  | ||||
| assert_type(AR_U == AR_U, npt.NDArray[np.bool]) | ||||
| assert_type(AR_S == AR_S, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U != AR_U, npt.NDArray[np.bool]) | ||||
| assert_type(AR_S != AR_S, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U >= AR_U, npt.NDArray[np.bool]) | ||||
| assert_type(AR_S >= AR_S, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U <= AR_U, npt.NDArray[np.bool]) | ||||
| assert_type(AR_S <= AR_S, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U > AR_U, npt.NDArray[np.bool]) | ||||
| assert_type(AR_S > AR_S, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U < AR_U, npt.NDArray[np.bool]) | ||||
| assert_type(AR_S < AR_S, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U * 5, _StrCharArray) | ||||
| assert_type(AR_S * [5], _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U % "test", _StrCharArray) | ||||
| assert_type(AR_S % b"test", _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.capitalize(), _StrCharArray) | ||||
| assert_type(AR_S.capitalize(), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.center(5), _StrCharArray) | ||||
| assert_type(AR_S.center([2, 3, 4], b"a"), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.encode(), _BytesCharArray) | ||||
| assert_type(AR_S.decode(), _StrCharArray) | ||||
|  | ||||
| assert_type(AR_U.expandtabs(), _StrCharArray) | ||||
| assert_type(AR_S.expandtabs(tabsize=4), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.join("_"), _StrCharArray) | ||||
| assert_type(AR_S.join([b"_", b""]), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.ljust(5), _StrCharArray) | ||||
| assert_type(AR_S.ljust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), _BytesCharArray) | ||||
| assert_type(AR_U.rjust(5), _StrCharArray) | ||||
| assert_type(AR_S.rjust([4, 3, 1], fillchar=[b"a", b"b", b"c"]), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.lstrip(), _StrCharArray) | ||||
| assert_type(AR_S.lstrip(chars=b"_"), _BytesCharArray) | ||||
| assert_type(AR_U.rstrip(), _StrCharArray) | ||||
| assert_type(AR_S.rstrip(chars=b"_"), _BytesCharArray) | ||||
| assert_type(AR_U.strip(), _StrCharArray) | ||||
| assert_type(AR_S.strip(chars=b"_"), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.partition("\n"), _StrCharArray) | ||||
| assert_type(AR_S.partition([b"a", b"b", b"c"]), _BytesCharArray) | ||||
| assert_type(AR_U.rpartition("\n"), _StrCharArray) | ||||
| assert_type(AR_S.rpartition([b"a", b"b", b"c"]), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.replace("_", "-"), _StrCharArray) | ||||
| assert_type(AR_S.replace([b"_", b""], [b"a", b"b"]), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.split("_"), npt.NDArray[np.object_]) | ||||
| assert_type(AR_S.split(maxsplit=[1, 2, 3]), npt.NDArray[np.object_]) | ||||
| assert_type(AR_U.rsplit("_"), npt.NDArray[np.object_]) | ||||
| assert_type(AR_S.rsplit(maxsplit=[1, 2, 3]), npt.NDArray[np.object_]) | ||||
|  | ||||
| assert_type(AR_U.splitlines(), npt.NDArray[np.object_]) | ||||
| assert_type(AR_S.splitlines(keepends=[True, True, False]), npt.NDArray[np.object_]) | ||||
|  | ||||
| assert_type(AR_U.swapcase(), _StrCharArray) | ||||
| assert_type(AR_S.swapcase(), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.title(), _StrCharArray) | ||||
| assert_type(AR_S.title(), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.upper(), _StrCharArray) | ||||
| assert_type(AR_S.upper(), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.zfill(5), _StrCharArray) | ||||
| assert_type(AR_S.zfill([2, 3, 4]), _BytesCharArray) | ||||
|  | ||||
| assert_type(AR_U.count("a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(AR_S.count([b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
|  | ||||
| assert_type(AR_U.endswith("a", start=[1, 2, 3]), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.endswith([b"a", b"b", b"c"], end=9), npt.NDArray[np.bool]) | ||||
| assert_type(AR_U.startswith("a", start=[1, 2, 3]), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.startswith([b"a", b"b", b"c"], end=9), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.find("a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(AR_S.find([b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
| assert_type(AR_U.rfind("a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(AR_S.rfind([b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
|  | ||||
| assert_type(AR_U.index("a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(AR_S.index([b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
| assert_type(AR_U.rindex("a", start=[1, 2, 3]), npt.NDArray[np.int_]) | ||||
| assert_type(AR_S.rindex([b"a", b"b", b"c"], end=9), npt.NDArray[np.int_]) | ||||
|  | ||||
| assert_type(AR_U.isalpha(), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.isalpha(), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.isalnum(), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.isalnum(), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.isdecimal(), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.isdecimal(), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.isdigit(), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.isdigit(), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.islower(), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.islower(), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.isnumeric(), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.isnumeric(), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.isspace(), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.isspace(), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.istitle(), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.istitle(), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.isupper(), npt.NDArray[np.bool]) | ||||
| assert_type(AR_S.isupper(), npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(AR_U.__array_finalize__(object()), None) | ||||
| assert_type(AR_S.__array_finalize__(object()), None) | ||||
| @ -0,0 +1,264 @@ | ||||
| import decimal | ||||
| import fractions | ||||
| from typing import Any, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
|  | ||||
| c16 = np.complex128() | ||||
| f8 = np.float64() | ||||
| i8 = np.int64() | ||||
| u8 = np.uint64() | ||||
|  | ||||
| c8 = np.complex64() | ||||
| f4 = np.float32() | ||||
| i4 = np.int32() | ||||
| u4 = np.uint32() | ||||
|  | ||||
| dt = np.datetime64(0, "D") | ||||
| td = np.timedelta64(0, "D") | ||||
|  | ||||
| b_ = np.bool() | ||||
|  | ||||
| b = bool() | ||||
| c = complex() | ||||
| f = float() | ||||
| i = int() | ||||
|  | ||||
| AR = np.array([0], dtype=np.int64) | ||||
| AR.setflags(write=False) | ||||
|  | ||||
| SEQ = (0, 1, 2, 3, 4) | ||||
|  | ||||
| # object-like comparisons | ||||
|  | ||||
| assert_type(i8 > fractions.Fraction(1, 5), np.bool) | ||||
| assert_type(i8 > [fractions.Fraction(1, 5)], npt.NDArray[np.bool]) | ||||
| assert_type(i8 > decimal.Decimal("1.5"), np.bool) | ||||
| assert_type(i8 > [decimal.Decimal("1.5")], npt.NDArray[np.bool]) | ||||
|  | ||||
| # Time structures | ||||
|  | ||||
| assert_type(dt > dt, np.bool) | ||||
|  | ||||
| assert_type(td > td, np.bool) | ||||
| assert_type(td > i, np.bool) | ||||
| assert_type(td > i4, np.bool) | ||||
| assert_type(td > i8, np.bool) | ||||
|  | ||||
| assert_type(td > AR, npt.NDArray[np.bool]) | ||||
| assert_type(td > SEQ, npt.NDArray[np.bool]) | ||||
| assert_type(AR > SEQ, npt.NDArray[np.bool]) | ||||
| assert_type(AR > td, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > td, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > AR, npt.NDArray[np.bool]) | ||||
|  | ||||
| # boolean | ||||
|  | ||||
| assert_type(b_ > b, np.bool) | ||||
| assert_type(b_ > b_, np.bool) | ||||
| assert_type(b_ > i, np.bool) | ||||
| assert_type(b_ > i8, np.bool) | ||||
| assert_type(b_ > i4, np.bool) | ||||
| assert_type(b_ > u8, np.bool) | ||||
| assert_type(b_ > u4, np.bool) | ||||
| assert_type(b_ > f, np.bool) | ||||
| assert_type(b_ > f8, np.bool) | ||||
| assert_type(b_ > f4, np.bool) | ||||
| assert_type(b_ > c, np.bool) | ||||
| assert_type(b_ > c16, np.bool) | ||||
| assert_type(b_ > c8, np.bool) | ||||
| assert_type(b_ > AR, npt.NDArray[np.bool]) | ||||
| assert_type(b_ > SEQ, npt.NDArray[np.bool]) | ||||
|  | ||||
| # Complex | ||||
|  | ||||
| assert_type(c16 > c16, np.bool) | ||||
| assert_type(c16 > f8, np.bool) | ||||
| assert_type(c16 > i8, np.bool) | ||||
| assert_type(c16 > c8, np.bool) | ||||
| assert_type(c16 > f4, np.bool) | ||||
| assert_type(c16 > i4, np.bool) | ||||
| assert_type(c16 > b_, np.bool) | ||||
| assert_type(c16 > b, np.bool) | ||||
| assert_type(c16 > c, np.bool) | ||||
| assert_type(c16 > f, np.bool) | ||||
| assert_type(c16 > i, np.bool) | ||||
| assert_type(c16 > AR, npt.NDArray[np.bool]) | ||||
| assert_type(c16 > SEQ, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(c16 > c16, np.bool) | ||||
| assert_type(f8 > c16, np.bool) | ||||
| assert_type(i8 > c16, np.bool) | ||||
| assert_type(c8 > c16, np.bool) | ||||
| assert_type(f4 > c16, np.bool) | ||||
| assert_type(i4 > c16, np.bool) | ||||
| assert_type(b_ > c16, np.bool) | ||||
| assert_type(b > c16, np.bool) | ||||
| assert_type(c > c16, np.bool) | ||||
| assert_type(f > c16, np.bool) | ||||
| assert_type(i > c16, np.bool) | ||||
| assert_type(AR > c16, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > c16, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(c8 > c16, np.bool) | ||||
| assert_type(c8 > f8, np.bool) | ||||
| assert_type(c8 > i8, np.bool) | ||||
| assert_type(c8 > c8, np.bool) | ||||
| assert_type(c8 > f4, np.bool) | ||||
| assert_type(c8 > i4, np.bool) | ||||
| assert_type(c8 > b_, np.bool) | ||||
| assert_type(c8 > b, np.bool) | ||||
| assert_type(c8 > c, np.bool) | ||||
| assert_type(c8 > f, np.bool) | ||||
| assert_type(c8 > i, np.bool) | ||||
| assert_type(c8 > AR, npt.NDArray[np.bool]) | ||||
| assert_type(c8 > SEQ, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(c16 > c8, np.bool) | ||||
| assert_type(f8 > c8, np.bool) | ||||
| assert_type(i8 > c8, np.bool) | ||||
| assert_type(c8 > c8, np.bool) | ||||
| assert_type(f4 > c8, np.bool) | ||||
| assert_type(i4 > c8, np.bool) | ||||
| assert_type(b_ > c8, np.bool) | ||||
| assert_type(b > c8, np.bool) | ||||
| assert_type(c > c8, np.bool) | ||||
| assert_type(f > c8, np.bool) | ||||
| assert_type(i > c8, np.bool) | ||||
| assert_type(AR > c8, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > c8, npt.NDArray[np.bool]) | ||||
|  | ||||
| # Float | ||||
|  | ||||
| assert_type(f8 > f8, np.bool) | ||||
| assert_type(f8 > i8, np.bool) | ||||
| assert_type(f8 > f4, np.bool) | ||||
| assert_type(f8 > i4, np.bool) | ||||
| assert_type(f8 > b_, np.bool) | ||||
| assert_type(f8 > b, np.bool) | ||||
| assert_type(f8 > c, np.bool) | ||||
| assert_type(f8 > f, np.bool) | ||||
| assert_type(f8 > i, np.bool) | ||||
| assert_type(f8 > AR, npt.NDArray[np.bool]) | ||||
| assert_type(f8 > SEQ, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(f8 > f8, np.bool) | ||||
| assert_type(i8 > f8, np.bool) | ||||
| assert_type(f4 > f8, np.bool) | ||||
| assert_type(i4 > f8, np.bool) | ||||
| assert_type(b_ > f8, np.bool) | ||||
| assert_type(b > f8, np.bool) | ||||
| assert_type(c > f8, np.bool) | ||||
| assert_type(f > f8, np.bool) | ||||
| assert_type(i > f8, np.bool) | ||||
| assert_type(AR > f8, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > f8, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(f4 > f8, np.bool) | ||||
| assert_type(f4 > i8, np.bool) | ||||
| assert_type(f4 > f4, np.bool) | ||||
| assert_type(f4 > i4, np.bool) | ||||
| assert_type(f4 > b_, np.bool) | ||||
| assert_type(f4 > b, np.bool) | ||||
| assert_type(f4 > c, np.bool) | ||||
| assert_type(f4 > f, np.bool) | ||||
| assert_type(f4 > i, np.bool) | ||||
| assert_type(f4 > AR, npt.NDArray[np.bool]) | ||||
| assert_type(f4 > SEQ, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(f8 > f4, np.bool) | ||||
| assert_type(i8 > f4, np.bool) | ||||
| assert_type(f4 > f4, np.bool) | ||||
| assert_type(i4 > f4, np.bool) | ||||
| assert_type(b_ > f4, np.bool) | ||||
| assert_type(b > f4, np.bool) | ||||
| assert_type(c > f4, np.bool) | ||||
| assert_type(f > f4, np.bool) | ||||
| assert_type(i > f4, np.bool) | ||||
| assert_type(AR > f4, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > f4, npt.NDArray[np.bool]) | ||||
|  | ||||
| # Int | ||||
|  | ||||
| assert_type(i8 > i8, np.bool) | ||||
| assert_type(i8 > u8, np.bool) | ||||
| assert_type(i8 > i4, np.bool) | ||||
| assert_type(i8 > u4, np.bool) | ||||
| assert_type(i8 > b_, np.bool) | ||||
| assert_type(i8 > b, np.bool) | ||||
| assert_type(i8 > c, np.bool) | ||||
| assert_type(i8 > f, np.bool) | ||||
| assert_type(i8 > i, np.bool) | ||||
| assert_type(i8 > AR, npt.NDArray[np.bool]) | ||||
| assert_type(i8 > SEQ, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(u8 > u8, np.bool) | ||||
| assert_type(u8 > i4, np.bool) | ||||
| assert_type(u8 > u4, np.bool) | ||||
| assert_type(u8 > b_, np.bool) | ||||
| assert_type(u8 > b, np.bool) | ||||
| assert_type(u8 > c, np.bool) | ||||
| assert_type(u8 > f, np.bool) | ||||
| assert_type(u8 > i, np.bool) | ||||
| assert_type(u8 > AR, npt.NDArray[np.bool]) | ||||
| assert_type(u8 > SEQ, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(i8 > i8, np.bool) | ||||
| assert_type(u8 > i8, np.bool) | ||||
| assert_type(i4 > i8, np.bool) | ||||
| assert_type(u4 > i8, np.bool) | ||||
| assert_type(b_ > i8, np.bool) | ||||
| assert_type(b > i8, np.bool) | ||||
| assert_type(c > i8, np.bool) | ||||
| assert_type(f > i8, np.bool) | ||||
| assert_type(i > i8, np.bool) | ||||
| assert_type(AR > i8, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > i8, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(u8 > u8, np.bool) | ||||
| assert_type(i4 > u8, np.bool) | ||||
| assert_type(u4 > u8, np.bool) | ||||
| assert_type(b_ > u8, np.bool) | ||||
| assert_type(b > u8, np.bool) | ||||
| assert_type(c > u8, np.bool) | ||||
| assert_type(f > u8, np.bool) | ||||
| assert_type(i > u8, np.bool) | ||||
| assert_type(AR > u8, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > u8, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(i4 > i8, np.bool) | ||||
| assert_type(i4 > i4, np.bool) | ||||
| assert_type(i4 > i, np.bool) | ||||
| assert_type(i4 > b_, np.bool) | ||||
| assert_type(i4 > b, np.bool) | ||||
| assert_type(i4 > AR, npt.NDArray[np.bool]) | ||||
| assert_type(i4 > SEQ, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(u4 > i8, np.bool) | ||||
| assert_type(u4 > i4, np.bool) | ||||
| assert_type(u4 > u8, np.bool) | ||||
| assert_type(u4 > u4, np.bool) | ||||
| assert_type(u4 > i, np.bool) | ||||
| assert_type(u4 > b_, np.bool) | ||||
| assert_type(u4 > b, np.bool) | ||||
| assert_type(u4 > AR, npt.NDArray[np.bool]) | ||||
| assert_type(u4 > SEQ, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(i8 > i4, np.bool) | ||||
| assert_type(i4 > i4, np.bool) | ||||
| assert_type(i > i4, np.bool) | ||||
| assert_type(b_ > i4, np.bool) | ||||
| assert_type(b > i4, np.bool) | ||||
| assert_type(AR > i4, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > i4, npt.NDArray[np.bool]) | ||||
|  | ||||
| assert_type(i8 > u4, np.bool) | ||||
| assert_type(i4 > u4, np.bool) | ||||
| assert_type(u8 > u4, np.bool) | ||||
| assert_type(u4 > u4, np.bool) | ||||
| assert_type(b_ > u4, np.bool) | ||||
| assert_type(b > u4, np.bool) | ||||
| assert_type(i > u4, np.bool) | ||||
| assert_type(AR > u4, npt.NDArray[np.bool]) | ||||
| assert_type(SEQ > u4, npt.NDArray[np.bool]) | ||||
| @ -0,0 +1,14 @@ | ||||
| from typing import Literal, assert_type | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
| assert_type(np.e, float) | ||||
| assert_type(np.euler_gamma, float) | ||||
| assert_type(np.inf, float) | ||||
| assert_type(np.nan, float) | ||||
| assert_type(np.pi, float) | ||||
|  | ||||
| assert_type(np.little_endian, bool) | ||||
|  | ||||
| assert_type(np.True_, np.bool[Literal[True]]) | ||||
| assert_type(np.False_, np.bool[Literal[False]]) | ||||
| @ -0,0 +1,81 @@ | ||||
| import ctypes as ct | ||||
| from typing import Any, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| import numpy.typing as npt | ||||
| from numpy import ctypeslib | ||||
|  | ||||
| AR_bool: npt.NDArray[np.bool] | ||||
| AR_ubyte: npt.NDArray[np.ubyte] | ||||
| AR_ushort: npt.NDArray[np.ushort] | ||||
| AR_uintc: npt.NDArray[np.uintc] | ||||
| AR_ulong: npt.NDArray[np.ulong] | ||||
| AR_ulonglong: npt.NDArray[np.ulonglong] | ||||
| AR_byte: npt.NDArray[np.byte] | ||||
| AR_short: npt.NDArray[np.short] | ||||
| AR_intc: npt.NDArray[np.intc] | ||||
| AR_long: npt.NDArray[np.long] | ||||
| AR_longlong: npt.NDArray[np.longlong] | ||||
| AR_single: npt.NDArray[np.single] | ||||
| AR_double: npt.NDArray[np.double] | ||||
| AR_longdouble: npt.NDArray[np.longdouble] | ||||
| AR_void: npt.NDArray[np.void] | ||||
|  | ||||
| pointer: ct._Pointer[Any] | ||||
|  | ||||
| assert_type(np.ctypeslib.c_intp(), ctypeslib.c_intp) | ||||
|  | ||||
| assert_type(np.ctypeslib.ndpointer(), type[ctypeslib._ndptr[None]]) | ||||
| assert_type(np.ctypeslib.ndpointer(dtype=np.float64), type[ctypeslib._ndptr[np.dtype[np.float64]]]) | ||||
| assert_type(np.ctypeslib.ndpointer(dtype=float), type[ctypeslib._ndptr[np.dtype]]) | ||||
| assert_type(np.ctypeslib.ndpointer(shape=(10, 3)), type[ctypeslib._ndptr[None]]) | ||||
| assert_type(np.ctypeslib.ndpointer(np.int64, shape=(10, 3)), type[ctypeslib._concrete_ndptr[np.dtype[np.int64]]]) | ||||
| assert_type(np.ctypeslib.ndpointer(int, shape=(1,)), type[np.ctypeslib._concrete_ndptr[np.dtype]]) | ||||
|  | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.bool), type[ct.c_bool]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.ubyte), type[ct.c_ubyte]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.ushort), type[ct.c_ushort]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.uintc), type[ct.c_uint]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.byte), type[ct.c_byte]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.short), type[ct.c_short]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.intc), type[ct.c_int]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.single), type[ct.c_float]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.double), type[ct.c_double]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(ct.c_double), type[ct.c_double]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type("q"), type[ct.c_longlong]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type([("i8", np.int64), ("f8", np.float64)]), type[Any]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type("i8"), type[Any]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type("f8"), type[Any]) | ||||
|  | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_bool.take(0)), ct.c_bool) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_ubyte.take(0)), ct.c_ubyte) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_ushort.take(0)), ct.c_ushort) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_uintc.take(0)), ct.c_uint) | ||||
|  | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_byte.take(0)), ct.c_byte) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_short.take(0)), ct.c_short) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_intc.take(0)), ct.c_int) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_single.take(0)), ct.c_float) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_double.take(0)), ct.c_double) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_void.take(0)), Any) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_bool), ct.Array[ct.c_bool]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_ubyte), ct.Array[ct.c_ubyte]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_ushort), ct.Array[ct.c_ushort]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_uintc), ct.Array[ct.c_uint]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_byte), ct.Array[ct.c_byte]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_short), ct.Array[ct.c_short]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_intc), ct.Array[ct.c_int]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_single), ct.Array[ct.c_float]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_double), ct.Array[ct.c_double]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_void), ct.Array[Any]) | ||||
|  | ||||
| assert_type(np.ctypeslib.as_array(AR_ubyte), npt.NDArray[np.ubyte]) | ||||
| assert_type(np.ctypeslib.as_array(1), npt.NDArray[Any]) | ||||
| assert_type(np.ctypeslib.as_array(pointer), npt.NDArray[Any]) | ||||
|  | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.long), type[ct.c_long]) | ||||
| assert_type(np.ctypeslib.as_ctypes_type(np.ulong), type[ct.c_ulong]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_ulong), ct.Array[ct.c_ulong]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_long), ct.Array[ct.c_long]) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_long.take(0)), ct.c_long) | ||||
| assert_type(np.ctypeslib.as_ctypes(AR_ulong.take(0)), ct.c_ulong) | ||||
| @ -0,0 +1,23 @@ | ||||
| from pathlib import Path | ||||
| from typing import IO, Any, assert_type | ||||
|  | ||||
| import numpy as np | ||||
|  | ||||
| path1: Path | ||||
| path2: str | ||||
|  | ||||
| d1 = np.lib.npyio.DataSource(path1) | ||||
| d2 = np.lib.npyio.DataSource(path2) | ||||
| d3 = np.lib.npyio.DataSource(None) | ||||
|  | ||||
| assert_type(d1.abspath("..."), str) | ||||
| assert_type(d2.abspath("..."), str) | ||||
| assert_type(d3.abspath("..."), str) | ||||
|  | ||||
| assert_type(d1.exists("..."), bool) | ||||
| assert_type(d2.exists("..."), bool) | ||||
| assert_type(d3.exists("..."), bool) | ||||
|  | ||||
| assert_type(d1.open("...", "r"), IO[Any]) | ||||
| assert_type(d2.open("...", encoding="utf8"), IO[Any]) | ||||
| assert_type(d3.open("...", newline="/n"), IO[Any]) | ||||
| @ -0,0 +1,136 @@ | ||||
| import ctypes as ct | ||||
| import datetime as dt | ||||
| from decimal import Decimal | ||||
| from fractions import Fraction | ||||
| from typing import Any, Literal, LiteralString, TypeAlias, assert_type | ||||
|  | ||||
| import numpy as np | ||||
| from numpy.dtypes import StringDType | ||||
|  | ||||
| # a combination of likely `object` dtype-like candidates (no `_co`) | ||||
| _PyObjectLike: TypeAlias = Decimal | Fraction | dt.datetime | dt.timedelta | ||||
|  | ||||
| dtype_U: np.dtype[np.str_] | ||||
| dtype_V: np.dtype[np.void] | ||||
| dtype_i8: np.dtype[np.int64] | ||||
|  | ||||
| py_int_co: type[int] | ||||
| py_float_co: type[float] | ||||
| py_complex_co: type[complex] | ||||
| py_object: type[_PyObjectLike] | ||||
| py_character: type[str | bytes] | ||||
| py_flexible: type[str | bytes | memoryview] | ||||
|  | ||||
| ct_floating: type[ct.c_float | ct.c_double | ct.c_longdouble] | ||||
| ct_number: type[ct.c_uint8 | ct.c_float] | ||||
| ct_generic: type[ct.c_bool | ct.c_char] | ||||
|  | ||||
| cs_integer: Literal["u1", "<i2", "L"] | ||||
| cs_number: Literal["=L", "i", "c16"] | ||||
| cs_flex: Literal[">V", "S"] | ||||
| cs_generic: Literal["H", "U", "h", "|M8[Y]", "?"] | ||||
|  | ||||
| dt_inexact: np.dtype[np.inexact] | ||||
| dt_string: StringDType | ||||
|  | ||||
| assert_type(np.dtype(np.float64), np.dtype[np.float64]) | ||||
| assert_type(np.dtype(np.float64, metadata={"test": "test"}), np.dtype[np.float64]) | ||||
| assert_type(np.dtype(np.int64), np.dtype[np.int64]) | ||||
|  | ||||
| # String aliases | ||||
| assert_type(np.dtype("float64"), np.dtype[np.float64]) | ||||
| assert_type(np.dtype("float32"), np.dtype[np.float32]) | ||||
| assert_type(np.dtype("int64"), np.dtype[np.int64]) | ||||
| assert_type(np.dtype("int32"), np.dtype[np.int32]) | ||||
| assert_type(np.dtype("bool"), np.dtype[np.bool]) | ||||
| assert_type(np.dtype("bytes"), np.dtype[np.bytes_]) | ||||
| assert_type(np.dtype("str"), np.dtype[np.str_]) | ||||
|  | ||||
| # Python types | ||||
| assert_type(np.dtype(bool), np.dtype[np.bool]) | ||||
| assert_type(np.dtype(py_int_co), np.dtype[np.int_ | np.bool]) | ||||
| assert_type(np.dtype(int), np.dtype[np.int_ | np.bool]) | ||||
| assert_type(np.dtype(py_float_co), np.dtype[np.float64 | np.int_ | np.bool]) | ||||
| assert_type(np.dtype(float), np.dtype[np.float64 | np.int_ | np.bool]) | ||||
| assert_type(np.dtype(py_complex_co), np.dtype[np.complex128 | np.float64 | np.int_ | np.bool]) | ||||
| assert_type(np.dtype(complex), np.dtype[np.complex128 | np.float64 | np.int_ | np.bool]) | ||||
| assert_type(np.dtype(py_object), np.dtype[np.object_]) | ||||
| assert_type(np.dtype(str), np.dtype[np.str_]) | ||||
| assert_type(np.dtype(bytes), np.dtype[np.bytes_]) | ||||
| assert_type(np.dtype(py_character), np.dtype[np.character]) | ||||
| assert_type(np.dtype(memoryview), np.dtype[np.void]) | ||||
| assert_type(np.dtype(py_flexible), np.dtype[np.flexible]) | ||||
|  | ||||
| assert_type(np.dtype(list), np.dtype[np.object_]) | ||||
| assert_type(np.dtype(dt.datetime), np.dtype[np.object_]) | ||||
| assert_type(np.dtype(dt.timedelta), np.dtype[np.object_]) | ||||
| assert_type(np.dtype(Decimal), np.dtype[np.object_]) | ||||
| assert_type(np.dtype(Fraction), np.dtype[np.object_]) | ||||
|  | ||||
| # char-codes | ||||
| assert_type(np.dtype("?"), np.dtype[np.bool]) | ||||
| assert_type(np.dtype("|b1"), np.dtype[np.bool]) | ||||
| assert_type(np.dtype("u1"), np.dtype[np.uint8]) | ||||
| assert_type(np.dtype("l"), np.dtype[np.long]) | ||||
| assert_type(np.dtype("longlong"), np.dtype[np.longlong]) | ||||
| assert_type(np.dtype(">g"), np.dtype[np.longdouble]) | ||||
| assert_type(np.dtype(cs_integer), np.dtype[np.integer]) | ||||
| assert_type(np.dtype(cs_number), np.dtype[np.number]) | ||||
| assert_type(np.dtype(cs_flex), np.dtype[np.flexible]) | ||||
| assert_type(np.dtype(cs_generic), np.dtype[np.generic]) | ||||
|  | ||||
| # ctypes | ||||
| assert_type(np.dtype(ct.c_double), np.dtype[np.double]) | ||||
| assert_type(np.dtype(ct.c_longlong), np.dtype[np.longlong]) | ||||
| assert_type(np.dtype(ct.c_uint32), np.dtype[np.uint32]) | ||||
| assert_type(np.dtype(ct.c_bool), np.dtype[np.bool]) | ||||
| assert_type(np.dtype(ct.c_char), np.dtype[np.bytes_]) | ||||
| assert_type(np.dtype(ct.py_object), np.dtype[np.object_]) | ||||
|  | ||||
| # Special case for None | ||||
| assert_type(np.dtype(None), np.dtype[np.float64]) | ||||
|  | ||||
| # Dypes of dtypes | ||||
| assert_type(np.dtype(np.dtype(np.float64)), np.dtype[np.float64]) | ||||
| assert_type(np.dtype(dt_inexact), np.dtype[np.inexact]) | ||||
|  | ||||
| # Parameterized dtypes | ||||
| assert_type(np.dtype("S8"), np.dtype) | ||||
|  | ||||
| # Void | ||||
| assert_type(np.dtype(("U", 10)), np.dtype[np.void]) | ||||
|  | ||||
| # StringDType | ||||
| assert_type(np.dtype(dt_string), StringDType) | ||||
| assert_type(np.dtype("T"), StringDType) | ||||
| assert_type(np.dtype("=T"), StringDType) | ||||
| assert_type(np.dtype("|T"), StringDType) | ||||
|  | ||||
| # Methods and attributes | ||||
| assert_type(dtype_U.base, np.dtype) | ||||
| assert_type(dtype_U.subdtype, tuple[np.dtype, tuple[Any, ...]] | None) | ||||
| assert_type(dtype_U.newbyteorder(), np.dtype[np.str_]) | ||||
| assert_type(dtype_U.type, type[np.str_]) | ||||
| assert_type(dtype_U.name, LiteralString) | ||||
| assert_type(dtype_U.names, tuple[str, ...] | None) | ||||
|  | ||||
| assert_type(dtype_U * 0, np.dtype[np.str_]) | ||||
| assert_type(dtype_U * 1, np.dtype[np.str_]) | ||||
| assert_type(dtype_U * 2, np.dtype[np.str_]) | ||||
|  | ||||
| assert_type(dtype_i8 * 0, np.dtype[np.void]) | ||||
| assert_type(dtype_i8 * 1, np.dtype[np.int64]) | ||||
| assert_type(dtype_i8 * 2, np.dtype[np.void]) | ||||
|  | ||||
| assert_type(0 * dtype_U, np.dtype[np.str_]) | ||||
| assert_type(1 * dtype_U, np.dtype[np.str_]) | ||||
| assert_type(2 * dtype_U, np.dtype[np.str_]) | ||||
|  | ||||
| assert_type(0 * dtype_i8, np.dtype) | ||||
| assert_type(1 * dtype_i8, np.dtype) | ||||
| assert_type(2 * dtype_i8, np.dtype) | ||||
|  | ||||
| assert_type(dtype_V["f0"], np.dtype) | ||||
| assert_type(dtype_V[0], np.dtype) | ||||
| assert_type(dtype_V[["f0", "f1"]], np.dtype[np.void]) | ||||
| assert_type(dtype_V[["f0"]], np.dtype[np.void]) | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user