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.

121 lines
3.5 KiB

6 months ago
  1. import abc
  2. import sys
  3. from threading import Lock
  4. from typing import (
  5. Any,
  6. Callable,
  7. Dict,
  8. List,
  9. Mapping,
  10. NamedTuple,
  11. Optional,
  12. Sequence,
  13. Tuple,
  14. Type,
  15. TypedDict,
  16. TypeVar,
  17. Union,
  18. overload,
  19. )
  20. from numpy import dtype, ndarray, uint32, uint64
  21. from numpy.typing import _ArrayLikeInt_co, _ShapeLike, _SupportsDType, _UInt32Codes, _UInt64Codes
  22. if sys.version_info >= (3, 8):
  23. from typing import Literal
  24. else:
  25. from typing_extensions import Literal
  26. _T = TypeVar("_T")
  27. _DTypeLikeUint32 = Union[
  28. dtype[uint32],
  29. _SupportsDType[dtype[uint32]],
  30. Type[uint32],
  31. _UInt32Codes,
  32. ]
  33. _DTypeLikeUint64 = Union[
  34. dtype[uint64],
  35. _SupportsDType[dtype[uint64]],
  36. Type[uint64],
  37. _UInt64Codes,
  38. ]
  39. class _SeedSeqState(TypedDict):
  40. entropy: Union[None, int, Sequence[int]]
  41. spawn_key: Tuple[int, ...]
  42. pool_size: int
  43. n_children_spawned: int
  44. class _Interface(NamedTuple):
  45. state_address: Any
  46. state: Any
  47. next_uint64: Any
  48. next_uint32: Any
  49. next_double: Any
  50. bit_generator: Any
  51. class ISeedSequence(abc.ABC):
  52. @abc.abstractmethod
  53. def generate_state(
  54. self, n_words: int, dtype: Union[_DTypeLikeUint32, _DTypeLikeUint64] = ...
  55. ) -> ndarray[Any, dtype[Union[uint32, uint64]]]: ...
  56. class ISpawnableSeedSequence(ISeedSequence):
  57. @abc.abstractmethod
  58. def spawn(self: _T, n_children: int) -> List[_T]: ...
  59. class SeedlessSeedSequence(ISpawnableSeedSequence):
  60. def generate_state(
  61. self, n_words: int, dtype: Union[_DTypeLikeUint32, _DTypeLikeUint64] = ...
  62. ) -> ndarray[Any, dtype[Union[uint32, uint64]]]: ...
  63. def spawn(self: _T, n_children: int) -> List[_T]: ...
  64. class SeedSequence(ISpawnableSeedSequence):
  65. entropy: Union[None, int, Sequence[int]]
  66. spawn_key: Tuple[int, ...]
  67. pool_size: int
  68. n_children_spawned: int
  69. pool: ndarray[Any, dtype[uint32]]
  70. def __init__(
  71. self,
  72. entropy: Union[None, int, Sequence[int], _ArrayLikeInt_co] = ...,
  73. *,
  74. spawn_key: Sequence[int] = ...,
  75. pool_size: int = ...,
  76. n_children_spawned: int = ...,
  77. ) -> None: ...
  78. def __repr__(self) -> str: ...
  79. @property
  80. def state(
  81. self,
  82. ) -> _SeedSeqState: ...
  83. def generate_state(
  84. self, n_words: int, dtype: Union[_DTypeLikeUint32, _DTypeLikeUint64] = ...
  85. ) -> ndarray[Any, dtype[Union[uint32, uint64]]]: ...
  86. def spawn(self, n_children: int) -> List[SeedSequence]: ...
  87. class BitGenerator(abc.ABC):
  88. lock: Lock
  89. def __init__(self, seed: Union[None, _ArrayLikeInt_co, SeedSequence] = ...) -> None: ...
  90. def __getstate__(self) -> Dict[str, Any]: ...
  91. def __setstate__(self, state: Dict[str, Any]) -> None: ...
  92. def __reduce__(
  93. self,
  94. ) -> Tuple[Callable[[str], BitGenerator], Tuple[str], Tuple[Dict[str, Any]]]: ...
  95. @abc.abstractmethod
  96. @property
  97. def state(self) -> Mapping[str, Any]: ...
  98. @state.setter
  99. def state(self, value: Mapping[str, Any]) -> None: ...
  100. @overload
  101. def random_raw(self, size: None = ..., output: Literal[True] = ...) -> int: ... # type: ignore[misc]
  102. @overload
  103. def random_raw(self, size: _ShapeLike = ..., output: Literal[True] = ...) -> ndarray[Any, dtype[uint64]]: ... # type: ignore[misc]
  104. @overload
  105. def random_raw(self, size: Optional[_ShapeLike] = ..., output: Literal[False] = ...) -> None: ... # type: ignore[misc]
  106. def _benchmark(self, cnt: int, method: str = ...) -> None: ...
  107. @property
  108. def ctypes(self) -> _Interface: ...
  109. @property
  110. def cffi(self) -> _Interface: ...