bit_generator.pyi 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import abc
  2. from collections.abc import Callable, Mapping, Sequence
  3. from threading import Lock
  4. from typing import Any, ClassVar, Literal, NamedTuple, TypeAlias, TypedDict, overload, type_check_only
  5. from _typeshed import Incomplete
  6. from typing_extensions import CapsuleType, Self
  7. import numpy as np
  8. from numpy._typing import NDArray, _ArrayLikeInt_co, _DTypeLike, _ShapeLike, _UInt32Codes, _UInt64Codes
  9. __all__ = ["BitGenerator", "SeedSequence"]
  10. ###
  11. _DTypeLikeUint_: TypeAlias = _DTypeLike[np.uint32 | np.uint64] | _UInt32Codes | _UInt64Codes
  12. @type_check_only
  13. class _SeedSeqState(TypedDict):
  14. entropy: int | Sequence[int] | None
  15. spawn_key: tuple[int, ...]
  16. pool_size: int
  17. n_children_spawned: int
  18. @type_check_only
  19. class _Interface(NamedTuple):
  20. state_address: Incomplete
  21. state: Incomplete
  22. next_uint64: Incomplete
  23. next_uint32: Incomplete
  24. next_double: Incomplete
  25. bit_generator: Incomplete
  26. @type_check_only
  27. class _CythonMixin:
  28. def __setstate_cython__(self, pyx_state: object, /) -> None: ...
  29. def __reduce_cython__(self) -> Any: ... # noqa: ANN401
  30. @type_check_only
  31. class _GenerateStateMixin(_CythonMixin):
  32. def generate_state(self, /, n_words: int, dtype: _DTypeLikeUint_ = ...) -> NDArray[np.uint32 | np.uint64]: ...
  33. ###
  34. class ISeedSequence(abc.ABC):
  35. @abc.abstractmethod
  36. def generate_state(self, /, n_words: int, dtype: _DTypeLikeUint_ = ...) -> NDArray[np.uint32 | np.uint64]: ...
  37. class ISpawnableSeedSequence(ISeedSequence, abc.ABC):
  38. @abc.abstractmethod
  39. def spawn(self, /, n_children: int) -> list[Self]: ...
  40. class SeedlessSeedSequence(_GenerateStateMixin, ISpawnableSeedSequence):
  41. def spawn(self, /, n_children: int) -> list[Self]: ...
  42. class SeedSequence(_GenerateStateMixin, ISpawnableSeedSequence):
  43. __pyx_vtable__: ClassVar[CapsuleType] = ...
  44. entropy: int | Sequence[int] | None
  45. spawn_key: tuple[int, ...]
  46. pool_size: int
  47. n_children_spawned: int
  48. pool: NDArray[np.uint32]
  49. def __init__(
  50. self,
  51. /,
  52. entropy: _ArrayLikeInt_co | None = None,
  53. *,
  54. spawn_key: Sequence[int] = (),
  55. pool_size: int = 4,
  56. n_children_spawned: int = ...,
  57. ) -> None: ...
  58. def spawn(self, /, n_children: int) -> list[Self]: ...
  59. @property
  60. def state(self) -> _SeedSeqState: ...
  61. class BitGenerator(_CythonMixin, abc.ABC):
  62. lock: Lock
  63. @property
  64. def state(self) -> Mapping[str, Any]: ...
  65. @state.setter
  66. def state(self, value: Mapping[str, Any], /) -> None: ...
  67. @property
  68. def seed_seq(self) -> ISeedSequence: ...
  69. @property
  70. def ctypes(self) -> _Interface: ...
  71. @property
  72. def cffi(self) -> _Interface: ...
  73. @property
  74. def capsule(self) -> CapsuleType: ...
  75. #
  76. def __init__(self, /, seed: _ArrayLikeInt_co | SeedSequence | None = None) -> None: ...
  77. def __reduce__(self) -> tuple[Callable[[str], Self], tuple[str], tuple[Mapping[str, Any], ISeedSequence]]: ...
  78. def spawn(self, /, n_children: int) -> list[Self]: ...
  79. def _benchmark(self, /, cnt: int, method: str = "uint64") -> None: ...
  80. #
  81. @overload
  82. def random_raw(self, /, size: None = None, output: Literal[True] = True) -> int: ...
  83. @overload
  84. def random_raw(self, /, size: _ShapeLike, output: Literal[True] = True) -> NDArray[np.uint64]: ...
  85. @overload
  86. def random_raw(self, /, size: _ShapeLike | None, output: Literal[False]) -> None: ...
  87. @overload
  88. def random_raw(self, /, size: _ShapeLike | None = None, *, output: Literal[False]) -> None: ...