bit_generator.pyi 3.3 KB

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