m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

361 lines
7.8 KiB

6 months ago
  1. import sys
  2. import datetime as dt
  3. from typing import Optional, Union, Sequence, Tuple, Any, overload, TypeVar
  4. from numpy import (
  5. ndarray,
  6. number,
  7. integer,
  8. intp,
  9. bool_,
  10. generic,
  11. _OrderKACF,
  12. _OrderACF,
  13. _ModeKind,
  14. _PartitionKind,
  15. _SortKind,
  16. _SortSide,
  17. )
  18. from numpy.typing import (
  19. DTypeLike,
  20. ArrayLike,
  21. _ShapeLike,
  22. _Shape,
  23. _ArrayLikeBool_co,
  24. _ArrayLikeInt_co,
  25. _NumberLike_co,
  26. )
  27. if sys.version_info >= (3, 8):
  28. from typing import Literal
  29. else:
  30. from typing_extensions import Literal
  31. # Various annotations for scalars
  32. # While dt.datetime and dt.timedelta are not technically part of NumPy,
  33. # they are one of the rare few builtin scalars which serve as valid return types.
  34. # See https://github.com/numpy/numpy-stubs/pull/67#discussion_r412604113.
  35. _ScalarNumpy = Union[generic, dt.datetime, dt.timedelta]
  36. _ScalarBuiltin = Union[str, bytes, dt.date, dt.timedelta, bool, int, float, complex]
  37. _Scalar = Union[_ScalarBuiltin, _ScalarNumpy]
  38. # Integers and booleans can generally be used interchangeably
  39. _ScalarGeneric = TypeVar("_ScalarGeneric", bound=generic)
  40. _Number = TypeVar("_Number", bound=number)
  41. # The signature of take() follows a common theme with its overloads:
  42. # 1. A generic comes in; the same generic comes out
  43. # 2. A scalar comes in; a generic comes out
  44. # 3. An array-like object comes in; some keyword ensures that a generic comes out
  45. # 4. An array-like object comes in; an ndarray or generic comes out
  46. def take(
  47. a: ArrayLike,
  48. indices: _ArrayLikeInt_co,
  49. axis: Optional[int] = ...,
  50. out: Optional[ndarray] = ...,
  51. mode: _ModeKind = ...,
  52. ) -> Any: ...
  53. def reshape(
  54. a: ArrayLike,
  55. newshape: _ShapeLike,
  56. order: _OrderACF = ...,
  57. ) -> ndarray: ...
  58. def choose(
  59. a: _ArrayLikeInt_co,
  60. choices: ArrayLike,
  61. out: Optional[ndarray] = ...,
  62. mode: _ModeKind = ...,
  63. ) -> Any: ...
  64. def repeat(
  65. a: ArrayLike,
  66. repeats: _ArrayLikeInt_co,
  67. axis: Optional[int] = ...,
  68. ) -> ndarray: ...
  69. def put(
  70. a: ndarray,
  71. ind: _ArrayLikeInt_co,
  72. v: ArrayLike,
  73. mode: _ModeKind = ...,
  74. ) -> None: ...
  75. def swapaxes(
  76. a: ArrayLike,
  77. axis1: int,
  78. axis2: int,
  79. ) -> ndarray: ...
  80. def transpose(
  81. a: ArrayLike,
  82. axes: Union[None, Sequence[int], ndarray] = ...
  83. ) -> ndarray: ...
  84. def partition(
  85. a: ArrayLike,
  86. kth: _ArrayLikeInt_co,
  87. axis: Optional[int] = ...,
  88. kind: _PartitionKind = ...,
  89. order: Union[None, str, Sequence[str]] = ...,
  90. ) -> ndarray: ...
  91. def argpartition(
  92. a: ArrayLike,
  93. kth: _ArrayLikeInt_co,
  94. axis: Optional[int] = ...,
  95. kind: _PartitionKind = ...,
  96. order: Union[None, str, Sequence[str]] = ...,
  97. ) -> Any: ...
  98. def sort(
  99. a: ArrayLike,
  100. axis: Optional[int] = ...,
  101. kind: Optional[_SortKind] = ...,
  102. order: Union[None, str, Sequence[str]] = ...,
  103. ) -> ndarray: ...
  104. def argsort(
  105. a: ArrayLike,
  106. axis: Optional[int] = ...,
  107. kind: Optional[_SortKind] = ...,
  108. order: Union[None, str, Sequence[str]] = ...,
  109. ) -> ndarray: ...
  110. @overload
  111. def argmax(
  112. a: ArrayLike,
  113. axis: None = ...,
  114. out: Optional[ndarray] = ...,
  115. ) -> intp: ...
  116. @overload
  117. def argmax(
  118. a: ArrayLike,
  119. axis: Optional[int] = ...,
  120. out: Optional[ndarray] = ...,
  121. ) -> Any: ...
  122. @overload
  123. def argmin(
  124. a: ArrayLike,
  125. axis: None = ...,
  126. out: Optional[ndarray] = ...,
  127. ) -> intp: ...
  128. @overload
  129. def argmin(
  130. a: ArrayLike,
  131. axis: Optional[int] = ...,
  132. out: Optional[ndarray] = ...,
  133. ) -> Any: ...
  134. @overload
  135. def searchsorted(
  136. a: ArrayLike,
  137. v: _Scalar,
  138. side: _SortSide = ...,
  139. sorter: Optional[_ArrayLikeInt_co] = ..., # 1D int array
  140. ) -> intp: ...
  141. @overload
  142. def searchsorted(
  143. a: ArrayLike,
  144. v: ArrayLike,
  145. side: _SortSide = ...,
  146. sorter: Optional[_ArrayLikeInt_co] = ..., # 1D int array
  147. ) -> ndarray: ...
  148. def resize(
  149. a: ArrayLike,
  150. new_shape: _ShapeLike,
  151. ) -> ndarray: ...
  152. @overload
  153. def squeeze(
  154. a: _ScalarGeneric,
  155. axis: Optional[_ShapeLike] = ...,
  156. ) -> _ScalarGeneric: ...
  157. @overload
  158. def squeeze(
  159. a: ArrayLike,
  160. axis: Optional[_ShapeLike] = ...,
  161. ) -> ndarray: ...
  162. def diagonal(
  163. a: ArrayLike,
  164. offset: int = ...,
  165. axis1: int = ...,
  166. axis2: int = ..., # >= 2D array
  167. ) -> ndarray: ...
  168. def trace(
  169. a: ArrayLike, # >= 2D array
  170. offset: int = ...,
  171. axis1: int = ...,
  172. axis2: int = ...,
  173. dtype: DTypeLike = ...,
  174. out: Optional[ndarray] = ...,
  175. ) -> Any: ...
  176. def ravel(a: ArrayLike, order: _OrderKACF = ...) -> ndarray: ...
  177. def nonzero(a: ArrayLike) -> Tuple[ndarray, ...]: ...
  178. def shape(a: ArrayLike) -> _Shape: ...
  179. def compress(
  180. condition: ArrayLike, # 1D bool array
  181. a: ArrayLike,
  182. axis: Optional[int] = ...,
  183. out: Optional[ndarray] = ...,
  184. ) -> ndarray: ...
  185. @overload
  186. def clip(
  187. a: ArrayLike,
  188. a_min: ArrayLike,
  189. a_max: Optional[ArrayLike],
  190. out: Optional[ndarray] = ...,
  191. **kwargs: Any,
  192. ) -> Any: ...
  193. @overload
  194. def clip(
  195. a: ArrayLike,
  196. a_min: None,
  197. a_max: ArrayLike,
  198. out: Optional[ndarray] = ...,
  199. **kwargs: Any,
  200. ) -> Any: ...
  201. def sum(
  202. a: ArrayLike,
  203. axis: _ShapeLike = ...,
  204. dtype: DTypeLike = ...,
  205. out: Optional[ndarray] = ...,
  206. keepdims: bool = ...,
  207. initial: _NumberLike_co = ...,
  208. where: _ArrayLikeBool_co = ...,
  209. ) -> Any: ...
  210. @overload
  211. def all(
  212. a: ArrayLike,
  213. axis: None = ...,
  214. out: None = ...,
  215. keepdims: Literal[False] = ...,
  216. ) -> bool_: ...
  217. @overload
  218. def all(
  219. a: ArrayLike,
  220. axis: Optional[_ShapeLike] = ...,
  221. out: Optional[ndarray] = ...,
  222. keepdims: bool = ...,
  223. ) -> Any: ...
  224. @overload
  225. def any(
  226. a: ArrayLike,
  227. axis: None = ...,
  228. out: None = ...,
  229. keepdims: Literal[False] = ...,
  230. ) -> bool_: ...
  231. @overload
  232. def any(
  233. a: ArrayLike,
  234. axis: Optional[_ShapeLike] = ...,
  235. out: Optional[ndarray] = ...,
  236. keepdims: bool = ...,
  237. ) -> Any: ...
  238. def cumsum(
  239. a: ArrayLike,
  240. axis: Optional[int] = ...,
  241. dtype: DTypeLike = ...,
  242. out: Optional[ndarray] = ...,
  243. ) -> ndarray: ...
  244. def ptp(
  245. a: ArrayLike,
  246. axis: Optional[_ShapeLike] = ...,
  247. out: Optional[ndarray] = ...,
  248. keepdims: bool = ...,
  249. ) -> Any: ...
  250. def amax(
  251. a: ArrayLike,
  252. axis: Optional[_ShapeLike] = ...,
  253. out: Optional[ndarray] = ...,
  254. keepdims: bool = ...,
  255. initial: _NumberLike_co = ...,
  256. where: _ArrayLikeBool_co = ...,
  257. ) -> Any: ...
  258. def amin(
  259. a: ArrayLike,
  260. axis: Optional[_ShapeLike] = ...,
  261. out: Optional[ndarray] = ...,
  262. keepdims: bool = ...,
  263. initial: _NumberLike_co = ...,
  264. where: _ArrayLikeBool_co = ...,
  265. ) -> Any: ...
  266. # TODO: `np.prod()``: For object arrays `initial` does not necessarily
  267. # have to be a numerical scalar.
  268. # The only requirement is that it is compatible
  269. # with the `.__mul__()` method(s) of the passed array's elements.
  270. # Note that the same situation holds for all wrappers around
  271. # `np.ufunc.reduce`, e.g. `np.sum()` (`.__add__()`).
  272. def prod(
  273. a: ArrayLike,
  274. axis: Optional[_ShapeLike] = ...,
  275. dtype: DTypeLike = ...,
  276. out: Optional[ndarray] = ...,
  277. keepdims: bool = ...,
  278. initial: _NumberLike_co = ...,
  279. where: _ArrayLikeBool_co = ...,
  280. ) -> Any: ...
  281. def cumprod(
  282. a: ArrayLike,
  283. axis: Optional[int] = ...,
  284. dtype: DTypeLike = ...,
  285. out: Optional[ndarray] = ...,
  286. ) -> ndarray: ...
  287. def ndim(a: ArrayLike) -> int: ...
  288. def size(a: ArrayLike, axis: Optional[int] = ...) -> int: ...
  289. def around(
  290. a: ArrayLike,
  291. decimals: int = ...,
  292. out: Optional[ndarray] = ...,
  293. ) -> Any: ...
  294. def mean(
  295. a: ArrayLike,
  296. axis: Optional[_ShapeLike] = ...,
  297. dtype: DTypeLike = ...,
  298. out: Optional[ndarray] = ...,
  299. keepdims: bool = ...,
  300. ) -> Any: ...
  301. def std(
  302. a: ArrayLike,
  303. axis: Optional[_ShapeLike] = ...,
  304. dtype: DTypeLike = ...,
  305. out: Optional[ndarray] = ...,
  306. ddof: int = ...,
  307. keepdims: bool = ...,
  308. ) -> Any: ...
  309. def var(
  310. a: ArrayLike,
  311. axis: Optional[_ShapeLike] = ...,
  312. dtype: DTypeLike = ...,
  313. out: Optional[ndarray] = ...,
  314. ddof: int = ...,
  315. keepdims: bool = ...,
  316. ) -> Any: ...