diff --git a/.github/check-warnings/msvc-allowed-warnings.txt b/.github/check-warnings/msvc-allowed-warnings.txt index fa5597b18216..4cc6e6ab2124 100644 --- a/.github/check-warnings/msvc-allowed-warnings.txt +++ b/.github/check-warnings/msvc-allowed-warnings.txt @@ -15,7 +15,7 @@ C:\a\numpy\numpy\numpy\random\src\pcg64\pcg64.h(342): warning C4146: unary minus operator applied to unsigned type, result still unsigned D:\a\numpy\numpy\numpy\random\src\pcg64\pcg64.h(342): warning C4146: unary minus operator applied to unsigned type, result still unsigned cl : Command line warning D9025 : overriding '/arch:SSE2' with '/arch:AVX2' -numpy/random/_generator.cp312-win32.pyd.p/numpy/random/_generator.pyx.c(26290): warning C4244: 'function': conversion from 'int64_t' to 'double', possible loss of data -numpy/random/_generator.cp312-win32.pyd.p/numpy/random/_generator.pyx.c(38314): warning C4244: 'function': conversion from 'int64_t' to 'double', possible loss of data -numpy/random/_generator.cp312-win_arm64.pyd.p/numpy/random/_generator.pyx.c(26290): warning C4244: 'function': conversion from 'int64_t' to 'double', possible loss of data -numpy/random/_generator.cp312-win_arm64.pyd.p/numpy/random/_generator.pyx.c(38314): warning C4244: 'function': conversion from 'int64_t' to 'double', possible loss of data +numpy/random/_generator.cp312-win32.pyd.p/numpy/random/_generator.pyx.c(26329): warning C4244: 'function': conversion from 'int64_t' to 'double', possible loss of data +numpy/random/_generator.cp312-win32.pyd.p/numpy/random/_generator.pyx.c(38353): warning C4244: 'function': conversion from 'int64_t' to 'double', possible loss of data +numpy/random/_generator.cp312-win_arm64.pyd.p/numpy/random/_generator.pyx.c(26329): warning C4244: 'function': conversion from 'int64_t' to 'double', possible loss of data +numpy/random/_generator.cp312-win_arm64.pyd.p/numpy/random/_generator.pyx.c(38353): warning C4244: 'function': conversion from 'int64_t' to 'double', possible loss of data diff --git a/.github/workflows/cygwin.yml b/.github/workflows/cygwin.yml index e8f7083336e6..525709493d5f 100644 --- a/.github/workflows/cygwin.yml +++ b/.github/workflows/cygwin.yml @@ -28,7 +28,7 @@ jobs: fetch-tags: true persist-credentials: false - name: Install Cygwin - uses: egor-tensin/setup-cygwin@d2c752bab416d4b0662591bd366fc2686297c82d # v4 + uses: egor-tensin/setup-cygwin@fca9069f92361187d4abfaa5d8a7490e435d8349 # v4 with: platform: x86_64 install-dir: 'C:\tools\cygwin' @@ -37,7 +37,7 @@ jobs: python-setuptools-wheel liblapack-devel liblapack0 gcc-fortran gcc-g++ git dash cmake ninja - name: Set Windows PATH - uses: egor-tensin/cleanup-path@f04bc953e6823bf491cc0bdcff959c630db1b458 # v4.0.1 + uses: egor-tensin/cleanup-path@64ef0b5036b30ce7845058a1d7a8d0830db39b94 # v4.0.2 with: dirs: 'C:\tools\cygwin\bin;C:\tools\cygwin\lib\lapack' - name: Verify that bash is Cygwin bash @@ -67,7 +67,7 @@ jobs: cd tools /usr/bin/python3.9 -m pytest --pyargs numpy -n2 -m "not slow" - name: Upload wheel if tests fail - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 if: failure() with: name: numpy-cygwin-wheel diff --git a/.github/workflows/linux_qemu.yml b/.github/workflows/linux_qemu.yml index 916417ebc513..f82bf1aa2626 100644 --- a/.github/workflows/linux_qemu.yml +++ b/.github/workflows/linux_qemu.yml @@ -96,7 +96,7 @@ jobs: sudo apt install -y ninja-build gcc-${TOOLCHAIN_NAME} g++-${TOOLCHAIN_NAME} gfortran-${TOOLCHAIN_NAME} - name: Cache docker container - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 id: container-cache with: path: ~/docker_${{ matrix.BUILD_PROP[1] }} @@ -204,7 +204,7 @@ jobs: sudo apt install -y ninja-build gcc-14-${TOOLCHAIN_NAME} g++-14-${TOOLCHAIN_NAME} gfortran-14-${TOOLCHAIN_NAME} - name: Cache docker container - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 id: container-cache with: path: ~/docker_${{ matrix.BUILD_PROP[1] }} diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index f2af68370b99..15d3cf947222 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -49,7 +49,7 @@ jobs: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT - name: Setup compiler cache - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 id: cache-ccache with: path: ${{ steps.prep-ccache.outputs.dir }} @@ -73,7 +73,7 @@ jobs: # ensure we re-solve once a day (since we don't lock versions). Could be # replaced by a conda-lock based approach in the future. - name: Cache conda environment - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 + uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 env: # Increase this value to reset cache if environment.yml has not changed CACHE_NUMBER: 1 diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index ac87ccacd846..41f421ce3889 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -61,7 +61,7 @@ jobs: submodules: recursive fetch-tags: true persist-credentials: false - - uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7.1.5 + - uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7.1.6 with: python-version: ${{ matrix.os_python[1] }} activate-environment: true diff --git a/.github/workflows/mypy_primer.yml b/.github/workflows/mypy_primer.yml index 040a154d2895..b0b57cb93d7b 100644 --- a/.github/workflows/mypy_primer.yml +++ b/.github/workflows/mypy_primer.yml @@ -74,7 +74,7 @@ jobs: run: | echo ${{ github.event.pull_request.number }} | tee pr_number.txt - name: Upload mypy_primer diff + PR number - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 if: ${{ matrix.shard-index == 0 }} with: name: mypy_primer_diffs-${{ matrix.shard-index }} @@ -82,7 +82,7 @@ jobs: diff_${{ matrix.shard-index }}.txt pr_number.txt - name: Upload mypy_primer diff - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 if: ${{ matrix.shard-index != 0 }} with: name: mypy_primer_diffs-${{ matrix.shard-index }} @@ -96,7 +96,7 @@ jobs: contents: read steps: - name: Merge artifacts - uses: actions/upload-artifact/merge@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + uses: actions/upload-artifact/merge@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 with: name: mypy_primer_diffs pattern: mypy_primer_diffs-* diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index 140d92d43e61..421790b4ae1e 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -42,7 +42,7 @@ jobs: # Upload the results as artifacts (optional). Commenting out will disable # uploads of run results in SARIF format to the repository Actions tab. - name: "Upload artifact" - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 with: name: SARIF file path: results.sarif diff --git a/.github/workflows/stubtest.yml b/.github/workflows/stubtest.yml index c91954403b14..526471f799c7 100644 --- a/.github/workflows/stubtest.yml +++ b/.github/workflows/stubtest.yml @@ -43,7 +43,7 @@ jobs: fetch-tags: true persist-credentials: false - - uses: astral-sh/setup-uv@ed21f2f24f8dd64503750218de024bcf64c7250a # v7.1.5 + - uses: astral-sh/setup-uv@681c641aba71e4a1c380be3ab5e12ad51f415867 # v7.1.6 with: python-version: ${{ matrix.py }} activate-environment: true diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 436e929fe636..27ee88d80677 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -102,7 +102,7 @@ jobs: env: CIBW_BUILD: ${{ matrix.python }}-${{ matrix.buildplat[1] }} - - uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0 + - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 with: name: ${{ matrix.python }}-${{ matrix.buildplat[1] }}-${{ matrix.buildplat[2] }} path: ./wheelhouse/*.whl diff --git a/environment.yml b/environment.yml index 307dd4631012..774d6c0209ac 100644 --- a/environment.yml +++ b/environment.yml @@ -24,7 +24,7 @@ dependencies: - pytest-xdist - hypothesis # For type annotations - - mypy=1.19.0 + - mypy=1.19.1 - orjson # makes mypy faster # For building docs - sphinx>=4.5.0 diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi index aad324f54c4d..4128dd3cb9ec 100644 --- a/numpy/__init__.pyi +++ b/numpy/__init__.pyi @@ -1,16 +1,15 @@ # ruff: noqa: I001 -import builtins import ctypes as ct import datetime as dt import inspect import sys from abc import abstractmethod -from types import EllipsisType, ModuleType, TracebackType, MappingProxyType, GenericAlias +from builtins import bool as py_bool from decimal import Decimal from fractions import Fraction +from types import EllipsisType, ModuleType, TracebackType, MappingProxyType, GenericAlias from uuid import UUID -import numpy as np from numpy.__config__ import show as show_config from numpy._pytesttester import PytestTester from numpy._core._internal import _ctypes @@ -714,7 +713,7 @@ _NBitT1 = TypeVar("_NBitT1", bound=NBitBase, default=Any) # pyright: ignore[rep _NBitT2 = TypeVar("_NBitT2", bound=NBitBase, default=_NBitT1) # pyright: ignore[reportDeprecated] _ItemT_co = TypeVar("_ItemT_co", default=Any, covariant=True) -_BoolItemT_co = TypeVar("_BoolItemT_co", bound=builtins.bool, default=builtins.bool, covariant=True) +_BoolItemT_co = TypeVar("_BoolItemT_co", bound=py_bool, default=py_bool, covariant=True) _NumberItemT_co = TypeVar("_NumberItemT_co", bound=complex, default=int | float | complex, covariant=True) _InexactItemT_co = TypeVar("_InexactItemT_co", bound=complex, default=float | complex, covariant=True) _FlexibleItemT_co = TypeVar( @@ -729,8 +728,8 @@ _DT64ItemT_co = TypeVar("_DT64ItemT_co", bound=_DT64Item, default=Any, covariant ### Type Aliases (for internal use only) -type _Falsy = L[False, 0] | np.bool[L[False]] -type _Truthy = L[True, 1] | np.bool[L[True]] +type _Falsy = L[False, 0] | bool_[L[False]] +type _Truthy = L[True, 1] | bool_[L[True]] type _1D = tuple[int] type _2D = tuple[int, int] @@ -750,8 +749,8 @@ type _ArrayNumeric = NDArray[number | timedelta64 | object_] type _ScalarNotObject = bool_ | number | flexible | datetime64 | timedelta64 -type _Float64_co = float | floating[_64Bit] | float32 | float16 | integer | np.bool -type _Complex64_co = number[_32Bit] | number[_16Bit] | number[_8Bit] | builtins.bool | np.bool +type _Float64_co = float | floating[_64Bit] | float32 | float16 | integer | bool_ +type _Complex64_co = number[_32Bit] | number[_16Bit] | number[_8Bit] | py_bool | bool_ type _Complex128_co = complex | number[_64Bit] | _Complex64_co type _ToIndex = SupportsIndex | slice | EllipsisType | _ArrayLikeInt_co | None @@ -888,8 +887,8 @@ type _SortSide = L["left", "right"] type _ConvertibleToInt = SupportsInt | SupportsIndex | _CharLike_co type _ConvertibleToFloat = SupportsFloat | SupportsIndex | _CharLike_co type _ConvertibleToComplex = SupportsComplex | SupportsFloat | SupportsIndex | _CharLike_co -type _ConvertibleToTD64 = dt.timedelta | int | _CharLike_co | character | number | timedelta64 | np.bool | None -type _ConvertibleToDT64 = dt.date | int | _CharLike_co | character | number | datetime64 | np.bool | None +type _ConvertibleToTD64 = dt.timedelta | int | _CharLike_co | character | number | timedelta64 | bool_ | None +type _ConvertibleToDT64 = dt.date | int | _CharLike_co | character | number | datetime64 | bool_ | None type _NDIterFlagsKind = L[ "buffered", @@ -1062,9 +1061,9 @@ euler_gamma: Final[float] = ... pi: Final[float] = ... inf: Final[float] = ... nan: Final[float] = ... -little_endian: Final[builtins.bool] = ... -False_: Final[np.bool[L[False]]] = ... -True_: Final[np.bool[L[True]]] = ... +little_endian: Final[py_bool] = ... +False_: Final[bool_[L[False]]] = ... +True_: Final[bool_[L[True]]] = ... newaxis: Final[None] = None # not in __all__ @@ -1090,7 +1089,7 @@ class _DTypeMeta(type): @final class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 - names: tuple[builtins.str, ...] | None + names: tuple[str, ...] | None def __hash__(self) -> int: ... # `None` results in the default dtype @@ -1098,10 +1097,10 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: type[float64 | ct.c_double] | _Float64Codes | None, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ... + metadata: dict[str, Any] = ... ) -> dtype[float64]: ... # Overload for `dtype` instances, scalar types, and instances that have a @@ -1110,10 +1109,10 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__[ScalarT: generic]( cls, dtype: _DTypeLike[ScalarT], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[ScalarT]: ... # Builtin types @@ -1129,18 +1128,18 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 @overload def __new__( cls, - dtype: type[builtins.bool | np.bool | ct.c_bool] | _BoolCodes, - align: builtins.bool = False, - copy: builtins.bool = False, + dtype: type[py_bool | bool_ | ct.c_bool] | _BoolCodes, + align: py_bool = False, + copy: py_bool = False, *, metadata: dict[str, Any] = ..., - ) -> dtype[np.bool]: ... + ) -> dtype[bool_]: ... @overload def __new__( cls, - dtype: type[int], # also accepts `type[builtins.bool]` - align: builtins.bool = False, - copy: builtins.bool = False, + dtype: type[int], # also accepts `type[py_bool]` + align: py_bool = False, + copy: py_bool = False, *, metadata: dict[str, Any] = ..., ) -> dtype[int_ | Any]: ... @@ -1148,8 +1147,8 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: type[float], # also accepts `type[int | bool]` - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, metadata: dict[str, Any] = ..., ) -> dtype[float64 | Any]: ... @@ -1157,8 +1156,8 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: type[complex], # also accepts `type[float | int | bool]` - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, metadata: dict[str, Any] = ..., ) -> dtype[complex128 | Any]: ... @@ -1166,8 +1165,8 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: type[bytes | ct.c_char] | _BytesCodes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, metadata: dict[str, Any] = ..., ) -> dtype[bytes_]: ... @@ -1175,8 +1174,8 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: type[str] | _StrCodes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, metadata: dict[str, Any] = ..., ) -> dtype[str_]: ... @@ -1190,8 +1189,8 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: type[void | memoryview] | _VoidDTypeLike | _VoidCodes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, metadata: dict[str, Any] = ..., ) -> dtype[void]: ... @@ -1201,8 +1200,8 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: type[object_ | _BuiltinObjectLike | ct.py_object[Any]] | _ObjectCodes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, metadata: dict[str, Any] = ..., ) -> dtype[object_]: ... @@ -1212,55 +1211,55 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: _UInt8Codes | type[ct.c_uint8], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uint8]: ... @overload def __new__( cls, dtype: _UInt16Codes | type[ct.c_uint16 | ct.c_ushort], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uint16]: ... @overload def __new__( cls, dtype: _UInt32Codes | _UIntCCodes | type[ct.c_uint32 | ct.c_uint], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uint32]: ... @overload def __new__( cls, dtype: _UInt64Codes | _ULongLongCodes | type[ct.c_uint64 | ct.c_ulonglong], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uint64]: ... @overload def __new__( cls, dtype: _UIntPCodes | type[ct.c_void_p | ct.c_size_t], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uintp]: ... @overload def __new__( cls, dtype: _ULongCodes | type[ct.c_ulong], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[uint32 | uint64]: ... # `signedinteger` string-based representations and ctypes @@ -1268,55 +1267,55 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: _Int8Codes | type[ct.c_int8], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[int8]: ... @overload def __new__( cls, dtype: _Int16Codes | type[ct.c_int16 | ct.c_short], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[int16]: ... @overload def __new__( cls, dtype: _Int32Codes | _IntCCodes | type[ct.c_int32 | ct.c_int], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[int32]: ... @overload def __new__( cls, dtype: _Int64Codes | _LongLongCodes | type[ct.c_int64 | ct.c_longlong], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[int64]: ... @overload def __new__( cls, dtype: _IntPCodes | type[intp | ct.c_ssize_t], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[intp]: ... @overload def __new__( cls, dtype: _LongCodes | type[ct.c_long], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[int32 | int64]: ... # `floating` string-based representations and ctypes @@ -1324,29 +1323,29 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: _Float16Codes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[float16]: ... @overload def __new__( cls, dtype: _Float32Codes | type[ct.c_float], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[float32]: ... # float64 codes are covered by overload 1 @overload def __new__( cls, dtype: _LongDoubleCodes | type[ct.c_longdouble], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[longdouble]: ... # `complexfloating` string-based representations and ctypes @@ -1355,56 +1354,56 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: _Complex64Codes | type[ct.c_float_complex], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[complex64]: ... @overload def __new__( cls, dtype: _Complex128Codes | type[ct.c_double_complex], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[complex128]: ... @overload def __new__( cls, dtype: _CLongDoubleCodes | type[ct.c_longdouble_complex], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[clongdouble]: ... else: @overload def __new__( cls, dtype: _Complex64Codes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[complex64]: ... @overload def __new__( cls, dtype: _Complex128Codes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[complex128]: ... @overload def __new__( cls, dtype: _CLongDoubleCodes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[clongdouble]: ... # Miscellaneous string-based representations and ctypes @@ -1412,19 +1411,19 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: _TD64Codes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[timedelta64]: ... @overload def __new__( cls, dtype: _DT64Codes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[datetime64]: ... # `StringDType` requires special treatment because it has no scalar type @@ -1432,10 +1431,10 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: dtypes.StringDType | _StringCodes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtypes.StringDType: ... # Combined char-codes and ctypes, analogous to the scalar-type hierarchy @@ -1443,62 +1442,62 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: _UnsignedIntegerCodes | _UnsignedIntegerCType, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[unsignedinteger]: ... @overload def __new__( cls, dtype: _SignedIntegerCodes | _SignedIntegerCType, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[signedinteger]: ... @overload def __new__( cls, dtype: _IntegerCodes | _IntegerCType, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[integer]: ... @overload def __new__( cls, dtype: _FloatingCodes | _FloatingCType, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[floating]: ... @overload def __new__( cls, dtype: _ComplexFloatingCodes, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[complexfloating]: ... @overload def __new__( cls, dtype: _InexactCodes | _FloatingCType, - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[inexact]: ... @overload def __new__( cls, - dtype: _CharacterCodes | type[bytes | builtins.str | ct.c_char], - align: builtins.bool = False, - copy: builtins.bool = False, + dtype: _CharacterCodes | type[bytes | str | ct.c_char], + align: py_bool = False, + copy: py_bool = False, *, metadata: dict[str, Any] = ..., ) -> dtype[character]: ... @@ -1507,11 +1506,11 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 @overload def __new__( cls, - dtype: builtins.str, - align: builtins.bool = False, - copy: builtins.bool = False, + dtype: str, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype: ... # Catch-all overload for object-likes @@ -1524,18 +1523,18 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 def __new__( cls, dtype: type[object], - align: builtins.bool = False, - copy: builtins.bool = False, + align: py_bool = False, + copy: py_bool = False, *, - metadata: dict[builtins.str, Any] = ..., + metadata: dict[str, Any] = ..., ) -> dtype[object_ | Any]: ... def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @overload - def __getitem__(self: dtype[void], key: list[builtins.str], /) -> dtype[void]: ... + def __getitem__(self: dtype[void], key: list[str], /) -> dtype[void]: ... @overload - def __getitem__(self: dtype[void], key: builtins.str | SupportsIndex, /) -> dtype: ... + def __getitem__(self: dtype[void], key: str | SupportsIndex, /) -> dtype: ... # NOTE: In the future 1-based multiplications will also yield `flexible` dtypes @overload @@ -1553,16 +1552,16 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 @overload def __rmul__(self, value: SupportsIndex, /) -> dtype: ... - def __gt__(self, other: DTypeLike | None, /) -> builtins.bool: ... - def __ge__(self, other: DTypeLike | None, /) -> builtins.bool: ... - def __lt__(self, other: DTypeLike | None, /) -> builtins.bool: ... - def __le__(self, other: DTypeLike | None, /) -> builtins.bool: ... + def __gt__(self, other: DTypeLike | None, /) -> py_bool: ... + def __ge__(self, other: DTypeLike | None, /) -> py_bool: ... + def __lt__(self, other: DTypeLike | None, /) -> py_bool: ... + def __le__(self, other: DTypeLike | None, /) -> py_bool: ... # Explicitly defined `__eq__` and `__ne__` to get around mypy's # `strict_equality` option; even though their signatures are # identical to their `object`-based counterpart - def __eq__(self, other: Any, /) -> builtins.bool: ... - def __ne__(self, other: Any, /) -> builtins.bool: ... + def __eq__(self, other: Any, /) -> py_bool: ... + def __ne__(self, other: Any, /) -> py_bool: ... @property def alignment(self) -> int: ... @@ -1579,19 +1578,19 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta): # noqa: UP046 @property def flags(self) -> int: ... @property - def hasobject(self) -> builtins.bool: ... + def hasobject(self) -> py_bool: ... @property def isbuiltin(self) -> _DTypeBuiltinKind: ... @property - def isnative(self) -> builtins.bool: ... + def isnative(self) -> py_bool: ... @property - def isalignedstruct(self) -> builtins.bool: ... + def isalignedstruct(self) -> py_bool: ... @property def itemsize(self) -> int: ... @property def kind(self) -> _DTypeKind: ... @property - def metadata(self) -> MappingProxyType[builtins.str, Any] | None: ... + def metadata(self) -> MappingProxyType[str, Any] | None: ... @property def name(self) -> LiteralString: ... @property @@ -1687,7 +1686,7 @@ class _ArrayOrScalarCommon: @property def device(self) -> L["cpu"]: ... - def __bool__(self, /) -> builtins.bool: ... + def __bool__(self, /) -> py_bool: ... def __int__(self, /) -> int: ... def __float__(self, /) -> float: ... def __copy__(self) -> Self: ... @@ -1716,9 +1715,9 @@ class _ArrayOrScalarCommon: self, /, *, - write: builtins.bool | None = None, - align: builtins.bool | None = None, - uic: builtins.bool | None = None, + write: py_bool | None = None, + align: py_bool | None = None, + uic: py_bool | None = None, ) -> None: ... @property @@ -1726,13 +1725,13 @@ class _ArrayOrScalarCommon: @property def __array_priority__(self) -> float: ... @property - def __array_struct__(self) -> CapsuleType: ... # builtins.PyCapsule + def __array_struct__(self) -> CapsuleType: ... def __array_namespace__(self, /, *, api_version: _ArrayAPIVersion | None = None) -> ModuleType: ... def __setstate__(self, state: tuple[ SupportsIndex, # version _ShapeLike, # Shape _DTypeT_co, # DType - np.bool, # F-continuous + bool_, # F-continuous bytes | list[Any], # Data ], /) -> None: ... @@ -1745,33 +1744,33 @@ class _ArrayOrScalarCommon: kind: _SortKind | None = ..., order: str | Sequence[str] | None = ..., *, - stable: builtins.bool | None = ..., + stable: py_bool | None = ..., ) -> NDArray[intp]: ... @overload # axis=None (default), out=None (default), keepdims=False (default) def argmax(self, /, axis: None = None, out: None = None, *, keepdims: L[False] = False) -> intp: ... @overload # axis=index, out=None (default) - def argmax(self, /, axis: SupportsIndex, out: None = None, *, keepdims: builtins.bool = False) -> Any: ... + def argmax(self, /, axis: SupportsIndex, out: None = None, *, keepdims: py_bool = False) -> Any: ... @overload # axis=index, out=ndarray def argmax[OutT: _ArrayInt_co]( - self, /, axis: SupportsIndex | None, out: OutT, *, keepdims: builtins.bool = False + self, /, axis: SupportsIndex | None, out: OutT, *, keepdims: py_bool = False ) -> OutT: ... @overload def argmax[OutT: _ArrayInt_co]( - self, /, axis: SupportsIndex | None = None, *, out: OutT, keepdims: builtins.bool = False + self, /, axis: SupportsIndex | None = None, *, out: OutT, keepdims: py_bool = False ) -> OutT: ... @overload # axis=None (default), out=None (default), keepdims=False (default) def argmin(self, /, axis: None = None, out: None = None, *, keepdims: L[False] = False) -> intp: ... @overload # axis=index, out=None (default) - def argmin(self, /, axis: SupportsIndex, out: None = None, *, keepdims: builtins.bool = False) -> Any: ... + def argmin(self, /, axis: SupportsIndex, out: None = None, *, keepdims: py_bool = False) -> Any: ... @overload # axis=index, out=ndarray def argmin[OutT: _ArrayInt_co]( - self, /, axis: SupportsIndex | None, out: OutT, *, keepdims: builtins.bool = False + self, /, axis: SupportsIndex | None, out: OutT, *, keepdims: py_bool = False ) -> OutT: ... @overload def argmin[OutT: _ArrayInt_co]( - self, /, axis: SupportsIndex | None = None, *, out: OutT, keepdims: builtins.bool = False + self, /, axis: SupportsIndex | None = None, *, out: OutT, keepdims: py_bool = False ) -> OutT: ... # Keep in sync with `MaskedArray.round` @@ -1839,7 +1838,7 @@ class _ArrayOrScalarCommon: axis: _ShapeLike | None = None, out: None = None, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> Any: ... @@ -1850,7 +1849,7 @@ class _ArrayOrScalarCommon: axis: _ShapeLike | None, out: ArrayT, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @@ -1861,7 +1860,7 @@ class _ArrayOrScalarCommon: axis: _ShapeLike | None = None, *, out: ArrayT, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @@ -1873,7 +1872,7 @@ class _ArrayOrScalarCommon: axis: _ShapeLike | None = None, out: None = None, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> Any: ... @@ -1884,7 +1883,7 @@ class _ArrayOrScalarCommon: axis: _ShapeLike | None, out: ArrayT, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @@ -1895,7 +1894,7 @@ class _ArrayOrScalarCommon: axis: _ShapeLike | None = None, *, out: ArrayT, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @@ -1908,7 +1907,7 @@ class _ArrayOrScalarCommon: dtype: DTypeLike | None = None, out: None = None, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> Any: ... @@ -1920,7 +1919,7 @@ class _ArrayOrScalarCommon: dtype: DTypeLike | None, out: ArrayT, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @@ -1932,7 +1931,7 @@ class _ArrayOrScalarCommon: dtype: DTypeLike | None = None, *, out: ArrayT, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @@ -1945,7 +1944,7 @@ class _ArrayOrScalarCommon: dtype: DTypeLike | None = None, out: None = None, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> Any: ... @@ -1957,7 +1956,7 @@ class _ArrayOrScalarCommon: dtype: DTypeLike | None, out: ArrayT, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @@ -1969,7 +1968,7 @@ class _ArrayOrScalarCommon: dtype: DTypeLike | None = None, *, out: ArrayT, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., initial: _NumberLike_co | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @@ -1981,7 +1980,7 @@ class _ArrayOrScalarCommon: dtype: DTypeLike | None = None, out: None = None, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> Any: ... @overload @@ -1992,7 +1991,7 @@ class _ArrayOrScalarCommon: dtype: DTypeLike | None, out: ArrayT, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @overload @@ -2003,7 +2002,7 @@ class _ArrayOrScalarCommon: dtype: DTypeLike | None = None, *, out: ArrayT, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., ) -> ArrayT: ... @@ -2015,7 +2014,7 @@ class _ArrayOrScalarCommon: out: None = None, ddof: float = 0, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., mean: _ArrayLikeNumber_co | _NoValueType = ..., correction: float | _NoValueType = ..., @@ -2028,7 +2027,7 @@ class _ArrayOrScalarCommon: out: ArrayT, ddof: float = 0, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., mean: _ArrayLikeNumber_co | _NoValueType = ..., correction: float | _NoValueType = ..., @@ -2041,7 +2040,7 @@ class _ArrayOrScalarCommon: *, out: ArrayT, ddof: float = 0, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., mean: _ArrayLikeNumber_co | _NoValueType = ..., correction: float | _NoValueType = ..., @@ -2055,7 +2054,7 @@ class _ArrayOrScalarCommon: out: None = None, ddof: float = 0, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., mean: _ArrayLikeNumber_co | _NoValueType = ..., correction: float | _NoValueType = ..., @@ -2068,7 +2067,7 @@ class _ArrayOrScalarCommon: out: ArrayT, ddof: float = 0, *, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., mean: _ArrayLikeNumber_co | _NoValueType = ..., correction: float | _NoValueType = ..., @@ -2081,7 +2080,7 @@ class _ArrayOrScalarCommon: *, out: ArrayT, ddof: float = 0, - keepdims: builtins.bool | _NoValueType = ..., + keepdims: py_bool | _NoValueType = ..., where: _ArrayLikeBool_co | _NoValueType = ..., mean: _ArrayLikeNumber_co | _NoValueType = ..., correction: float | _NoValueType = ..., @@ -2121,9 +2120,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @overload - def __array__(self, dtype: None = None, /, *, copy: builtins.bool | None = None) -> ndarray[_ShapeT_co, _DTypeT_co]: ... + def __array__(self, dtype: None = None, /, *, copy: py_bool | None = None) -> ndarray[_ShapeT_co, _DTypeT_co]: ... @overload - def __array__[DTypeT: dtype](self, dtype: DTypeT, /, *, copy: builtins.bool | None = None) -> ndarray[_ShapeT_co, DTypeT]: ... + def __array__[DTypeT: dtype](self, dtype: DTypeT, /, *, copy: py_bool | None = None) -> ndarray[_ShapeT_co, DTypeT]: ... def __array_ufunc__( self, @@ -2150,7 +2149,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): self, array: ndarray[ShapeT, DTypeT], context: tuple[ufunc, tuple[Any, ...], int] | None = ..., - return_scalar: builtins.bool = ..., + return_scalar: py_bool = ..., /, ) -> ndarray[ShapeT, DTypeT]: ... @@ -2168,7 +2167,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload # flexible | object_ | bool def __setitem__( - self: ndarray[Any, dtype[flexible | object_ | np.bool] | dtypes.StringDType], + self: ndarray[Any, dtype[flexible | object_ | bool_] | dtypes.StringDType], key: _ToIndices, value: object, /, @@ -2231,7 +2230,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def strides(self, value: _ShapeLike) -> None: ... # - def byteswap(self, inplace: builtins.bool = ...) -> Self: ... + def byteswap(self, inplace: py_bool = ...) -> Self: ... @property def flat(self) -> flatiter[Self]: ... @@ -2260,9 +2259,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def tolist(self, /) -> Any: ... @overload - def resize(self, new_shape: _ShapeLike, /, *, refcheck: builtins.bool = True) -> None: ... + def resize(self, new_shape: _ShapeLike, /, *, refcheck: py_bool = True) -> None: ... @overload - def resize(self, /, *new_shape: SupportsIndex, refcheck: builtins.bool = True) -> None: ... + def resize(self, /, *new_shape: SupportsIndex, refcheck: py_bool = True) -> None: ... # keep in sync with `ma.MaskedArray.squeeze` def squeeze( @@ -2286,7 +2285,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): keepdims: L[False, 0] = False, *, where: _ArrayLikeBool_co = True - ) -> np.bool: ... + ) -> bool_: ... @overload def all( self, @@ -2295,7 +2294,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): keepdims: SupportsIndex = False, *, where: _ArrayLikeBool_co = True, - ) -> np.bool | NDArray[np.bool]: ... + ) -> bool_ | NDArray[bool_]: ... @overload def all[ArrayT: ndarray]( self, @@ -2323,7 +2322,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): keepdims: L[False, 0] = False, *, where: _ArrayLikeBool_co = True - ) -> np.bool: ... + ) -> bool_: ... @overload def any( self, @@ -2332,7 +2331,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): keepdims: SupportsIndex = False, *, where: _ArrayLikeBool_co = True, - ) -> np.bool | NDArray[np.bool]: ... + ) -> bool_ | NDArray[bool_]: ... @overload def any[ArrayT: ndarray]( self, @@ -2410,7 +2409,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def dot[ArrayT: ndarray](self, b: ArrayLike, /, out: ArrayT) -> ArrayT: ... # `nonzero()` raises for 0d arrays/generics - def nonzero(self) -> tuple[ndarray[tuple[int], np.dtype[intp]], ...]: ... + def nonzero(self) -> tuple[ndarray[tuple[int], dtype[intp]], ...]: ... @overload def searchsorted( @@ -2436,7 +2435,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): kind: _SortKind | None = None, order: str | Sequence[str] | None = None, *, - stable: builtins.bool | None = None, + stable: py_bool | None = None, ) -> None: ... # Keep in sync with `MaskedArray.trace` @@ -2523,7 +2522,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.reshape` # NOTE: reshape also accepts negative integers, so we can't use integer literals @overload # (None) - def reshape(self, shape: None, /, *, order: _OrderACF = "C", copy: builtins.bool | None = None) -> Self: ... + def reshape(self, shape: None, /, *, order: _OrderACF = "C", copy: py_bool | None = None) -> Self: ... @overload # (empty_sequence) def reshape( # mypy false positive self, @@ -2531,7 +2530,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[()], _DTypeT_co]: ... @overload # (() | (int) | (int, int) | ....) # up to 8-d def reshape[ @@ -2552,7 +2551,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[AnyShapeT, _DTypeT_co]: ... @overload # (index) def reshape( @@ -2561,7 +2560,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[int], _DTypeT_co]: ... @overload # (index, index) def reshape( @@ -2571,7 +2570,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[int, int], _DTypeT_co]: ... @overload # (index, index, index) def reshape( @@ -2582,7 +2581,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[int, int, int], _DTypeT_co]: ... @overload # (index, index, index, index) def reshape( @@ -2594,7 +2593,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[int, int, int, int], _DTypeT_co]: ... @overload # (int, *(index, ...)) def reshape( @@ -2603,7 +2602,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): /, *shape: SupportsIndex, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[_AnyShape, _DTypeT_co]: ... @overload # (sequence[index]) def reshape( @@ -2612,7 +2611,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[_AnyShape, _DTypeT_co]: ... @overload @@ -2621,8 +2620,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): dtype: _DTypeLike[ScalarT], order: _OrderKACF = ..., casting: _CastingKind = ..., - subok: builtins.bool = ..., - copy: builtins.bool | _CopyMode = ..., + subok: py_bool = ..., + copy: py_bool | _CopyMode = ..., ) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def astype( @@ -2630,8 +2629,8 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): dtype: DTypeLike | None, order: _OrderKACF = ..., casting: _CastingKind = ..., - subok: builtins.bool = ..., - copy: builtins.bool | _CopyMode = ..., + subok: py_bool = ..., + copy: py_bool | _CopyMode = ..., ) -> ndarray[_ShapeT_co, dtype]: ... # @@ -2657,10 +2656,10 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def getfield(self, /, dtype: DTypeLike, offset: SupportsIndex = 0) -> NDArray[Any]: ... def __index__(self: NDArray[integer], /) -> int: ... - def __complex__(self: NDArray[number | np.bool | object_], /) -> complex: ... + def __complex__(self: NDArray[number | bool_ | object_], /) -> complex: ... def __len__(self) -> int: ... - def __contains__(self, value: object, /) -> builtins.bool: ... + def __contains__(self, value: object, /) -> py_bool: ... # NOTE: This weird `Never` tuple works around a strange mypy issue where it assigns # `tuple[int]` to `tuple[Never]` or `tuple[int, int]` to `tuple[Never, Never]`. @@ -2682,67 +2681,67 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # @overload - def __lt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co, /) -> NDArray[np.bool]: ... + def __lt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co, /) -> NDArray[bool_]: ... @overload - def __lt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> NDArray[np.bool]: ... + def __lt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> NDArray[bool_]: ... @overload - def __lt__(self: NDArray[datetime64], other: _ArrayLikeDT64_co, /) -> NDArray[np.bool]: ... + def __lt__(self: NDArray[datetime64], other: _ArrayLikeDT64_co, /) -> NDArray[bool_]: ... @overload - def __lt__(self: NDArray[bytes_], other: _ArrayLikeBytes_co, /) -> NDArray[np.bool]: ... + def __lt__(self: NDArray[bytes_], other: _ArrayLikeBytes_co, /) -> NDArray[bool_]: ... @overload - def __lt__(self: _ArrayString, other: _ArrayLikeStr_co | _ArrayLikeString_co, /) -> NDArray[np.bool]: ... + def __lt__(self: _ArrayString, other: _ArrayLikeStr_co | _ArrayLikeString_co, /) -> NDArray[bool_]: ... @overload - def __lt__(self: NDArray[object_], other: object, /) -> NDArray[np.bool]: ... + def __lt__(self: NDArray[object_], other: object, /) -> NDArray[bool_]: ... @overload - def __lt__(self, other: _ArrayLikeObject_co, /) -> NDArray[np.bool]: ... + def __lt__(self, other: _ArrayLikeObject_co, /) -> NDArray[bool_]: ... # @overload - def __le__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co, /) -> NDArray[np.bool]: ... + def __le__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co, /) -> NDArray[bool_]: ... @overload - def __le__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> NDArray[np.bool]: ... + def __le__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> NDArray[bool_]: ... @overload - def __le__(self: NDArray[datetime64], other: _ArrayLikeDT64_co, /) -> NDArray[np.bool]: ... + def __le__(self: NDArray[datetime64], other: _ArrayLikeDT64_co, /) -> NDArray[bool_]: ... @overload - def __le__(self: NDArray[bytes_], other: _ArrayLikeBytes_co, /) -> NDArray[np.bool]: ... + def __le__(self: NDArray[bytes_], other: _ArrayLikeBytes_co, /) -> NDArray[bool_]: ... @overload - def __le__(self: _ArrayString, other: _ArrayLikeStr_co | _ArrayLikeString_co, /) -> NDArray[np.bool]: ... + def __le__(self: _ArrayString, other: _ArrayLikeStr_co | _ArrayLikeString_co, /) -> NDArray[bool_]: ... @overload - def __le__(self: NDArray[object_], other: object, /) -> NDArray[np.bool]: ... + def __le__(self: NDArray[object_], other: object, /) -> NDArray[bool_]: ... @overload - def __le__(self, other: _ArrayLikeObject_co, /) -> NDArray[np.bool]: ... + def __le__(self, other: _ArrayLikeObject_co, /) -> NDArray[bool_]: ... # @overload - def __gt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co, /) -> NDArray[np.bool]: ... + def __gt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co, /) -> NDArray[bool_]: ... @overload - def __gt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> NDArray[np.bool]: ... + def __gt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> NDArray[bool_]: ... @overload - def __gt__(self: NDArray[datetime64], other: _ArrayLikeDT64_co, /) -> NDArray[np.bool]: ... + def __gt__(self: NDArray[datetime64], other: _ArrayLikeDT64_co, /) -> NDArray[bool_]: ... @overload - def __gt__(self: NDArray[bytes_], other: _ArrayLikeBytes_co, /) -> NDArray[np.bool]: ... + def __gt__(self: NDArray[bytes_], other: _ArrayLikeBytes_co, /) -> NDArray[bool_]: ... @overload - def __gt__(self: _ArrayString, other: _ArrayLikeStr_co | _ArrayLikeString_co, /) -> NDArray[np.bool]: ... + def __gt__(self: _ArrayString, other: _ArrayLikeStr_co | _ArrayLikeString_co, /) -> NDArray[bool_]: ... @overload - def __gt__(self: NDArray[object_], other: object, /) -> NDArray[np.bool]: ... + def __gt__(self: NDArray[object_], other: object, /) -> NDArray[bool_]: ... @overload - def __gt__(self, other: _ArrayLikeObject_co, /) -> NDArray[np.bool]: ... + def __gt__(self, other: _ArrayLikeObject_co, /) -> NDArray[bool_]: ... # @overload - def __ge__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co, /) -> NDArray[np.bool]: ... + def __ge__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co, /) -> NDArray[bool_]: ... @overload - def __ge__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> NDArray[np.bool]: ... + def __ge__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co, /) -> NDArray[bool_]: ... @overload - def __ge__(self: NDArray[datetime64], other: _ArrayLikeDT64_co, /) -> NDArray[np.bool]: ... + def __ge__(self: NDArray[datetime64], other: _ArrayLikeDT64_co, /) -> NDArray[bool_]: ... @overload - def __ge__(self: NDArray[bytes_], other: _ArrayLikeBytes_co, /) -> NDArray[np.bool]: ... + def __ge__(self: NDArray[bytes_], other: _ArrayLikeBytes_co, /) -> NDArray[bool_]: ... @overload - def __ge__(self: _ArrayString, other: _ArrayLikeStr_co | _ArrayLikeString_co, /) -> NDArray[np.bool]: ... + def __ge__(self: _ArrayString, other: _ArrayLikeStr_co | _ArrayLikeString_co, /) -> NDArray[bool_]: ... @overload - def __ge__(self: NDArray[object_], other: object, /) -> NDArray[np.bool]: ... + def __ge__(self: NDArray[object_], other: object, /) -> NDArray[bool_]: ... @overload - def __ge__(self, other: _ArrayLikeObject_co, /) -> NDArray[np.bool]: ... + def __ge__(self, other: _ArrayLikeObject_co, /) -> NDArray[bool_]: ... # Unary ops @@ -2772,9 +2771,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload def __matmul__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __matmul__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __matmul__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload - def __matmul__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __matmul__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __matmul__(self: NDArray[floating[_64Bit]], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -2801,9 +2800,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload # signature equivalent to __matmul__ def __rmatmul__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __rmatmul__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __rmatmul__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload - def __rmatmul__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __rmatmul__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __rmatmul__(self: NDArray[floating[_64Bit]], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -2829,14 +2828,14 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload def __mod__[ScalarT: floating | integer]( - self: NDArray[ScalarT], other: int | np.bool, / + self: NDArray[ScalarT], other: int | bool_, / ) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __mod__[ScalarT: floating | integer](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __mod__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... + def __mod__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... @overload - def __mod__[ScalarT: floating | integer](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __mod__[ScalarT: floating | integer](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __mod__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -2856,14 +2855,14 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload # signature equivalent to __mod__ def __rmod__[ScalarT: floating | integer]( - self: NDArray[ScalarT], other: int | np.bool, / + self: NDArray[ScalarT], other: int | bool_, / ) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __rmod__[ScalarT: floating | integer](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __rmod__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... + def __rmod__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... @overload - def __rmod__[ScalarT: floating | integer](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __rmod__[ScalarT: floating | integer](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __rmod__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -2883,17 +2882,17 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload def __divmod__[ScalarT: floating | integer]( - self: NDArray[ScalarT], rhs: int | np.bool, / + self: NDArray[ScalarT], rhs: int | bool_, / ) -> _2Tuple[ndarray[_ShapeT_co, dtype[ScalarT]]]: ... @overload def __divmod__[ScalarT: floating | integer]( self: NDArray[ScalarT], rhs: _ArrayLikeBool_co, / ) -> _2Tuple[NDArray[ScalarT]]: ... @overload - def __divmod__(self: NDArray[np.bool], rhs: _ArrayLikeBool_co, /) -> _2Tuple[NDArray[int8]]: ... + def __divmod__(self: NDArray[bool_], rhs: _ArrayLikeBool_co, /) -> _2Tuple[NDArray[int8]]: ... @overload def __divmod__[ScalarT: floating | integer]( - self: NDArray[np.bool], rhs: _ArrayLike[ScalarT], / + self: NDArray[bool_], rhs: _ArrayLike[ScalarT], / ) -> _2Tuple[NDArray[ScalarT]]: ... @overload def __divmod__(self: NDArray[float64], rhs: _ArrayLikeFloat64_co, /) -> _2Tuple[NDArray[float64]]: ... @@ -2910,17 +2909,17 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): @overload # signature equivalent to __divmod__ def __rdivmod__[ScalarT: floating | integer]( - self: NDArray[ScalarT], lhs: int | np.bool, / + self: NDArray[ScalarT], lhs: int | bool_, / ) -> _2Tuple[ndarray[_ShapeT_co, dtype[ScalarT]]]: ... @overload def __rdivmod__[ScalarT: floating | integer]( self: NDArray[ScalarT], lhs: _ArrayLikeBool_co, / ) -> _2Tuple[NDArray[ScalarT]]: ... @overload - def __rdivmod__(self: NDArray[np.bool], lhs: _ArrayLikeBool_co, /) -> _2Tuple[NDArray[int8]]: ... + def __rdivmod__(self: NDArray[bool_], lhs: _ArrayLikeBool_co, /) -> _2Tuple[NDArray[int8]]: ... @overload def __rdivmod__[ScalarT: floating | integer]( - self: NDArray[np.bool], lhs: _ArrayLike[ScalarT], / + self: NDArray[bool_], lhs: _ArrayLike[ScalarT], / ) -> _2Tuple[NDArray[ScalarT]]: ... @overload def __rdivmod__(self: NDArray[float64], lhs: _ArrayLikeFloat64_co, /) -> _2Tuple[NDArray[float64]]: ... @@ -2937,13 +2936,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__add__` @overload - def __add__[ScalarT: number](self: NDArray[ScalarT], other: int | np.bool, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... + def __add__[ScalarT: number](self: NDArray[ScalarT], other: int | bool_, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __add__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __add__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __add__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload - def __add__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __add__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __add__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -2985,13 +2984,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__radd__` @overload # signature equivalent to __add__ - def __radd__[ScalarT: number](self: NDArray[ScalarT], other: int | np.bool, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... + def __radd__[ScalarT: number](self: NDArray[ScalarT], other: int | bool_, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __radd__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __radd__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __radd__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload - def __radd__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __radd__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __radd__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -3033,13 +3032,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__sub__` @overload - def __sub__[ScalarT: number](self: NDArray[ScalarT], other: int | np.bool, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... + def __sub__[ScalarT: number](self: NDArray[ScalarT], other: int | bool_, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __sub__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __sub__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NoReturn: ... + def __sub__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NoReturn: ... @overload - def __sub__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __sub__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __sub__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -3071,13 +3070,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__rsub__` @overload - def __rsub__[ScalarT: number](self: NDArray[ScalarT], other: int | np.bool, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... + def __rsub__[ScalarT: number](self: NDArray[ScalarT], other: int | bool_, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __rsub__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __rsub__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NoReturn: ... + def __rsub__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NoReturn: ... @overload - def __rsub__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __rsub__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __rsub__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -3109,13 +3108,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__mul__` @overload - def __mul__[ScalarT: number](self: NDArray[ScalarT], other: int | np.bool, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... + def __mul__[ScalarT: number](self: NDArray[ScalarT], other: int | bool_, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __mul__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __mul__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __mul__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload - def __mul__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __mul__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __mul__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -3151,13 +3150,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__rmul__` @overload # signature equivalent to __mul__ - def __rmul__[ScalarT: number](self: NDArray[ScalarT], other: int | np.bool, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... + def __rmul__[ScalarT: number](self: NDArray[ScalarT], other: int | bool_, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __rmul__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __rmul__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __rmul__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload - def __rmul__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __rmul__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __rmul__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -3256,14 +3255,14 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__floordiv__` @overload def __floordiv__[ScalarT: integer | floating]( - self: NDArray[ScalarT], other: int | np.bool, / + self: NDArray[ScalarT], other: int | bool_, / ) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __floordiv__[ScalarT: integer | floating](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __floordiv__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... + def __floordiv__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... @overload - def __floordiv__[ScalarT: integer | floating](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __floordiv__[ScalarT: integer | floating](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __floordiv__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -3288,14 +3287,14 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__rfloordiv__` @overload def __rfloordiv__[ScalarT: integer | floating]( - self: NDArray[ScalarT], other: int | np.bool, / + self: NDArray[ScalarT], other: int | bool_, / ) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __rfloordiv__[ScalarT: integer | floating](self: NDArray[ScalarT], other: _ArrayLikeBool_co, /) -> NDArray[ScalarT]: ... @overload - def __rfloordiv__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... + def __rfloordiv__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... @overload - def __rfloordiv__[ScalarT: integer | floating](self: NDArray[np.bool], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... + def __rfloordiv__[ScalarT: integer | floating](self: NDArray[bool_], other: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... @overload def __rfloordiv__(self: NDArray[float64], other: _ArrayLikeFloat64_co, /) -> NDArray[float64]: ... @overload @@ -3317,13 +3316,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__pow__` @overload - def __pow__[ScalarT: number](self: NDArray[ScalarT], other: int | np.bool, mod: None = None, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... + def __pow__[ScalarT: number](self: NDArray[ScalarT], other: int | bool_, mod: None = None, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __pow__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, mod: None = None, /) -> NDArray[ScalarT]: ... @overload - def __pow__(self: NDArray[np.bool], other: _ArrayLikeBool_co, mod: None = None, /) -> NDArray[int8]: ... + def __pow__(self: NDArray[bool_], other: _ArrayLikeBool_co, mod: None = None, /) -> NDArray[int8]: ... @overload - def __pow__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], mod: None = None, /) -> NDArray[ScalarT]: ... + def __pow__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], mod: None = None, /) -> NDArray[ScalarT]: ... @overload def __pow__(self: NDArray[float64], other: _ArrayLikeFloat64_co, mod: None = None, /) -> NDArray[float64]: ... @overload @@ -3351,13 +3350,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): # Keep in sync with `MaskedArray.__rpow__` @overload - def __rpow__[ScalarT: number](self: NDArray[ScalarT], other: int | np.bool, mod: None = None, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... + def __rpow__[ScalarT: number](self: NDArray[ScalarT], other: int | bool_, mod: None = None, /) -> ndarray[_ShapeT_co, dtype[ScalarT]]: ... @overload def __rpow__[ScalarT: number](self: NDArray[ScalarT], other: _ArrayLikeBool_co, mod: None = None, /) -> NDArray[ScalarT]: ... @overload - def __rpow__(self: NDArray[np.bool], other: _ArrayLikeBool_co, mod: None = None, /) -> NDArray[int8]: ... + def __rpow__(self: NDArray[bool_], other: _ArrayLikeBool_co, mod: None = None, /) -> NDArray[int8]: ... @overload - def __rpow__[ScalarT: number](self: NDArray[np.bool], other: _ArrayLike[ScalarT], mod: None = None, /) -> NDArray[ScalarT]: ... + def __rpow__[ScalarT: number](self: NDArray[bool_], other: _ArrayLike[ScalarT], mod: None = None, /) -> NDArray[ScalarT]: ... @overload def __rpow__(self: NDArray[float64], other: _ArrayLikeFloat64_co, mod: None = None, /) -> NDArray[float64]: ... @overload @@ -3384,7 +3383,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __rpow__(self: NDArray[Any], other: _ArrayLikeObject_co, mod: None = None, /) -> Any: ... @overload - def __lshift__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... + def __lshift__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... @overload def __lshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3395,7 +3394,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __lshift__(self: NDArray[Any], other: _ArrayLikeObject_co, /) -> Any: ... @overload - def __rlshift__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... + def __rlshift__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... @overload def __rlshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3406,7 +3405,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __rlshift__(self: NDArray[Any], other: _ArrayLikeObject_co, /) -> Any: ... @overload - def __rshift__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... + def __rshift__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... @overload def __rshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3417,7 +3416,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __rshift__(self: NDArray[Any], other: _ArrayLikeObject_co, /) -> Any: ... @overload - def __rrshift__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... + def __rrshift__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[int8]: ... @overload def __rrshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3428,7 +3427,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __rrshift__(self: NDArray[Any], other: _ArrayLikeObject_co, /) -> Any: ... @overload - def __and__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __and__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload def __and__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3439,7 +3438,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __and__(self: NDArray[Any], other: _ArrayLikeObject_co, /) -> Any: ... @overload - def __rand__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __rand__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload def __rand__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3450,7 +3449,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __rand__(self: NDArray[Any], other: _ArrayLikeObject_co, /) -> Any: ... @overload - def __xor__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __xor__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload def __xor__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3461,7 +3460,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __xor__(self: NDArray[Any], other: _ArrayLikeObject_co, /) -> Any: ... @overload - def __rxor__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __rxor__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload def __rxor__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3472,7 +3471,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __rxor__(self: NDArray[Any], other: _ArrayLikeObject_co, /) -> Any: ... @overload - def __or__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __or__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload def __or__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3483,7 +3482,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): def __or__(self: NDArray[Any], other: _ArrayLikeObject_co, /) -> Any: ... @overload - def __ror__(self: NDArray[np.bool], other: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... + def __ror__(self: NDArray[bool_], other: _ArrayLikeBool_co, /) -> NDArray[bool_]: ... @overload def __ror__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... @overload @@ -3645,7 +3644,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]): stream: int | Any | None = None, max_version: tuple[int, int] | None = None, dl_device: tuple[int, int] | None = None, - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> CapsuleType: ... def __dlpack_device__(self, /) -> tuple[L[1], L[0]]: ... @@ -3765,9 +3764,9 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): # NOTE: this wont't raise, but won't do anything either @overload - def resize(self, /, *, refcheck: builtins.bool = True) -> None: ... + def resize(self, /, *, refcheck: py_bool = True) -> None: ... @overload - def resize(self, new_shape: L[0, -1] | tuple[L[0, -1]] | tuple[()], /, *, refcheck: builtins.bool = True) -> None: ... + def resize(self, new_shape: L[0, -1] | tuple[L[0, -1]] | tuple[()], /, *, refcheck: py_bool = True) -> None: ... # def byteswap(self, /, inplace: L[False] = False) -> Self: ... @@ -3780,8 +3779,8 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): dtype: _DTypeLike[ScalarT], order: _OrderKACF = "K", casting: _CastingKind = "unsafe", - subok: builtins.bool = True, - copy: builtins.bool | _CopyMode = True, + subok: py_bool = True, + copy: py_bool | _CopyMode = True, ) -> ScalarT: ... @overload def astype( @@ -3790,8 +3789,8 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): dtype: DTypeLike | None, order: _OrderKACF = "K", casting: _CastingKind = "unsafe", - subok: builtins.bool = True, - copy: builtins.bool | _CopyMode = True, + subok: py_bool = True, + copy: py_bool | _CopyMode = True, ) -> Incomplete: ... # NOTE: `view` will perform a 0D->scalar cast, @@ -3857,7 +3856,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> Self: ... @overload # (ShapeT: (index, ...)) def reshape[ShapeT: tuple[int, *tuple[int, ...]]]( @@ -3866,7 +3865,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[ShapeT, dtype[Self]]: ... @overload # (Sequence[index, ...]) # not recommended def reshape( @@ -3875,7 +3874,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> NDArray[Self] | Any: ... @overload # _(index) def reshape( @@ -3884,7 +3883,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[int], dtype[Self]]: ... @overload # _(index, index) def reshape( @@ -3894,7 +3893,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[int, int], dtype[Self]]: ... @overload # _(index, index, index) def reshape( @@ -3905,7 +3904,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[int, int, int], dtype[Self]]: ... @overload # _(index, index, index, index) def reshape( @@ -3917,7 +3916,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): /, *, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[int, int, int, int], dtype[Self]]: ... @overload # _(index, index, index, index, index, *index) # ndim >= 5 def reshape( @@ -3930,7 +3929,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): /, *sizes6_: SupportsIndex, order: _OrderACF = "C", - copy: builtins.bool | None = None, + copy: py_bool | None = None, ) -> ndarray[tuple[int, int, int, int, int, *tuple[int, ...]], dtype[Self]]: ... def squeeze(self, axis: L[0] | tuple[()] | None = ...) -> Self: ... @@ -3944,8 +3943,8 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): out: None = None, keepdims: SupportsIndex = False, *, - where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True - ) -> np.bool: ... + where: py_bool | bool_ | ndarray[tuple[()], dtype[bool_]] = True + ) -> bool_: ... @overload def all[ScalarT: generic]( self, @@ -3954,7 +3953,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): out: ndarray[tuple[()], dtype[ScalarT]], keepdims: SupportsIndex = False, *, - where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True, + where: py_bool | bool_ | ndarray[tuple[()], dtype[bool_]] = True, ) -> ScalarT: ... @overload def all[ScalarT: generic]( @@ -3964,7 +3963,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): *, out: ndarray[tuple[()], dtype[ScalarT]], keepdims: SupportsIndex = False, - where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True, + where: py_bool | bool_ | ndarray[tuple[()], dtype[bool_]] = True, ) -> ScalarT: ... @overload @@ -3975,8 +3974,8 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): out: None = None, keepdims: SupportsIndex = False, *, - where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True - ) -> np.bool: ... + where: py_bool | bool_ | ndarray[tuple[()], dtype[bool_]] = True + ) -> bool_: ... @overload def any[ScalarT: generic]( self, @@ -3985,7 +3984,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): out: ndarray[tuple[()], dtype[ScalarT]], keepdims: SupportsIndex = False, *, - where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True, + where: py_bool | bool_ | ndarray[tuple[()], dtype[bool_]] = True, ) -> ScalarT: ... @overload def any[ScalarT: generic]( @@ -3995,7 +3994,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]): *, out: ndarray[tuple[()], dtype[ScalarT]], keepdims: SupportsIndex = False, - where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True, + where: py_bool | bool_ | ndarray[tuple[()], dtype[bool_]] = True, ) -> ScalarT: ... # Keep `dtype` at the bottom to avoid name conflicts with `np.dtype` @@ -4058,41 +4057,41 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @property def real(self) -> Self: ... @property - def imag(self) -> np.bool[L[False]]: ... + def imag(self) -> bool_[L[False]]: ... @overload # mypy bug workaround: https://github.com/numpy/numpy/issues/29245 - def __new__(cls, value: Never, /) -> np.bool[builtins.bool]: ... + def __new__(cls, value: Never, /) -> bool_[py_bool]: ... @overload - def __new__(cls, value: _Falsy = ..., /) -> np.bool[L[False]]: ... + def __new__(cls, value: _Falsy = ..., /) -> bool_[L[False]]: ... @overload - def __new__(cls, value: _Truthy, /) -> np.bool[L[True]]: ... + def __new__(cls, value: _Truthy, /) -> bool_[L[True]]: ... @overload - def __new__(cls, value: object, /) -> np.bool[builtins.bool]: ... + def __new__(cls, value: object, /) -> bool_[py_bool]: ... def __class_getitem__(cls, type_arg: type | object, /) -> GenericAlias: ... def __bool__(self, /) -> _BoolItemT_co: ... @overload - def __int__(self: np.bool[L[False]], /) -> L[0]: ... + def __int__(self: bool_[L[False]], /) -> L[0]: ... @overload - def __int__(self: np.bool[L[True]], /) -> L[1]: ... + def __int__(self: bool_[L[True]], /) -> L[1]: ... @overload def __int__(self, /) -> L[0, 1]: ... def __abs__(self) -> Self: ... @overload - def __invert__(self: np.bool[L[False]], /) -> np.bool[L[True]]: ... + def __invert__(self: bool_[L[False]], /) -> bool_[L[True]]: ... @overload - def __invert__(self: np.bool[L[True]], /) -> np.bool[L[False]]: ... + def __invert__(self: bool_[L[True]], /) -> bool_[L[False]]: ... @overload - def __invert__(self, /) -> np.bool: ... + def __invert__(self, /) -> bool_: ... @overload def __add__[ScalarT: number](self, other: ScalarT, /) -> ScalarT: ... @overload - def __add__(self, other: builtins.bool | bool_, /) -> bool_: ... + def __add__(self, other: py_bool | bool_, /) -> bool_: ... @overload def __add__(self, other: int, /) -> int_: ... @overload @@ -4103,7 +4102,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __radd__[ScalarT: number](self, other: ScalarT, /) -> ScalarT: ... @overload - def __radd__(self, other: builtins.bool, /) -> bool_: ... + def __radd__(self, other: py_bool, /) -> bool_: ... @overload def __radd__(self, other: int, /) -> int_: ... @overload @@ -4132,7 +4131,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __mul__[ScalarT: number](self, other: ScalarT, /) -> ScalarT: ... @overload - def __mul__(self, other: builtins.bool | bool_, /) -> bool_: ... + def __mul__(self, other: py_bool | bool_, /) -> bool_: ... @overload def __mul__(self, other: int, /) -> int_: ... @overload @@ -4143,7 +4142,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __rmul__[ScalarT: number](self, other: ScalarT, /) -> ScalarT: ... @overload - def __rmul__(self, other: builtins.bool, /) -> bool_: ... + def __rmul__(self, other: py_bool, /) -> bool_: ... @overload def __rmul__(self, other: int, /) -> int_: ... @overload @@ -4154,7 +4153,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __pow__[ScalarT: number](self, other: ScalarT, mod: None = None, /) -> ScalarT: ... @overload - def __pow__(self, other: builtins.bool | bool_, mod: None = None, /) -> int8: ... + def __pow__(self, other: py_bool | bool_, mod: None = None, /) -> int8: ... @overload def __pow__(self, other: int, mod: None = None, /) -> int_: ... @overload @@ -4165,7 +4164,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __rpow__[ScalarT: number](self, other: ScalarT, mod: None = None, /) -> ScalarT: ... @overload - def __rpow__(self, other: builtins.bool, mod: None = None, /) -> int8: ... + def __rpow__(self, other: py_bool, mod: None = None, /) -> int8: ... @overload def __rpow__(self, other: int, mod: None = None, /) -> int_: ... @overload @@ -4190,7 +4189,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __floordiv__[ScalarT: integer | floating](self, other: ScalarT, /) -> ScalarT: ... @overload - def __floordiv__(self, other: builtins.bool | bool_, /) -> int8: ... + def __floordiv__(self, other: py_bool | bool_, /) -> int8: ... @overload def __floordiv__(self, other: int, /) -> int_: ... @overload @@ -4199,7 +4198,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __rfloordiv__[ScalarT: integer | floating](self, other: ScalarT, /) -> ScalarT: ... @overload - def __rfloordiv__(self, other: builtins.bool, /) -> int8: ... + def __rfloordiv__(self, other: py_bool, /) -> int8: ... @overload def __rfloordiv__(self, other: int, /) -> int_: ... @overload @@ -4209,7 +4208,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __mod__[ScalarT: integer | floating](self, other: ScalarT, /) -> ScalarT: ... @overload - def __mod__(self, other: builtins.bool | bool_, /) -> int8: ... + def __mod__(self, other: py_bool | bool_, /) -> int8: ... @overload def __mod__(self, other: int, /) -> int_: ... @overload @@ -4219,7 +4218,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __rmod__[ScalarT: integer | floating](self, other: ScalarT, /) -> ScalarT: ... @overload - def __rmod__(self, other: builtins.bool, /) -> int8: ... + def __rmod__(self, other: py_bool, /) -> int8: ... @overload def __rmod__(self, other: int, /) -> int_: ... @overload @@ -4229,7 +4228,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __divmod__[ScalarT: integer | floating](self, other: ScalarT, /) -> _2Tuple[ScalarT]: ... @overload - def __divmod__(self, other: builtins.bool | bool_, /) -> _2Tuple[int8]: ... + def __divmod__(self, other: py_bool | bool_, /) -> _2Tuple[int8]: ... @overload def __divmod__(self, other: int, /) -> _2Tuple[int_]: ... @overload @@ -4239,7 +4238,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __rdivmod__[ScalarT: integer | floating](self, other: ScalarT, /) -> _2Tuple[ScalarT]: ... @overload - def __rdivmod__(self, other: builtins.bool, /) -> _2Tuple[int8]: ... + def __rdivmod__(self, other: py_bool, /) -> _2Tuple[int8]: ... @overload def __rdivmod__(self, other: int, /) -> _2Tuple[int_]: ... @overload @@ -4248,14 +4247,14 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __lshift__[ScalarT: integer](self, other: ScalarT, /) -> ScalarT: ... @overload - def __lshift__(self, other: builtins.bool | bool_, /) -> int8: ... + def __lshift__(self, other: py_bool | bool_, /) -> int8: ... @overload def __lshift__(self, other: int, /) -> int_: ... @overload def __rlshift__[ScalarT: integer](self, other: ScalarT, /) -> ScalarT: ... @overload - def __rlshift__(self, other: builtins.bool, /) -> int8: ... + def __rlshift__(self, other: py_bool, /) -> int8: ... @overload def __rlshift__(self, other: int, /) -> int_: ... @@ -4263,7 +4262,7 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __rshift__[ScalarT: integer](self, other: ScalarT, /) -> ScalarT: ... @overload - def __rshift__(self, other: builtins.bool | bool_, /) -> int8: ... + def __rshift__(self, other: py_bool | bool_, /) -> int8: ... @overload def __rshift__(self, other: int, /) -> int_: ... @@ -4271,50 +4270,50 @@ class bool(generic[_BoolItemT_co], Generic[_BoolItemT_co]): @overload def __rrshift__[ScalarT: integer](self, other: ScalarT, /) -> ScalarT: ... @overload - def __rrshift__(self, other: builtins.bool, /) -> int8: ... + def __rrshift__(self, other: py_bool, /) -> int8: ... @overload def __rrshift__(self, other: int, /) -> int_: ... @overload - def __and__(self: np.bool[L[False]], other: builtins.bool | np.bool, /) -> np.bool[L[False]]: ... + def __and__(self: bool_[L[False]], other: py_bool | bool_, /) -> bool_[L[False]]: ... @overload - def __and__(self, other: L[False] | np.bool[L[False]], /) -> np.bool[L[False]]: ... + def __and__(self, other: L[False] | bool_[L[False]], /) -> bool_[L[False]]: ... @overload - def __and__(self, other: L[True] | np.bool[L[True]], /) -> Self: ... + def __and__(self, other: L[True] | bool_[L[True]], /) -> Self: ... @overload - def __and__(self, other: builtins.bool | np.bool, /) -> np.bool: ... + def __and__(self, other: py_bool | bool_, /) -> bool_: ... @overload def __and__[ScalarT: integer](self, other: ScalarT, /) -> ScalarT: ... @overload - def __and__(self, other: int, /) -> np.bool | intp: ... + def __and__(self, other: int, /) -> bool_ | intp: ... __rand__ = __and__ @overload - def __xor__[ItemT: builtins.bool](self: np.bool[L[False]], other: ItemT | np.bool[ItemT], /) -> np.bool[ItemT]: ... + def __xor__[ItemT: py_bool](self: bool_[L[False]], other: ItemT | bool_[ItemT], /) -> bool_[ItemT]: ... @overload - def __xor__(self: np.bool[L[True]], other: L[True] | np.bool[L[True]], /) -> np.bool[L[False]]: ... + def __xor__(self: bool_[L[True]], other: L[True] | bool_[L[True]], /) -> bool_[L[False]]: ... @overload - def __xor__(self, other: L[False] | np.bool[L[False]], /) -> Self: ... + def __xor__(self, other: L[False] | bool_[L[False]], /) -> Self: ... @overload - def __xor__(self, other: builtins.bool | np.bool, /) -> np.bool: ... + def __xor__(self, other: py_bool | bool_, /) -> bool_: ... @overload def __xor__[ScalarT: integer](self, other: ScalarT, /) -> ScalarT: ... @overload - def __xor__(self, other: int, /) -> np.bool | intp: ... + def __xor__(self, other: int, /) -> bool_ | intp: ... __rxor__ = __xor__ @overload - def __or__(self: np.bool[L[True]], other: builtins.bool | np.bool, /) -> np.bool[L[True]]: ... + def __or__(self: bool_[L[True]], other: py_bool | bool_, /) -> bool_[L[True]]: ... @overload - def __or__(self, other: L[False] | np.bool[L[False]], /) -> Self: ... + def __or__(self, other: L[False] | bool_[L[False]], /) -> Self: ... @overload - def __or__(self, other: L[True] | np.bool[L[True]], /) -> np.bool[L[True]]: ... + def __or__(self, other: L[True] | bool_[L[True]], /) -> bool_[L[True]]: ... @overload - def __or__(self, other: builtins.bool | np.bool, /) -> np.bool: ... + def __or__(self, other: py_bool | bool_, /) -> bool_: ... @overload def __or__[ScalarT: integer](self, other: ScalarT, /) -> ScalarT: ... @overload - def __or__(self, other: int, /) -> np.bool | intp: ... + def __or__(self, other: int, /) -> bool_ | intp: ... __ror__ = __or__ @overload @@ -5063,7 +5062,7 @@ class floating(_RealMixin, _RoundMixin, inexact[_NBitT, float]): def __rdivmod__(self, other: float, /) -> _2Tuple[Self]: ... # NOTE: `is_integer` and `as_integer_ratio` are technically defined in the concrete subtypes - def is_integer(self, /) -> builtins.bool: ... + def is_integer(self, /) -> py_bool: ... def as_integer_ratio(self, /) -> tuple[int, int]: ... float16 = floating[_16Bit] @@ -5487,7 +5486,7 @@ class timedelta64(_IntegralMixin, generic[_TD64ItemT_co], Generic[_TD64ItemT_co] @overload def __mul__(self, x: _IntLike_co, /) -> Self: ... @overload - def __mul__(self, x: float | np.floating, /) -> timedelta64[_TD64ItemT_co | None]: ... + def __mul__(self, x: float | floating, /) -> timedelta64[_TD64ItemT_co | None]: ... @overload def __mul__(self, x: _FloatLike_co, /) -> timedelta64: ... __rmul__ = __mul__ @@ -5900,7 +5899,7 @@ class ufunc: *, signature: tuple[dtype | None, ...] | None = None, casting: _CastingKind | None = None, - reduction: builtins.bool = False, + reduction: py_bool = False, ) -> tuple[dtype, ...]: ... # Parameters: `__name__`, `ntypes` and `identity` @@ -6102,24 +6101,24 @@ class nditer: def copy(self) -> nditer: ... def debug_print(self) -> None: ... def enable_external_loop(self) -> None: ... - def iternext(self) -> builtins.bool: ... + def iternext(self) -> py_bool: ... def remove_axis(self, i: SupportsIndex, /) -> None: ... def remove_multi_index(self) -> None: ... def reset(self) -> None: ... @property def dtypes(self) -> tuple[dtype, ...]: ... @property - def finished(self) -> builtins.bool: ... + def finished(self) -> py_bool: ... @property - def has_delayed_bufalloc(self) -> builtins.bool: ... + def has_delayed_bufalloc(self) -> py_bool: ... @property - def has_index(self) -> builtins.bool: ... + def has_index(self) -> py_bool: ... @property - def has_multi_index(self) -> builtins.bool: ... + def has_multi_index(self) -> py_bool: ... @property def index(self) -> int: ... @property - def iterationneedsapi(self) -> builtins.bool: ... + def iterationneedsapi(self) -> py_bool: ... @property def iterindex(self) -> int: ... @property @@ -6181,7 +6180,7 @@ class memmap(ndarray[_ShapeT_co, _DTypeT_co]): self, array: memmap[_ShapeT_co, _DTypeT_co], context: tuple[ufunc, tuple[Any, ...], int] | None = None, - return_scalar: builtins.bool = False, + return_scalar: py_bool = False, ) -> Any: ... def flush(self) -> None: ... @@ -6220,9 +6219,9 @@ class poly1d: __hash__: ClassVar[None] # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride] @overload - def __array__(self, /, t: None = None, copy: builtins.bool | None = None) -> ndarray[tuple[int]]: ... + def __array__(self, /, t: None = None, copy: py_bool | None = None) -> ndarray[tuple[int]]: ... @overload - def __array__[DTypeT: dtype](self, /, t: DTypeT, copy: builtins.bool | None = None) -> ndarray[tuple[int], DTypeT]: ... + def __array__[DTypeT: dtype](self, /, t: DTypeT, copy: py_bool | None = None) -> ndarray[tuple[int], DTypeT]: ... @overload def __call__(self, val: _ScalarLike_co) -> Any: ... @@ -6234,7 +6233,7 @@ class poly1d: def __init__( self, c_or_r: ArrayLike, - r: builtins.bool = False, + r: py_bool = False, variable: str | None = None, ) -> None: ... def __len__(self) -> int: ... @@ -6264,5 +6263,5 @@ def from_dlpack( /, *, device: L["cpu"] | None = None, - copy: builtins.bool | None = None, -) -> NDArray[number | np.bool]: ... + copy: py_bool | None = None, +) -> NDArray[number | bool_]: ... diff --git a/numpy/linalg/_linalg.pyi b/numpy/linalg/_linalg.pyi index 38926e84d0a6..010a378ea2a7 100644 --- a/numpy/linalg/_linalg.pyi +++ b/numpy/linalg/_linalg.pyi @@ -5,30 +5,22 @@ from typing import ( Literal as L, NamedTuple, Never, + Protocol, SupportsIndex, - SupportsInt, overload, + type_check_only, ) from typing_extensions import TypeVar import numpy as np -from numpy import ( - complexfloating, - float64, - floating, - int32, - object_, - signedinteger, - timedelta64, - unsignedinteger, - vecdot, -) +from numpy import complexfloating, floating, signedinteger, unsignedinteger, vecdot from numpy._core.fromnumeric import matrix_transpose from numpy._globals import _NoValue, _NoValueType from numpy._typing import ( ArrayLike, DTypeLike, NDArray, + _AnyShape, _ArrayLike, _ArrayLikeBool_co, _ArrayLikeComplex_co, @@ -37,7 +29,10 @@ from numpy._typing import ( _ArrayLikeObject_co, _ArrayLikeTD64_co, _ArrayLikeUInt_co, + _ComplexLike_co, + _DTypeLike, _NestedSequence, + _Shape, _ShapeLike, ) from numpy.linalg import LinAlgError @@ -78,19 +73,38 @@ __all__ = [ ] type _AtMost1D = tuple[()] | tuple[int] +type _AtLeast2D = tuple[int, int, *tuple[int, ...]] type _AtLeast3D = tuple[int, int, int, *tuple[int, ...]] type _AtLeast4D = tuple[int, int, int, int, *tuple[int, ...]] type _JustAnyShape = tuple[Never, ...] # workaround for microsoft/pyright#10232 type _tuple2[T] = tuple[T, T] +type _Ax2 = SupportsIndex | _tuple2[SupportsIndex] type _inexact32 = np.float32 | np.complex64 -type _to_float64 = np.float64 | np.integer | np.bool +type _inexact80 = np.longdouble | np.clongdouble +type _to_integer = np.integer | np.bool +type _to_timedelta64 = np.timedelta64 | _to_integer +type _to_float64 = np.float64 | _to_integer type _to_inexact64 = np.complex128 | _to_float64 +type _to_inexact64_unsafe = _to_inexact64 | np.datetime64 | np.timedelta64 | np.character +type _to_complex = np.number | np.bool type _Array2D[ScalarT: np.generic] = np.ndarray[tuple[int, int], np.dtype[ScalarT]] type _Array3ND[ScalarT: np.generic] = np.ndarray[_AtLeast3D, np.dtype[ScalarT]] +# ==2d +type _ArrayLike2D[ScalarT: np.generic] = _SupportsArray[tuple[int, int], np.dtype[ScalarT]] | Sequence[Sequence[ScalarT]] +# >=2d +type _ArrayLike2ND[ScalarT: np.generic] = _SupportsArray[_AtLeast2D, np.dtype[ScalarT]] | _NestedSequence[Sequence[ScalarT]] +# >=3d +type _ArrayLike3ND[ScalarT: np.generic] = ( + _SupportsArray[_AtLeast3D, np.dtype[ScalarT]] + | _NestedSequence[Sequence[Sequence[ScalarT]]] +) + +type _ToArray1D[ScalarT: np.generic] = _SupportsArray[tuple[int], np.dtype[ScalarT]] + # anything that safe-casts (from floating) into float64/complex128 type _ToArrayF64 = _ArrayLike[_to_float64] | _NestedSequence[float] type _ToArrayC128 = _ArrayLike[_to_inexact64] | _NestedSequence[complex] @@ -108,11 +122,23 @@ type _SideKind = L["L", "U", "l", "u"] type _NonNegInt = L[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] type _NegInt = L[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16] +type _LstSqResult[ShapeT: tuple[int, ...], InexactT: np.inexact, FloatingT: np.floating] = tuple[ + np.ndarray[ShapeT, np.dtype[InexactT]], # least-squares solution + np.ndarray[tuple[int], np.dtype[FloatingT]], # residuals + np.int32, # rank + np.ndarray[tuple[int], np.dtype[FloatingT]], # singular values +] + _FloatingT_co = TypeVar("_FloatingT_co", bound=np.floating, default=Any, covariant=True) _FloatingOrArrayT_co = TypeVar("_FloatingOrArrayT_co", bound=np.floating | NDArray[np.floating], default=Any, covariant=True) _InexactT_co = TypeVar("_InexactT_co", bound=np.inexact, default=Any, covariant=True) _InexactOrArrayT_co = TypeVar("_InexactOrArrayT_co", bound=np.inexact | NDArray[np.inexact], default=Any, covariant=True) +# shape-typed variant of numpy._typing._SupportsArray +@type_check_only +class _SupportsArray[ShapeT: _Shape, DTypeT: np.dtype](Protocol): + def __array__(self, /) -> np.ndarray[ShapeT, DTypeT]: ... + ### fortran_int = np.intc @@ -140,42 +166,45 @@ class SlogdetResult(NamedTuple, Generic[_FloatingOrArrayT_co, _InexactOrArrayT_c sign: _FloatingOrArrayT_co logabsdet: _InexactOrArrayT_co -# TODO: narrow return types -@overload -def tensorsolve( - a: _ArrayLikeInt_co, - b: _ArrayLikeInt_co, - axes: Iterable[int] | None = None, -) -> NDArray[float64]: ... -@overload -def tensorsolve( - a: _ArrayLikeFloat_co, - b: _ArrayLikeFloat_co, - axes: Iterable[int] | None = None, -) -> NDArray[floating]: ... -@overload -def tensorsolve( - a: _ArrayLikeComplex_co, - b: _ArrayLikeComplex_co, - axes: Iterable[int] | None = None, -) -> NDArray[complexfloating]: ... +# keep in sync with `solve` +@overload # ~float64, +float64 +def tensorsolve(a: _ToArrayF64, b: _ArrayLikeFloat_co, axes: Iterable[int] | None = None) -> NDArray[np.float64]: ... +@overload # +float64, ~float64 +def tensorsolve(a: _ArrayLikeFloat_co, b: _ToArrayF64, axes: Iterable[int] | None = None) -> NDArray[np.float64]: ... +@overload # ~float32, ~float32 +def tensorsolve(a: _ArrayLike[np.float32], b: _ArrayLike[np.float32], axes: Iterable[int] | None = None) -> NDArray[np.float32]: ... +@overload # +float, +float +def tensorsolve(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, axes: Iterable[int] | None = None) -> NDArray[np.float64 | Any]: ... +@overload # ~complex128, +complex128 +def tensorsolve(a: _AsArrayC128, b: _ArrayLikeComplex_co, axes: Iterable[int] | None = None) -> NDArray[np.complex128]: ... +@overload # +complex128, ~complex128 +def tensorsolve(a: _ArrayLikeComplex_co, b: _AsArrayC128, axes: Iterable[int] | None = None) -> NDArray[np.complex128]: ... +@overload # ~complex64, +complex64 +def tensorsolve(a: _ArrayLike[np.complex64], b: _ArrayLike[np.complex64 | np.float32], axes: Iterable[int] | None = None) -> NDArray[np.complex64]: ... +@overload # +complex64, ~complex64 +def tensorsolve(a: _ArrayLike[np.complex64 | np.float32], b: _ArrayLike[np.complex64], axes: Iterable[int] | None = None) -> NDArray[np.complex64]: ... +@overload # +complex, +complex +def tensorsolve(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, axes: Iterable[int] | None = None) -> NDArray[np.complex128 | Any]: ... -# TODO: narrow return types -@overload -def solve( - a: _ArrayLikeInt_co, - b: _ArrayLikeInt_co, -) -> NDArray[float64]: ... -@overload -def solve( - a: _ArrayLikeFloat_co, - b: _ArrayLikeFloat_co, -) -> NDArray[floating]: ... -@overload -def solve( - a: _ArrayLikeComplex_co, - b: _ArrayLikeComplex_co, -) -> NDArray[complexfloating]: ... +# keep in sync with `tensorsolve` +@overload # ~float64, +float64 +def solve(a: _ToArrayF64, b: _ArrayLikeFloat_co) -> NDArray[np.float64]: ... +@overload # +float64, ~float64 +def solve(a: _ArrayLikeFloat_co, b: _ToArrayF64) -> NDArray[np.float64]: ... +@overload # ~float32, ~float32 +def solve(a: _ArrayLike[np.float32], b: _ArrayLike[np.float32]) -> NDArray[np.float32]: ... +@overload # +float, +float +def solve(a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co) -> NDArray[np.float64 | Any]: ... +@overload # ~complex128, +complex128 +def solve(a: _AsArrayC128, b: _ArrayLikeComplex_co) -> NDArray[np.complex128]: ... +@overload # +complex128, ~complex128 +def solve(a: _ArrayLikeComplex_co, b: _AsArrayC128) -> NDArray[np.complex128]: ... +@overload # ~complex64, +complex64 +def solve(a: _ArrayLike[np.complex64], b: _ArrayLike[np.complex64 | np.float32]) -> NDArray[np.complex64]: ... +@overload # +complex64, ~complex64 +def solve(a: _ArrayLike[np.complex64 | np.float32], b: _ArrayLike[np.complex64]) -> NDArray[np.complex64]: ... +@overload # +complex, +complex +def solve(a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co) -> NDArray[np.complex128 | Any]: ... # keep in sync with the other inverse functions and cholesky @overload # inexact32 @@ -258,32 +287,6 @@ def matrix_power[ScalarT: _inexact32](a: _ArrayLike[ScalarT], n: SupportsIndex) @overload # fallback def matrix_power(a: _ArrayLikeComplex_co | _ArrayLikeObject_co, n: SupportsIndex) -> np.ndarray: ... -# TODO: narrow return types -@overload -def outer(x1: _ArrayLike[Never], x2: _ArrayLike[Never], /) -> NDArray[Any]: ... -@overload -def outer(x1: _ArrayLikeBool_co, x2: _ArrayLikeBool_co, /) -> NDArray[np.bool]: ... -@overload -def outer[ScalarT: np.number](x1: _ArrayLike[ScalarT], x2: _ArrayLike[ScalarT], /) -> NDArray[ScalarT]: ... -@overload -def outer(x1: _ArrayLikeUInt_co, x2: _ArrayLikeUInt_co, /) -> NDArray[unsignedinteger]: ... -@overload -def outer(x1: _ArrayLikeInt_co, x2: _ArrayLikeInt_co, /) -> NDArray[signedinteger]: ... -@overload -def outer(x1: _ArrayLikeFloat_co, x2: _ArrayLikeFloat_co, /) -> NDArray[floating]: ... -@overload -def outer(x1: _ArrayLikeComplex_co, x2: _ArrayLikeComplex_co, /) -> NDArray[complexfloating]: ... -@overload -def outer(x1: _ArrayLikeTD64_co, x2: _ArrayLikeTD64_co, /) -> NDArray[timedelta64]: ... -@overload -def outer(x1: _ArrayLikeObject_co, x2: _ArrayLikeObject_co, /) -> NDArray[object_]: ... -@overload -def outer( - x1: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co, - x2: _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co, - /, -) -> NDArray[Any]: ... - # NOTE: for real input the output dtype (floating/complexfloating) depends on the specific values @overload # abstract `inexact` and `floating` (excluding concrete types) def eig(a: NDArray[np.inexact[Never]]) -> EigResult: ... @@ -514,96 +517,356 @@ def det(a: _Array3ND[np.complex128] | _NestedSequence[Sequence[list[complex]]]) @overload # fallback def det(a: _ArrayLikeComplex_co) -> Any: ... -# TODO: narrow return types -@overload -def lstsq( - a: _ArrayLikeInt_co, b: _ArrayLikeInt_co, rcond: float | None = None -) -> tuple[ - NDArray[float64], - NDArray[float64], - int32, - NDArray[float64], -]: ... -@overload +# +@overload # +float64, ~float64, known shape +def lstsq[ShapeT: tuple[int] | tuple[int, int]]( + a: _SupportsArray[tuple[int, int], np.dtype[_to_float64]] | Sequence[Sequence[float]], + b: _SupportsArray[ShapeT, np.dtype[np.floating | np.integer]], + rcond: float | None = None, +) -> _LstSqResult[ShapeT, np.float64, np.float64]: ... +@overload # ~float64, +float64, known shape +def lstsq[ShapeT: tuple[int] | tuple[int, int]]( + a: _SupportsArray[tuple[int, int], np.dtype[np.floating | np.integer]] | Sequence[Sequence[float]], + b: _SupportsArray[ShapeT, np.dtype[_to_float64]], + rcond: float | None = None, +) -> _LstSqResult[ShapeT, np.float64, np.float64]: ... +@overload # +complex128, ~complex128, known shape +def lstsq[ShapeT: tuple[int] | tuple[int, int]]( + a: _SupportsArray[tuple[int, int], np.dtype[np.number]] | Sequence[Sequence[complex]], + b: _SupportsArray[ShapeT, np.dtype[np.complex128]], + rcond: float | None = None, +) -> _LstSqResult[ShapeT, np.complex128, np.float64]: ... +@overload # ~complex128, +complex128, known shape +def lstsq[ShapeT: tuple[int] | tuple[int, int]]( + a: _SupportsArray[tuple[int, int], np.dtype[np.complex128]] | Sequence[list[complex]], + b: _SupportsArray[ShapeT, np.dtype[np.number]], + rcond: float | None = None, +) -> _LstSqResult[ShapeT, np.complex128, np.float64]: ... +@overload # ~float32, ~float32, known shape +def lstsq[ShapeT: tuple[int] | tuple[int, int]]( + a: _SupportsArray[tuple[int, int], np.dtype[np.float32]], + b: _SupportsArray[ShapeT, np.dtype[np.float32]], + rcond: float | None = None, +) -> _LstSqResult[ShapeT, np.float32, np.float32]: ... +@overload # +complex64, ~complex64, known shape +def lstsq[ShapeT: tuple[int] | tuple[int, int]]( + a: _SupportsArray[tuple[int, int], np.dtype[np.complex64 | np.float32]], + b: _SupportsArray[ShapeT, np.dtype[np.complex64]], + rcond: float | None = None, +) -> _LstSqResult[ShapeT, np.complex64, np.float32]: ... +@overload # ~complex64, +complex64, known shape +def lstsq[ShapeT: tuple[int] | tuple[int, int]]( + a: _SupportsArray[tuple[int, int], np.dtype[np.complex64]], + b: _SupportsArray[ShapeT, np.dtype[np.complex64 | np.float32]], + rcond: float | None = None, +) -> _LstSqResult[ShapeT, np.complex64, np.float32]: ... +@overload # +float64, +float64, unknown shape def lstsq( - a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, rcond: float | None = None -) -> tuple[ - NDArray[floating], - NDArray[floating], - int32, - NDArray[floating], -]: ... -@overload + a: _ArrayLikeFloat_co, + b: _ArrayLikeFloat_co, + rcond: float | None = None, +) -> _LstSqResult[_AnyShape, np.float64 | Any, np.float64 | Any]: ... +@overload # +complex128, +complex128, unknown shape def lstsq( - a: _ArrayLikeComplex_co, b: _ArrayLikeComplex_co, rcond: float | None = None -) -> tuple[ - NDArray[complexfloating], - NDArray[floating], - int32, - NDArray[floating], -]: ... + a: _ArrayLikeComplex_co, + b: _ArrayLikeComplex_co, + rcond: float | None = None, +) -> _LstSqResult[_AnyShape, np.complex128 | Any, np.float64 | Any]: ... -# TODO: narrow return types -@overload +# NOTE: This assumes that `axis` is only passed if `x` is >1d, and that `keepdims` is never passed positionally. +# keep in sync with `vector_norm` +@overload # +inexact64 (unsafe casting), axis=None, keepdims=False def norm( - x: ArrayLike, - ord: float | L["fro", "nuc"] | None = None, + x: _ArrayLike[_to_inexact64_unsafe] | _NestedSequence[complex], + ord: _OrderKind | None = None, axis: None = None, keepdims: L[False] = False, -) -> floating: ... -@overload +) -> np.float64: ... +@overload # +inexact64 (unsafe casting), axis= (positional), keepdims=False def norm( - x: ArrayLike, - ord: float | L["fro", "nuc"] | None, - axis: SupportsInt | SupportsIndex | tuple[int, ...] | None, - keepdims: bool = False, -) -> Any: ... -@overload + x: _ArrayLike[_to_inexact64_unsafe] | _NestedSequence[complex], + ord: _OrderKind | None, + axis: _Ax2, + keepdims: L[False] = False, +) -> NDArray[np.float64]: ... +@overload # +inexact64 (unsafe casting), axis= (keyword), keepdims=False def norm( - x: ArrayLike, - ord: float | L["fro", "nuc"] | None = None, + x: _ArrayLike[_to_inexact64_unsafe] | _NestedSequence[complex], + ord: _OrderKind | None = None, *, - axis: SupportsInt | SupportsIndex | tuple[int, ...] | None, - keepdims: bool = False, -) -> Any: ... + axis: _Ax2, + keepdims: L[False] = False, +) -> NDArray[np.float64]: ... +@overload # +inexact64 (unsafe casting), shape known, keepdims=True +def norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[_to_inexact64_unsafe]], + ord: _OrderKind | None = None, + axis: _Ax2 | None = None, + *, + keepdims: L[True], +) -> np.ndarray[ShapeT, np.dtype[np.float64]]: ... +@overload # +inexact64 (unsafe casting), shape unknown, keepdims=True +def norm( + x: _ArrayLike[_to_inexact64_unsafe] | _NestedSequence[complex], + ord: _OrderKind | None = None, + axis: _Ax2 | None = None, + *, + keepdims: L[True], +) -> NDArray[np.float64]: ... +@overload # ~float16, axis=None, keepdims=False +def norm( + x: _ArrayLike[np.float16], ord: _OrderKind | None = None, axis: None = None, keepdims: L[False] = False +) -> np.float16: ... +@overload # ~float16, axis= (positional), keepdims=False +def norm( + x: _ArrayLike[np.float16], ord: _OrderKind | None, axis: _Ax2, keepdims: L[False] = False +) -> NDArray[np.float16]: ... +@overload # ~float16, axis= (keyword), keepdims=False +def norm( + x: _ArrayLike[np.float16], ord: _OrderKind | None = None, *, axis: _Ax2, keepdims: L[False] = False +) -> NDArray[np.float16]: ... +@overload # ~float16, shape known, keepdims=True +def norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[np.float16]], ord: _OrderKind | None = None, axis: _Ax2 | None = None, *, keepdims: L[True] +) -> np.ndarray[ShapeT, np.dtype[np.float16]]: ... +@overload # ~float16, shape unknown, keepdims=True +def norm( + x: _ArrayLike[np.float16], ord: _OrderKind | None = None, axis: _Ax2 | None = None, *, keepdims: L[True] +) -> NDArray[np.float16]: ... +@overload # ~inexact32, axis=None, keepdims=False +def norm( + x: _ArrayLike[_inexact32], ord: _OrderKind | None = None, axis: None = None, keepdims: L[False] = False +) -> np.float32: ... +@overload # ~inexact32, axis= (positional), keepdims=False +def norm( + x: _ArrayLike[_inexact32], ord: _OrderKind | None, axis: _Ax2, keepdims: L[False] = False +) -> NDArray[np.float32]: ... +@overload # ~inexact32, axis= (keyword), keepdims=False +def norm( + x: _ArrayLike[_inexact32], ord: _OrderKind | None = None, *, axis: _Ax2, keepdims: L[False] = False +) -> NDArray[np.float32]: ... +@overload # ~inexact32, shape known, keepdims=True +def norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[_inexact32]], ord: _OrderKind | None = None, axis: _Ax2 | None = None, *, keepdims: L[True] +) -> np.ndarray[ShapeT, np.dtype[np.float32]]: ... +@overload # ~inexact32, shape unknown, keepdims=True +def norm( + x: _ArrayLike[_inexact32], ord: _OrderKind | None = None, axis: _Ax2 | None = None, *, keepdims: L[True] +) -> NDArray[np.float32]: ... +@overload # ~inexact80, axis=None, keepdims=False +def norm( + x: _ArrayLike[_inexact80], ord: _OrderKind | None = None, axis: None = None, keepdims: L[False] = False +) -> np.longdouble: ... +@overload # ~inexact80, axis= (positional), keepdims=False +def norm( + x: _ArrayLike[_inexact80], ord: _OrderKind | None, axis: _Ax2, keepdims: L[False] = False +) -> NDArray[np.longdouble]: ... +@overload # ~inexact80, axis= (keyword), keepdims=False +def norm( + x: _ArrayLike[_inexact80], ord: _OrderKind | None = None, *, axis: _Ax2, keepdims: L[False] = False +) -> NDArray[np.longdouble]: ... +@overload # ~inexact80, shape known, keepdims=True +def norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[_inexact80]], ord: _OrderKind | None = None, axis: _Ax2 | None = None, *, keepdims: L[True] +) -> np.ndarray[ShapeT, np.dtype[np.longdouble]]: ... +@overload # ~inexact80, shape unknown, keepdims=True +def norm( + x: _ArrayLike[_inexact80], ord: _OrderKind | None = None, axis: _Ax2 | None = None, *, keepdims: L[True] +) -> NDArray[np.longdouble]: ... +@overload # fallback +def norm(x: ArrayLike, ord: _OrderKind | None = None, axis: _Ax2 | None = None, keepdims: bool = False) -> Any: ... -# TODO: narrow return types -@overload +# +@overload # +inexact64 (unsafe casting), ?d, keepdims=False def matrix_norm( - x: ArrayLike, + x: _SupportsArray[_JustAnyShape, np.dtype[_to_inexact64_unsafe]], /, *, - ord: float | L["fro", "nuc"] | None = "fro", + ord: _OrderKind | None = "fro", keepdims: L[False] = False, -) -> floating: ... -@overload +) -> NDArray[np.float64] | Any: ... +@overload # +inexact64 (unsafe casting), 2d, keepdims=False def matrix_norm( - x: ArrayLike, + x: _ArrayLike2D[_to_inexact64_unsafe] | Sequence[Sequence[complex]], /, *, - ord: float | L["fro", "nuc"] | None = "fro", - keepdims: bool = False, -) -> Any: ... + ord: _OrderKind | None = "fro", + keepdims: L[False] = False, +) -> np.float64: ... +@overload # +inexact64 (unsafe casting), >2d, keepdims=False +def matrix_norm( + x: _ArrayLike3ND[_to_inexact64_unsafe] | _NestedSequence[Sequence[Sequence[complex]]], + /, + *, + ord: _OrderKind | None = "fro", + keepdims: L[False] = False, +) -> NDArray[np.float64]: ... +@overload # +inexact64 (unsafe casting), shape known, keepdims=True +def matrix_norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[_to_inexact64_unsafe]], + /, + *, + ord: _OrderKind | None = "fro", + keepdims: L[True], +) -> np.ndarray[ShapeT, np.dtype[np.float64]]: ... +@overload # +inexact64 (unsafe casting), ?d, keepdims=True +def matrix_norm( + x: _ArrayLike2ND[_to_inexact64_unsafe] | _NestedSequence[Sequence[complex]], + /, + *, + ord: _OrderKind | None = "fro", + keepdims: L[True], +) -> NDArray[np.float64]: ... +@overload # ~float16, ?d, keepdims=False +def matrix_norm( + x: _SupportsArray[_JustAnyShape, np.dtype[np.float16]], /, *, ord: _OrderKind | None = None, keepdims: L[False] = False +) -> NDArray[np.float16] | Any: ... +@overload # ~float16, 2d, keepdims=False +def matrix_norm( + x: _ArrayLike2D[np.float16], /, *, ord: _OrderKind | None = None, keepdims: L[False] = False +) -> np.float16: ... +@overload # ~float16, >2d, keepdims=False +def matrix_norm( + x: _ArrayLike3ND[np.float16], /, *, ord: _OrderKind | None = None, keepdims: L[False] = False +) -> NDArray[np.float16]: ... +@overload # ~float16, shape known, keepdims=True +def matrix_norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[np.float16]], /, *, ord: _OrderKind | None = None, keepdims: L[True] +) -> np.ndarray[ShapeT, np.dtype[np.float16]]: ... +@overload # ~float16, ?d, keepdims=True +def matrix_norm( + x: _ArrayLike2ND[np.float16], /, *, ord: _OrderKind | None = None, keepdims: L[True] +) -> NDArray[np.float16]: ... +@overload # ~inexact32, ?d, keepdims=False +def matrix_norm( + x: _SupportsArray[_JustAnyShape, np.dtype[_inexact32]], /, *, ord: _OrderKind | None = None, keepdims: L[False] = False +) -> NDArray[np.float32] | Any: ... +@overload # ~inexact32, 2d, keepdims=False +def matrix_norm( + x: _ArrayLike2D[_inexact32], /, *, ord: _OrderKind | None = None, keepdims: L[False] = False +) -> np.float32: ... +@overload # ~inexact32, >2d, keepdims=False +def matrix_norm( + x: _ArrayLike3ND[_inexact32], /, *, ord: _OrderKind | None = None, keepdims: L[False] = False +) -> NDArray[np.float32]: ... +@overload # ~inexact32, shape known, keepdims=True +def matrix_norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[_inexact32]], /, *, ord: _OrderKind | None = None, keepdims: L[True] +) -> np.ndarray[ShapeT, np.dtype[np.float32]]: ... +@overload # ~inexact32, ?d, keepdims=True +def matrix_norm( + x: _ArrayLike2ND[_inexact32], /, *, ord: _OrderKind | None = None, keepdims: L[True] +) -> NDArray[np.float32]: ... +@overload # ~inexact80, ?d, keepdims=False +def matrix_norm( + x: _SupportsArray[_JustAnyShape, np.dtype[_inexact80]], /, *, ord: _OrderKind | None = None, keepdims: L[False] = False +) -> NDArray[np.longdouble] | Any: ... +@overload # ~inexact80, 2d, keepdims=False +def matrix_norm( + x: _ArrayLike2D[_inexact80], /, *, ord: _OrderKind | None = None, keepdims: L[False] = False +) -> np.longdouble: ... +@overload # ~inexact80, >2d, keepdims=False +def matrix_norm( + x: _ArrayLike3ND[_inexact80], /, *, ord: _OrderKind | None = None, keepdims: L[False] = False +) -> NDArray[np.longdouble]: ... +@overload # ~inexact80, shape known, keepdims=True +def matrix_norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[_inexact80]], /, *, ord: _OrderKind | None = None, keepdims: L[True] +) -> np.ndarray[ShapeT, np.dtype[np.longdouble]]: ... +@overload # ~inexact80, ?d, keepdims=True +def matrix_norm( + x: _ArrayLike2ND[_inexact80], /, *, ord: _OrderKind | None = None, keepdims: L[True] +) -> NDArray[np.longdouble]: ... +@overload # fallback +def matrix_norm(x: ArrayLike, /, *, ord: _OrderKind | None = None, keepdims: bool = False) -> Any: ... -# TODO: narrow return types -@overload +# keep in sync with `norm` +@overload # +inexact64 (unsafe casting), axis=None, keepdims=False def vector_norm( - x: ArrayLike, + x: _ArrayLike[_to_inexact64_unsafe] | _NestedSequence[complex], /, *, + keepdims: L[False] = False, axis: None = None, ord: float | None = 2, +) -> np.float64: ... +@overload # +inexact64 (unsafe casting), axis=, keepdims=False +def vector_norm( + x: _ArrayLike[_to_inexact64_unsafe] | _NestedSequence[complex], + /, + *, + axis: _Ax2, keepdims: L[False] = False, -) -> floating: ... -@overload + ord: float | None = 2, +) -> NDArray[np.float64]: ... +@overload # +inexact64 (unsafe casting), shape known, keepdims=True +def vector_norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[_to_inexact64_unsafe]], + /, + *, + axis: _Ax2 | None = None, + keepdims: L[True], + ord: float | None = 2, +) -> np.ndarray[ShapeT, np.dtype[np.float64]]: ... +@overload # +inexact64 (unsafe casting), shape unknown, keepdims=True def vector_norm( - x: ArrayLike, + x: _ArrayLike[_to_inexact64_unsafe] | _NestedSequence[complex], /, *, - axis: SupportsInt | SupportsIndex | tuple[int, ...], + axis: _Ax2 | None = None, + keepdims: L[True], ord: float | None = 2, - keepdims: bool = False, -) -> Any: ... +) -> NDArray[np.float64]: ... +@overload # ~float16, axis=None, keepdims=False +def vector_norm( + x: _ArrayLike[np.float16], /, *, axis: None = None, keepdims: L[False] = False, ord: float | None = 2 +) -> np.float16: ... +@overload # ~float16, axis= keepdims=False +def vector_norm( + x: _ArrayLike[np.float16], /, *, axis: _Ax2, keepdims: L[False] = False, ord: float | None = 2 +) -> NDArray[np.float16]: ... +@overload # ~float16, shape known, keepdims=True +def vector_norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[np.float16]], /, *, axis: _Ax2 | None = None, keepdims: L[True], ord: float | None = 2 +) -> np.ndarray[ShapeT, np.dtype[np.float16]]: ... +@overload # ~float16, shape unknown, keepdims=True +def vector_norm( + x: _ArrayLike[np.float16], /, *, axis: _Ax2 | None = None, keepdims: L[True], ord: float | None = 2 +) -> NDArray[np.float16]: ... +@overload # ~inexact32, axis=None, keepdims=False +def vector_norm( + x: _ArrayLike[_inexact32], /, *, axis: None = None, keepdims: L[False] = False, ord: float | None = 2 +) -> np.float32: ... +@overload # ~inexact32, axis= keepdims=False +def vector_norm( + x: _ArrayLike[_inexact32], /, *, axis: _Ax2, keepdims: L[False] = False, ord: float | None = 2 +) -> NDArray[np.float32]: ... +@overload # ~inexact32, shape known, keepdims=True +def vector_norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[_inexact32]], /, *, axis: _Ax2 | None = None, keepdims: L[True], ord: float | None = 2 +) -> np.ndarray[ShapeT, np.dtype[np.float32]]: ... +@overload # ~inexact32, shape unknown, keepdims=True +def vector_norm( + x: _ArrayLike[_inexact32], /, *, axis: _Ax2 | None = None, keepdims: L[True], ord: float | None = 2 +) -> NDArray[np.float32]: ... +@overload # ~inexact80, axis=None, keepdims=False +def vector_norm( + x: _ArrayLike[_inexact80], /, *, axis: None = None, keepdims: L[False] = False, ord: float | None = 2 +) -> np.longdouble: ... +@overload # ~inexact80, axis=, keepdims=False +def vector_norm( + x: _ArrayLike[_inexact80], /, *, axis: _Ax2, keepdims: L[False] = False, ord: float | None = 2 +) -> NDArray[np.longdouble]: ... +@overload # ~inexact80, shape known, keepdims=True +def vector_norm[ShapeT: _Shape]( + x: _SupportsArray[ShapeT, np.dtype[_inexact80]], /, *, axis: _Ax2 | None = None, keepdims: L[True], ord: float | None = 2 +) -> np.ndarray[ShapeT, np.dtype[np.longdouble]]: ... +@overload # ~inexact80, shape unknown, keepdims=True +def vector_norm( + x: _ArrayLike[_inexact80], /, *, axis: _Ax2 | None = None, keepdims: L[True], ord: float | None = 2 +) -> NDArray[np.longdouble]: ... +@overload # fallback +def vector_norm(x: ArrayLike, /, *, axis: _Ax2 | None = None, keepdims: bool = False, ord: float | None = 2) -> Any: ... # keep in sync with numpy._core.numeric.tensordot (ignoring `/, *`) @overload @@ -621,7 +884,7 @@ def tensordot( /, *, axes: int | tuple[_ShapeLike, _ShapeLike] = 2, -) -> NDArray[np.bool_]: ... +) -> NDArray[np.bool]: ... @overload def tensordot( a: _ArrayLikeInt_co, @@ -654,22 +917,155 @@ def multi_dot( out: NDArray[Any] | None = None, ) -> Any: ... -# TODO: narrow return types -def diagonal( - x: ArrayLike, # >= 2D array +# +@overload # workaround for microsoft/pyright#10232 +def diagonal[DTypeT: np.dtype]( + x: _SupportsArray[_JustAnyShape, DTypeT], /, *, offset: SupportsIndex = 0 +) -> np.ndarray[_AnyShape, DTypeT]: ... +@overload # 2d, known dtype +def diagonal[DTypeT: np.dtype]( + x: _SupportsArray[tuple[int, int], DTypeT], /, *, offset: SupportsIndex = 0 +) -> np.ndarray[tuple[int], DTypeT]: ... +@overload # 3d, known dtype +def diagonal[DTypeT: np.dtype]( + x: _SupportsArray[tuple[int, int, int], DTypeT], /, *, offset: SupportsIndex = 0 +) -> np.ndarray[tuple[int, int], DTypeT]: ... +@overload # 4d, known dtype +def diagonal[DTypeT: np.dtype]( + x: _SupportsArray[tuple[int, int, int, int], DTypeT], /, *, offset: SupportsIndex = 0 +) -> np.ndarray[tuple[int, int, int], DTypeT]: ... +@overload # nd like ~bool +def diagonal(x: _NestedSequence[list[bool]], /, *, offset: SupportsIndex = 0) -> NDArray[np.bool]: ... +@overload # nd like ~int +def diagonal(x: _NestedSequence[list[int]], /, *, offset: SupportsIndex = 0) -> NDArray[np.int_]: ... +@overload # nd like ~float +def diagonal(x: _NestedSequence[list[float]], /, *, offset: SupportsIndex = 0) -> NDArray[np.float64]: ... +@overload # nd like ~complex +def diagonal(x: _NestedSequence[list[complex]], /, *, offset: SupportsIndex = 0) -> NDArray[np.complex128]: ... +@overload # nd like ~bytes +def diagonal(x: _NestedSequence[list[bytes]], /, *, offset: SupportsIndex = 0) -> NDArray[np.bytes_]: ... +@overload # nd like ~str +def diagonal(x: _NestedSequence[list[str]], /, *, offset: SupportsIndex = 0) -> NDArray[np.str_]: ... +@overload # fallback +def diagonal(x: ArrayLike, /, *, offset: SupportsIndex = 0) -> np.ndarray: ... + +# +@overload # workaround for microsoft/pyright#10232 +def trace( + x: _SupportsArray[_JustAnyShape, np.dtype[_to_complex]], /, *, offset: SupportsIndex = 0, dtype: DTypeLike | None = None +) -> Any: ... +@overload # 2d known dtype, dtype=None +def trace[ScalarT: _to_complex]( + x: _SupportsArray[tuple[int, int], np.dtype[ScalarT]], /, *, offset: SupportsIndex = 0, dtype: None = None +) -> ScalarT: ... +@overload # 2d, dtype= +def trace[ScalarT: _to_complex]( + x: _SupportsArray[tuple[int, int], np.dtype[_to_complex]] | Sequence[Sequence[_ComplexLike_co]], /, *, offset: SupportsIndex = 0, -) -> NDArray[Any]: ... - -# TODO: narrow return types -def trace( - x: ArrayLike, # >= 2D array + dtype: _DTypeLike[ScalarT], +) -> ScalarT: ... +@overload # 2d bool +def trace(x: Sequence[Sequence[bool]], /, *, offset: SupportsIndex = 0, dtype: None = None) -> np.bool: ... +@overload # 2d int +def trace(x: Sequence[list[int]], /, *, offset: SupportsIndex = 0, dtype: None = None) -> np.int_: ... +@overload # 2d float +def trace(x: Sequence[list[float]], /, *, offset: SupportsIndex = 0, dtype: None = None) -> np.float64: ... +@overload # 2d complex +def trace(x: Sequence[list[complex]], /, *, offset: SupportsIndex = 0, dtype: None = None) -> np.complex128: ... +@overload # 3d known dtype, dtype=None +def trace[DTypeT: np.dtype[_to_complex]]( + x: _SupportsArray[tuple[int, int, int], DTypeT], /, *, offset: SupportsIndex = 0, dtype: None = None +) -> np.ndarray[tuple[int], DTypeT]: ... +@overload # 3d, dtype= +def trace[ScalarT: _to_complex]( + x: _SupportsArray[tuple[int, int, int], np.dtype[_to_complex]] | Sequence[Sequence[Sequence[_ComplexLike_co]]], /, *, offset: SupportsIndex = 0, - dtype: DTypeLike | None = None, -) -> Any: ... + dtype: _DTypeLike[ScalarT], +) -> np.ndarray[tuple[int], np.dtype[ScalarT]]: ... +@overload # 3d+ known dtype, dtype=None +def trace[DTypeT: np.dtype[_to_complex]]( + x: _SupportsArray[_AtLeast3D, DTypeT], /, *, offset: SupportsIndex = 0, dtype: None = None +) -> np.ndarray[tuple[int, *tuple[Any, ...]], DTypeT]: ... +@overload # 3d+, dtype= +def trace[ScalarT: _to_complex]( + x: _SupportsArray[_AtLeast3D, np.dtype[_to_complex]] | _NestedSequence[Sequence[Sequence[_ComplexLike_co]]], + /, + *, + offset: SupportsIndex = 0, + dtype: _DTypeLike[ScalarT], +) -> np.ndarray[tuple[int, *tuple[Any, ...]], np.dtype[ScalarT]]: ... +@overload # 3d+ bool +def trace( + x: _NestedSequence[Sequence[Sequence[bool]]], /, *, offset: SupportsIndex = 0, dtype: None = None +) -> NDArray[np.bool]: ... +@overload # 3d+ int +def trace( + x: _NestedSequence[Sequence[list[int]]], /, *, offset: SupportsIndex = 0, dtype: None = None +) -> NDArray[np.int_]: ... +@overload # 3d+ float +def trace( + x: _NestedSequence[Sequence[list[float]]], /, *, offset: SupportsIndex = 0, dtype: None = None +) -> NDArray[np.float64]: ... +@overload # 3d+ complex +def trace( + x: _NestedSequence[Sequence[list[complex]]], /, *, offset: SupportsIndex = 0, dtype: None = None +) -> NDArray[np.complex128]: ... +@overload # fallback +def trace(x: _ArrayLikeComplex_co, /, *, offset: SupportsIndex = 0, dtype: DTypeLike | None = None) -> Any: ... + +# +@overload # workaround for microsoft/pyright#10232 +def outer(x1: _ToArray1D[Never], x2: _ToArray1D[Never], /) -> np.ndarray[tuple[int, int]]: ... +@overload # +bool, +bool +def outer( + x1: _ToArray1D[np.bool] | Sequence[bool], x2: _ToArray1D[np.bool] | Sequence[bool], / +) -> np.ndarray[tuple[int, int], np.dtype[np.bool]]: ... +@overload # ~int64, +int64 +def outer( + x1: _ToArray1D[np.int64] | list[int], x2: _ToArray1D[_to_integer] | Sequence[int], / +) -> np.ndarray[tuple[int, int], np.dtype[np.int64]]: ... +@overload # +int64, ~int64 +def outer( + x1: _ToArray1D[_to_integer] | Sequence[int], x2: _ToArray1D[np.int64] | list[int], / +) -> np.ndarray[tuple[int, int], np.dtype[np.int64]]: ... +@overload # ~timedelta64, +timedelta64 +def outer( + x1: _ToArray1D[np.timedelta64] | Sequence[np.timedelta64], x2: _ToArray1D[_to_timedelta64] | Sequence[_to_timedelta64], / +) -> np.ndarray[tuple[int, int], np.dtype[np.timedelta64]]: ... +@overload # +timedelta64, ~timedelta64 +def outer( + x1: _ToArray1D[_to_timedelta64] | Sequence[_to_timedelta64], x2: _ToArray1D[np.timedelta64] | Sequence[np.timedelta64], / +) -> np.ndarray[tuple[int, int], np.dtype[np.timedelta64]]: ... +@overload # ~float64, +float64 +def outer( + x1: _ToArray1D[np.float64] | list[float], x2: _ToArray1D[_to_float64] | Sequence[float], / +) -> np.ndarray[tuple[int, int], np.dtype[np.float64]]: ... +@overload # +float64, ~float64 +def outer( + x1: _ToArray1D[_to_float64] | Sequence[float], x2: _ToArray1D[np.float64] | list[float], / +) -> np.ndarray[tuple[int, int], np.dtype[np.float64]]: ... +@overload # ~complex128, +complex128 +def outer( + x1: _ToArray1D[np.complex128] | list[complex], x2: _ToArray1D[_to_complex] | Sequence[complex], / +) -> np.ndarray[tuple[int, int], np.dtype[np.complex128]]: ... +@overload # +complex128, ~complex128 +def outer( + x1: _ToArray1D[_to_complex] | Sequence[complex], x2: _ToArray1D[np.complex128] | list[complex], / +) -> np.ndarray[tuple[int, int], np.dtype[np.complex128]]: ... +@overload # ~ScalarT, ~ScalarT +def outer[ScalarT: np.number | np.object_]( + x1: _ToArray1D[ScalarT] | Sequence[ScalarT], x2: _ToArray1D[ScalarT] | Sequence[ScalarT], / +) -> np.ndarray[tuple[int, int], np.dtype[ScalarT]]: ... +@overload # fallback +def outer( + x1: _ToArray1D[_to_complex] | Sequence[complex | _to_complex], + x2: _ToArray1D[_to_complex] | Sequence[complex | _to_complex], + /, +) -> np.ndarray[tuple[int, int]]: ... # TODO: narrow return types @overload diff --git a/numpy/random/mtrand.pyx b/numpy/random/mtrand.pyx index ae1706eb884b..c69284d0df9a 100644 --- a/numpy/random/mtrand.pyx +++ b/numpy/random/mtrand.pyx @@ -222,12 +222,13 @@ cdef class RandomState: "be instantized.") self._bitgen = ( PyCapsule_GetPointer(capsule, name))[0] self._aug_state.bit_generator = &self._bitgen - self._reset_gauss() self.lock = bit_generator.lock + self._reset_gauss() cdef _reset_gauss(self): - self._aug_state.has_gauss = 0 - self._aug_state.gauss = 0.0 + with self.lock: + self._aug_state.has_gauss = 0 + self._aug_state.gauss = 0.0 def seed(self, seed=None): """ @@ -301,8 +302,9 @@ cdef class RandomState: 'MT19937 BitGenerator. To silence this warning, ' 'set `legacy` to False.', RuntimeWarning) legacy = False - st['has_gauss'] = self._aug_state.has_gauss - st['gauss'] = self._aug_state.gauss + with self.lock: + st['has_gauss'] = self._aug_state.has_gauss + st['gauss'] = self._aug_state.gauss if legacy and not isinstance(self._bit_generator, _MT19937): raise ValueError( "legacy can only be True when the underlying bitgenerator is " diff --git a/numpy/typing/tests/data/reveal/linalg.pyi b/numpy/typing/tests/data/reveal/linalg.pyi index a40aa84d9c05..914dff2ab703 100644 --- a/numpy/typing/tests/data/reveal/linalg.pyi +++ b/numpy/typing/tests/data/reveal/linalg.pyi @@ -10,25 +10,39 @@ from numpy.linalg._linalg import ( SVDResult, ) +type _Array1D[ScalarT: np.generic] = np.ndarray[tuple[int], np.dtype[ScalarT]] +type _Array2D[ScalarT: np.generic] = np.ndarray[tuple[int, int], np.dtype[ScalarT]] + +bool_list_1d: list[bool] +bool_list_2d: list[list[bool]] +int_list_1d: list[int] int_list_2d: list[list[int]] float_list_1d: list[float] float_list_2d: list[list[float]] float_list_3d: list[list[list[float]]] float_list_4d: list[list[list[list[float]]]] +complex_list_1d: list[complex] complex_list_2d: list[list[complex]] complex_list_3d: list[list[list[complex]]] +bytes_list_2d: list[list[bytes]] +str_list_2d: list[list[str]] AR_any: np.ndarray AR_f_: npt.NDArray[np.floating] AR_c_: npt.NDArray[np.complexfloating] AR_i8: npt.NDArray[np.int64] +AR_f2: npt.NDArray[np.float16] AR_f4: npt.NDArray[np.float32] AR_f8: npt.NDArray[np.float64] +AR_f10: npt.NDArray[np.longdouble] AR_c8: npt.NDArray[np.complex64] AR_c16: npt.NDArray[np.complex128] +AR_c20: npt.NDArray[np.clongdouble] AR_O: npt.NDArray[np.object_] +AR_M: npt.NDArray[np.datetime64] AR_m: npt.NDArray[np.timedelta64] -AR_S: npt.NDArray[np.str_] +AR_S: npt.NDArray[np.bytes_] +AR_U: npt.NDArray[np.str_] AR_b: npt.NDArray[np.bool] SC_f8: np.float64 @@ -38,18 +52,28 @@ AR_f8_2d: np.ndarray[tuple[int, int], np.dtype[np.float64]] AR_f8_3d: np.ndarray[tuple[int, int, int], np.dtype[np.float64]] AR_f8_4d: np.ndarray[tuple[int, int, int, int], np.dtype[np.float64]] +AR_f2_2d: np.ndarray[tuple[int, int], np.dtype[np.float16]] +AR_f4_1d: np.ndarray[tuple[int], np.dtype[np.float32]] AR_f4_2d: np.ndarray[tuple[int, int], np.dtype[np.float32]] AR_f4_3d: np.ndarray[tuple[int, int, int], np.dtype[np.float32]] +AR_f10_2d: np.ndarray[tuple[int, int], np.dtype[np.longdouble]] +AR_f10_3d: np.ndarray[tuple[int, int, int], np.dtype[np.longdouble]] ### assert_type(np.linalg.tensorsolve(AR_i8, AR_i8), npt.NDArray[np.float64]) -assert_type(np.linalg.tensorsolve(AR_i8, AR_f8), npt.NDArray[np.floating]) -assert_type(np.linalg.tensorsolve(AR_c16, AR_f8), npt.NDArray[np.complexfloating]) +assert_type(np.linalg.tensorsolve(AR_i8, AR_f8), npt.NDArray[np.float64]) +assert_type(np.linalg.tensorsolve(AR_f4, AR_f4), npt.NDArray[np.float32]) +assert_type(np.linalg.tensorsolve(AR_c16, AR_f8), npt.NDArray[np.complex128]) +assert_type(np.linalg.tensorsolve(AR_c8, AR_f4), npt.NDArray[np.complex64]) +assert_type(np.linalg.tensorsolve(AR_f4, AR_c8), npt.NDArray[np.complex64]) assert_type(np.linalg.solve(AR_i8, AR_i8), npt.NDArray[np.float64]) -assert_type(np.linalg.solve(AR_i8, AR_f8), npt.NDArray[np.floating]) -assert_type(np.linalg.solve(AR_c16, AR_f8), npt.NDArray[np.complexfloating]) +assert_type(np.linalg.solve(AR_i8, AR_f8), npt.NDArray[np.float64]) +assert_type(np.linalg.solve(AR_f4, AR_f4), npt.NDArray[np.float32]) +assert_type(np.linalg.solve(AR_c16, AR_f8), npt.NDArray[np.complex128]) +assert_type(np.linalg.solve(AR_c8, AR_f4), npt.NDArray[np.complex64]) +assert_type(np.linalg.solve(AR_f4, AR_c8), npt.NDArray[np.complex64]) assert_type(np.linalg.tensorinv(AR_i8), npt.NDArray[np.float64]) assert_type(np.linalg.tensorinv(AR_f8), npt.NDArray[np.float64]) @@ -73,14 +97,6 @@ assert_type(np.linalg.cholesky(AR_i8), npt.NDArray[np.float64]) assert_type(np.linalg.cholesky(AR_f8), npt.NDArray[np.float64]) assert_type(np.linalg.cholesky(AR_c16), npt.NDArray[np.complex128]) -assert_type(np.linalg.outer(AR_i8, AR_i8), npt.NDArray[np.int64]) -assert_type(np.linalg.outer(AR_f8, AR_f8), npt.NDArray[np.float64]) -assert_type(np.linalg.outer(AR_c16, AR_c16), npt.NDArray[np.complex128]) -assert_type(np.linalg.outer(AR_b, AR_b), npt.NDArray[np.bool]) -assert_type(np.linalg.outer(AR_O, AR_O), npt.NDArray[np.object_]) -# NOTE: Mypy incorrectly infers `ndarray[Any, Any]`, but pyright behaves correctly. -assert_type(np.linalg.outer(AR_i8, AR_m), npt.NDArray[np.timedelta64]) # type: ignore[assert-type] - assert_type(np.linalg.qr(AR_i8), QRResult[np.float64]) assert_type(np.linalg.qr(AR_i8, "r"), npt.NDArray[np.float64]) assert_type(np.linalg.qr(AR_i8, "raw"), tuple[npt.NDArray[np.float64], npt.NDArray[np.float64]]) @@ -201,25 +217,136 @@ assert_type(np.linalg.det(AR_f8_3d), npt.NDArray[np.float64]) assert_type(np.linalg.det(complex_list_2d), np.complex128) assert_type(np.linalg.det(complex_list_3d), npt.NDArray[np.complex128]) -assert_type(np.linalg.lstsq(AR_i8, AR_i8), tuple[npt.NDArray[np.float64], npt.NDArray[np.float64], np.int32, npt.NDArray[np.float64]]) -assert_type(np.linalg.lstsq(AR_i8, AR_f8), tuple[npt.NDArray[np.floating], npt.NDArray[np.floating], np.int32, npt.NDArray[np.floating]]) -assert_type(np.linalg.lstsq(AR_f8, AR_c16), tuple[npt.NDArray[np.complexfloating], npt.NDArray[np.floating], np.int32, npt.NDArray[np.floating]]) - -assert_type(np.linalg.norm(AR_i8), np.floating) -assert_type(np.linalg.norm(AR_f8), np.floating) -assert_type(np.linalg.norm(AR_c16), np.floating) -assert_type(np.linalg.norm(AR_S), np.floating) -assert_type(np.linalg.norm(AR_f8, axis=0), Any) - -assert_type(np.linalg.matrix_norm(AR_i8), np.floating) -assert_type(np.linalg.matrix_norm(AR_f8), np.floating) -assert_type(np.linalg.matrix_norm(AR_c16), np.floating) -assert_type(np.linalg.matrix_norm(AR_S), np.floating) +assert_type( + np.linalg.lstsq(AR_i8, AR_i8), + tuple[npt.NDArray[np.float64], _Array1D[np.float64], np.int32, _Array1D[np.float64]], +) +assert_type( + np.linalg.lstsq(AR_f4, AR_f4), + tuple[npt.NDArray[np.float32], _Array1D[np.float32], np.int32, _Array1D[np.float32]], +) +assert_type( + np.linalg.lstsq(AR_i8, AR_f8), + tuple[npt.NDArray[np.float64], _Array1D[np.float64], np.int32, _Array1D[np.float64]], +) +assert_type( + np.linalg.lstsq(AR_f4, AR_f8), + tuple[npt.NDArray[np.float64], _Array1D[np.float64], np.int32, _Array1D[np.float64]], +) +assert_type( + np.linalg.lstsq(AR_f8, AR_i8), + tuple[npt.NDArray[np.float64], _Array1D[np.float64], np.int32, _Array1D[np.float64]], +) +assert_type( + np.linalg.lstsq(AR_f8, AR_f4), + tuple[npt.NDArray[np.float64], _Array1D[np.float64], np.int32, _Array1D[np.float64]], +) +assert_type( + np.linalg.lstsq(AR_c8, AR_c8), + tuple[npt.NDArray[np.complex64], _Array1D[np.float32], np.int32, _Array1D[np.float32]], +) +assert_type( + np.linalg.lstsq(AR_c8, AR_c16), + tuple[npt.NDArray[np.complex128], _Array1D[np.float64], np.int32, _Array1D[np.float64]], +) +assert_type( + np.linalg.lstsq(AR_c16, AR_c8), + tuple[npt.NDArray[np.complex128], _Array1D[np.float64], np.int32, _Array1D[np.float64]], +) +assert_type( + np.linalg.lstsq(AR_f8, AR_f8_1d), + tuple[_Array1D[np.float64], _Array1D[np.float64], np.int32, _Array1D[np.float64]], +) +assert_type( + np.linalg.lstsq(AR_f4, AR_f4_1d), + tuple[_Array1D[np.float32], _Array1D[np.float32], np.int32, _Array1D[np.float32]], +) +assert_type( + np.linalg.lstsq(AR_f8, AR_f8_2d), + tuple[_Array2D[np.float64], _Array1D[np.float64], np.int32, _Array1D[np.float64]], +) +assert_type( + np.linalg.lstsq(AR_f4, AR_f4_2d), + tuple[_Array2D[np.float32], _Array1D[np.float32], np.int32, _Array1D[np.float32]], +) -assert_type(np.linalg.vector_norm(AR_i8), np.floating) -assert_type(np.linalg.vector_norm(AR_f8), np.floating) -assert_type(np.linalg.vector_norm(AR_c16), np.floating) -assert_type(np.linalg.vector_norm(AR_S), np.floating) +assert_type(np.linalg.norm(AR_i8), np.float64) +assert_type(np.linalg.norm(AR_f8), np.float64) +assert_type(np.linalg.norm(AR_c16), np.float64) +# Mypy incorrectly infers `Any` for datetime64 and timedelta64, but pyright behaves correctly. +assert_type(np.linalg.norm(AR_M), np.float64) # type: ignore[assert-type] +assert_type(np.linalg.norm(AR_m), np.float64) # type: ignore[assert-type] +assert_type(np.linalg.norm(AR_U), np.float64) +assert_type(np.linalg.norm(AR_S), np.float64) +assert_type(np.linalg.norm(AR_f8, 0, 1), npt.NDArray[np.float64]) +assert_type(np.linalg.norm(AR_f8, axis=0), npt.NDArray[np.float64]) +assert_type(np.linalg.norm(AR_f8, keepdims=True), npt.NDArray[np.float64]) +assert_type(np.linalg.norm(AR_f8_2d, keepdims=True), _Array2D[np.float64]) +assert_type(np.linalg.norm(AR_f2), np.float16) +assert_type(np.linalg.norm(AR_f2, 0, 1), npt.NDArray[np.float16]) +assert_type(np.linalg.norm(AR_f2, axis=1), npt.NDArray[np.float16]) +assert_type(np.linalg.norm(AR_f2, keepdims=True), npt.NDArray[np.float16]) +assert_type(np.linalg.norm(AR_f2_2d, keepdims=True), _Array2D[np.float16]) +assert_type(np.linalg.norm(AR_f4), np.float32) +assert_type(np.linalg.norm(AR_c8), np.float32) +assert_type(np.linalg.norm(AR_f4, 0, 1), npt.NDArray[np.float32]) +assert_type(np.linalg.norm(AR_f4, axis=1), npt.NDArray[np.float32]) +assert_type(np.linalg.norm(AR_f4, keepdims=True), npt.NDArray[np.float32]) +assert_type(np.linalg.norm(AR_f4_2d, keepdims=True), _Array2D[np.float32]) +assert_type(np.linalg.norm(AR_f10), np.longdouble) +assert_type(np.linalg.norm(AR_c20), np.longdouble) +assert_type(np.linalg.norm(AR_f10, 0, 1), npt.NDArray[np.longdouble]) +assert_type(np.linalg.norm(AR_f10, axis=1), npt.NDArray[np.longdouble]) +assert_type(np.linalg.norm(AR_f10, keepdims=True), npt.NDArray[np.longdouble]) +assert_type(np.linalg.norm(AR_f10_2d, keepdims=True), _Array2D[np.longdouble]) + +assert_type(np.linalg.matrix_norm(AR_i8), npt.NDArray[np.float64] | Any) +assert_type(np.linalg.matrix_norm(AR_f8), npt.NDArray[np.float64] | Any) +assert_type(np.linalg.matrix_norm(AR_c16), npt.NDArray[np.float64] | Any) +assert_type(np.linalg.matrix_norm(AR_U), npt.NDArray[np.float64] | Any) +assert_type(np.linalg.matrix_norm(AR_S), npt.NDArray[np.float64] | Any) +assert_type(np.linalg.matrix_norm(AR_f8_2d), np.float64) +assert_type(np.linalg.matrix_norm(AR_f8_3d), npt.NDArray[np.float64]) +assert_type(np.linalg.matrix_norm(AR_f8_2d, keepdims=True), _Array2D[np.float64]) +assert_type(np.linalg.matrix_norm(AR_f4), npt.NDArray[np.float32] | Any) +assert_type(np.linalg.matrix_norm(AR_c8), npt.NDArray[np.float32] | Any) +assert_type(np.linalg.matrix_norm(AR_f4_2d), np.float32) +assert_type(np.linalg.matrix_norm(AR_f4_3d), npt.NDArray[np.float32]) +assert_type(np.linalg.matrix_norm(AR_f4_2d, keepdims=True), _Array2D[np.float32]) +assert_type(np.linalg.matrix_norm(AR_f10), npt.NDArray[np.longdouble] | Any) +assert_type(np.linalg.matrix_norm(AR_c20), npt.NDArray[np.longdouble] | Any) +assert_type(np.linalg.matrix_norm(AR_f10_2d), np.longdouble) +assert_type(np.linalg.matrix_norm(AR_f10_3d), npt.NDArray[np.longdouble]) +assert_type(np.linalg.matrix_norm(AR_f10_2d, keepdims=True), _Array2D[np.longdouble]) +assert_type(np.linalg.matrix_norm(complex_list_2d), np.float64) +assert_type(np.linalg.matrix_norm(complex_list_3d), npt.NDArray[np.float64]) +assert_type(np.linalg.matrix_norm(complex_list_2d, keepdims=True), npt.NDArray[np.float64]) + +assert_type(np.linalg.vector_norm(AR_i8), np.float64) +assert_type(np.linalg.vector_norm(AR_f8), np.float64) +assert_type(np.linalg.vector_norm(AR_c16), np.float64) +# Mypy incorrectly infers `Any` for datetime64 and timedelta64, but pyright behaves correctly. +assert_type(np.linalg.vector_norm(AR_M), np.float64) # type: ignore[assert-type] +assert_type(np.linalg.vector_norm(AR_m), np.float64) # type: ignore[assert-type] +assert_type(np.linalg.vector_norm(AR_U), np.float64) +assert_type(np.linalg.vector_norm(AR_S), np.float64) +assert_type(np.linalg.vector_norm(AR_f8, axis=0), npt.NDArray[np.float64]) +assert_type(np.linalg.vector_norm(AR_f8, keepdims=True), npt.NDArray[np.float64]) +assert_type(np.linalg.vector_norm(AR_f8_2d, keepdims=True), _Array2D[np.float64]) +assert_type(np.linalg.vector_norm(AR_f2), np.float16) +assert_type(np.linalg.vector_norm(AR_f2, axis=1), npt.NDArray[np.float16]) +assert_type(np.linalg.vector_norm(AR_f2, keepdims=True), npt.NDArray[np.float16]) +assert_type(np.linalg.vector_norm(AR_f2_2d, keepdims=True), _Array2D[np.float16]) +assert_type(np.linalg.vector_norm(AR_f4), np.float32) +assert_type(np.linalg.vector_norm(AR_c8), np.float32) +assert_type(np.linalg.vector_norm(AR_f4, axis=1), npt.NDArray[np.float32]) +assert_type(np.linalg.vector_norm(AR_f4, keepdims=True), npt.NDArray[np.float32]) +assert_type(np.linalg.vector_norm(AR_f4_2d, keepdims=True), _Array2D[np.float32]) +assert_type(np.linalg.vector_norm(AR_f10), np.longdouble) +assert_type(np.linalg.vector_norm(AR_c20), np.longdouble) +assert_type(np.linalg.vector_norm(AR_f10, axis=1), npt.NDArray[np.longdouble]) +assert_type(np.linalg.vector_norm(AR_f10, keepdims=True), npt.NDArray[np.longdouble]) +assert_type(np.linalg.vector_norm(AR_f10_2d, keepdims=True), _Array2D[np.longdouble]) assert_type(np.linalg.tensordot(AR_b, AR_b), npt.NDArray[np.bool]) assert_type(np.linalg.tensordot(AR_i8, AR_i8), npt.NDArray[np.int64]) @@ -234,6 +361,42 @@ assert_type(np.linalg.multi_dot([AR_f8, AR_c16]), Any) assert_type(np.linalg.multi_dot([AR_O, AR_O]), Any) assert_type(np.linalg.multi_dot([AR_m, AR_m]), Any) +# Mypy incorrectly infers `ndarray[Any, Any]`, but pyright behaves correctly. +assert_type(np.linalg.diagonal(AR_any), np.ndarray) # type: ignore[assert-type] +assert_type(np.linalg.diagonal(AR_f4), npt.NDArray[np.float32]) +assert_type(np.linalg.diagonal(AR_f4_2d), np.ndarray[tuple[int], np.dtype[np.float32]]) +assert_type(np.linalg.diagonal(AR_f8_2d), np.ndarray[tuple[int], np.dtype[np.float64]]) +assert_type(np.linalg.diagonal(bool_list_2d), npt.NDArray[np.bool]) +assert_type(np.linalg.diagonal(int_list_2d), npt.NDArray[np.int_]) +assert_type(np.linalg.diagonal(float_list_2d), npt.NDArray[np.float64]) +assert_type(np.linalg.diagonal(complex_list_2d), npt.NDArray[np.complex128]) +assert_type(np.linalg.diagonal(bytes_list_2d), npt.NDArray[np.bytes_]) +assert_type(np.linalg.diagonal(str_list_2d), npt.NDArray[np.str_]) + +assert_type(np.linalg.trace(AR_any), Any) +assert_type(np.linalg.trace(AR_f4), Any) +assert_type(np.linalg.trace(AR_f4_2d), np.float32) +assert_type(np.linalg.trace(AR_f8_2d), np.float64) +assert_type(np.linalg.trace(AR_f4_3d), np.ndarray[tuple[int], np.dtype[np.float32]]) +assert_type(np.linalg.trace(AR_f8_3d), np.ndarray[tuple[int], np.dtype[np.float64]]) +assert_type(np.linalg.trace(AR_f8_4d), np.ndarray[tuple[int, *tuple[Any, ...]], np.dtype[np.float64]]) +assert_type(np.linalg.trace(bool_list_2d), np.bool) +assert_type(np.linalg.trace(int_list_2d), np.int_) +assert_type(np.linalg.trace(float_list_2d), np.float64) +assert_type(np.linalg.trace(complex_list_2d), np.complex128) +assert_type(np.linalg.trace(float_list_3d), npt.NDArray[np.float64]) + +assert_type(np.linalg.outer(bool_list_1d, bool_list_1d), np.ndarray[tuple[int, int], np.dtype[np.bool]]) +assert_type(np.linalg.outer(int_list_1d, int_list_1d), np.ndarray[tuple[int, int], np.dtype[np.int64]]) +assert_type(np.linalg.outer(float_list_1d, float_list_1d), np.ndarray[tuple[int, int], np.dtype[np.float64]]) +assert_type(np.linalg.outer(complex_list_1d, complex_list_1d), np.ndarray[tuple[int, int], np.dtype[np.complex128]]) +assert_type(np.linalg.outer(AR_i8, AR_i8), np.ndarray[tuple[int, int], np.dtype[np.int64]]) +assert_type(np.linalg.outer(AR_f8, AR_f8), np.ndarray[tuple[int, int], np.dtype[np.float64]]) +assert_type(np.linalg.outer(AR_c16, AR_c16), np.ndarray[tuple[int, int], np.dtype[np.complex128]]) +assert_type(np.linalg.outer(AR_b, AR_b), np.ndarray[tuple[int, int], np.dtype[np.bool]]) +assert_type(np.linalg.outer(AR_O, AR_O), np.ndarray[tuple[int, int], np.dtype[np.object_]]) +assert_type(np.linalg.outer(AR_i8, AR_m), np.ndarray[tuple[int, int], np.dtype[np.timedelta64]]) + assert_type(np.linalg.cross(AR_i8, AR_i8), npt.NDArray[np.signedinteger]) assert_type(np.linalg.cross(AR_f8, AR_f8), npt.NDArray[np.floating]) assert_type(np.linalg.cross(AR_c16, AR_c16), npt.NDArray[np.complexfloating]) diff --git a/requirements/test_requirements.txt b/requirements/test_requirements.txt index 3094d4eb8470..e3b17f0fc856 100644 --- a/requirements/test_requirements.txt +++ b/requirements/test_requirements.txt @@ -7,7 +7,7 @@ ninja; sys_platform != "emscripten" pytest-xdist pytest-timeout # For testing types -mypy==1.19.0 +mypy==1.19.1 # for optional f2py encoding detection charset-normalizer tzdata