File size: 5,025 Bytes
6370773 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
import sys
from typing import (
TYPE_CHECKING,
ClassVar,
Literal,
TypeAlias,
TypedDict,
TypeVar,
final,
overload,
)
import numpy as np
if sys.version_info >= (3, 11):
from typing import Never
elif TYPE_CHECKING:
from typing_extensions import Never
else:
# `NoReturn` and `Never` are equivalent (but not equal) for type-checkers,
# but are used in different places by convention
from typing import NoReturn as Never
_Device: TypeAlias = Literal["cpu"]
_DeviceLike: TypeAlias = None | _Device
_Capabilities = TypedDict(
"_Capabilities",
{
"boolean indexing": Literal[True],
"data-dependent shapes": Literal[True],
},
)
_DefaultDTypes = TypedDict(
"_DefaultDTypes",
{
"real floating": np.dtype[np.float64],
"complex floating": np.dtype[np.complex128],
"integral": np.dtype[np.intp],
"indexing": np.dtype[np.intp],
},
)
_KindBool: TypeAlias = Literal["bool"]
_KindInt: TypeAlias = Literal["signed integer"]
_KindUInt: TypeAlias = Literal["unsigned integer"]
_KindInteger: TypeAlias = Literal["integral"]
_KindFloat: TypeAlias = Literal["real floating"]
_KindComplex: TypeAlias = Literal["complex floating"]
_KindNumber: TypeAlias = Literal["numeric"]
_Kind: TypeAlias = (
_KindBool
| _KindInt
| _KindUInt
| _KindInteger
| _KindFloat
| _KindComplex
| _KindNumber
)
_T1 = TypeVar("_T1")
_T2 = TypeVar("_T2")
_T3 = TypeVar("_T3")
_Permute1: TypeAlias = _T1 | tuple[_T1]
_Permute2: TypeAlias = tuple[_T1, _T2] | tuple[_T2, _T1]
_Permute3: TypeAlias = (
tuple[_T1, _T2, _T3] | tuple[_T1, _T3, _T2]
| tuple[_T2, _T1, _T3] | tuple[_T2, _T3, _T1]
| tuple[_T3, _T1, _T2] | tuple[_T3, _T2, _T1]
)
class _DTypesBool(TypedDict):
bool: np.dtype[np.bool]
class _DTypesInt(TypedDict):
int8: np.dtype[np.int8]
int16: np.dtype[np.int16]
int32: np.dtype[np.int32]
int64: np.dtype[np.int64]
class _DTypesUInt(TypedDict):
uint8: np.dtype[np.uint8]
uint16: np.dtype[np.uint16]
uint32: np.dtype[np.uint32]
uint64: np.dtype[np.uint64]
class _DTypesInteger(_DTypesInt, _DTypesUInt):
...
class _DTypesFloat(TypedDict):
float32: np.dtype[np.float32]
float64: np.dtype[np.float64]
class _DTypesComplex(TypedDict):
complex64: np.dtype[np.complex64]
complex128: np.dtype[np.complex128]
class _DTypesNumber(_DTypesInteger, _DTypesFloat, _DTypesComplex):
...
class _DTypes(_DTypesBool, _DTypesNumber):
...
class _DTypesUnion(TypedDict, total=False):
bool: np.dtype[np.bool]
int8: np.dtype[np.int8]
int16: np.dtype[np.int16]
int32: np.dtype[np.int32]
int64: np.dtype[np.int64]
uint8: np.dtype[np.uint8]
uint16: np.dtype[np.uint16]
uint32: np.dtype[np.uint32]
uint64: np.dtype[np.uint64]
float32: np.dtype[np.float32]
float64: np.dtype[np.float64]
complex64: np.dtype[np.complex64]
complex128: np.dtype[np.complex128]
_EmptyDict: TypeAlias = dict[Never, Never]
@final
class __array_namespace_info__:
__module__: ClassVar[Literal['numpy']]
def capabilities(self) -> _Capabilities: ...
def default_device(self) -> _Device: ...
def default_dtypes(
self,
*,
device: _DeviceLike = ...,
) -> _DefaultDTypes: ...
def devices(self) -> list[_Device]: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: None = ...,
) -> _DTypes: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: _Permute1[_KindBool],
) -> _DTypesBool: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: _Permute1[_KindInt],
) -> _DTypesInt: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: _Permute1[_KindUInt],
) -> _DTypesUInt: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: _Permute1[_KindFloat],
) -> _DTypesFloat: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: _Permute1[_KindComplex],
) -> _DTypesComplex: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: (
_Permute1[_KindInteger]
| _Permute2[_KindInt, _KindUInt]
),
) -> _DTypesInteger: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: (
_Permute1[_KindNumber]
| _Permute3[_KindInteger, _KindFloat, _KindComplex]
),
) -> _DTypesNumber: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: tuple[()],
) -> _EmptyDict: ...
@overload
def dtypes(
self,
*,
device: _DeviceLike = ...,
kind: tuple[_Kind, ...],
) -> _DTypesUnion: ...
|