11import abc
2+ from binascii import Incomplete
23from collections .abc import Callable , Mapping , Sequence
34from threading import Lock
4- from typing import Any , Generic , Literal , NamedTuple , TypeAlias , TypedDict , overload , type_check_only
5- from typing_extensions import Self , TypeVar
5+ from typing import Any , ClassVar , Generic , Literal as L , NamedTuple , TypeAlias , TypedDict , overload , type_check_only
6+ from typing_extensions import CapsuleType , Self , TypeVar
67
78import numpy as np
89from numpy ._typing import NDArray , _ArrayLikeInt_co , _DTypeLike , _ShapeLike , _UInt32Codes , _UInt64Codes
910
1011__all__ = ["BitGenerator" , "SeedSequence" ]
1112
13+ ###
14+
1215_StateT = TypeVar ("_StateT" , bound = Mapping [str , object ], default = Mapping [str , Any ])
1316
14- _DTypeLikeUint32 : TypeAlias = _DTypeLike [np .uint32 ] | _UInt32Codes
15- _DTypeLikeUint64 : TypeAlias = _DTypeLike [np .uint64 ] | _UInt64Codes
17+ _ToDTypeUInt32 : TypeAlias = _DTypeLike [np .uint32 ] | _UInt32Codes
18+ _ToDTypeUInt64 : TypeAlias = _DTypeLike [np .uint64 ] | _UInt64Codes
1619
1720###
1821
@@ -25,93 +28,96 @@ class _SeedSeqState(TypedDict):
2528
2629@type_check_only
2730class _Interface (NamedTuple ):
28- state_address : Any
29- state : Any
30- next_uint64 : Any
31- next_uint32 : Any
32- next_double : Any
33- bit_generator : Any
34-
35- class ISeedSequence (abc .ABC ):
36- @abc .abstractmethod
37- def generate_state (
38- self ,
39- n_words : int ,
40- dtype : _DTypeLikeUint32 | _DTypeLikeUint64 = ...,
41- ) -> NDArray [np .uint32 | np .uint64 ]: ...
42-
43- class ISpawnableSeedSequence (ISeedSequence , abc .ABC ):
44- @abc .abstractmethod
45- def spawn (self , n_children : int ) -> list [Self ]: ...
46-
47- class SeedlessSeedSequence (ISpawnableSeedSequence ):
48- def generate_state (
49- self ,
50- n_words : int ,
51- dtype : _DTypeLikeUint32 | _DTypeLikeUint64 = ...,
52- ) -> NDArray [np .uint32 | np .uint64 ]: ...
53- def spawn (self , n_children : int ) -> list [Self ]: ...
31+ state_address : Incomplete
32+ state : Incomplete
33+ next_uint64 : Incomplete
34+ next_uint32 : Incomplete
35+ next_double : Incomplete
36+ bit_generator : Incomplete
5437
55- class SeedSequence (ISpawnableSeedSequence ):
56- entropy : int | Sequence [int ] | None
57- spawn_key : tuple [int , ...]
58- pool_size : int
59- n_children_spawned : int
60- pool : NDArray [np .uint32 ]
38+ @type_check_only
39+ class _CythonMixin :
40+ def __setstate_cython__ (self , pyx_state : object , / ) -> None : ...
41+ def __reduce_cython__ (self ) -> Any : ...
6142
62- @property
63- def state (self ) -> _SeedSeqState : ...
43+ @type_check_only
44+ class _GenerateStateMixin (_CythonMixin ):
45+ @overload
46+ def generate_state (self , / , n_words : int , dtype : _ToDTypeUInt32 = ...) -> NDArray [np .uint32 ]: ...
47+ @overload
48+ def generate_state (self , / , n_words : int , dtype : _ToDTypeUInt64 ) -> NDArray [np .uint64 ]: ...
49+ @overload
50+ def generate_state (self , / , n_words : int , dtype : _ToDTypeUInt32 | _ToDTypeUInt64 = ...) -> NDArray [np .uint32 | np .uint64 ]: ...
6451
65- #
66- def __init__ (
67- self ,
68- entropy : int | Sequence [int ] | _ArrayLikeInt_co | None = None ,
69- * ,
70- spawn_key : Sequence [int ] = ...,
71- pool_size : int = ...,
72- n_children_spawned : int = ...,
73- ) -> None : ...
74- def generate_state (
75- self ,
76- n_words : int ,
77- dtype : _DTypeLikeUint32 | _DTypeLikeUint64 = ...,
78- ) -> NDArray [np .uint32 | np .uint64 ]: ...
79- def spawn (self , n_children : int ) -> list [SeedSequence ]: ...
52+ ###
8053
81- class BitGenerator (abc .ABC , Generic [_StateT ]):
54+ class BitGenerator (_CythonMixin , abc .ABC , Generic [_StateT ]):
8255 lock : Lock
8356
84- def __init__ (self , / , seed : _ArrayLikeInt_co | SeedSequence | None = None ) -> None : ...
85- def __getstate__ (self ) -> tuple [_StateT , ISeedSequence ]: ...
86- def __setstate__ (self , state_seed_seq : _StateT | tuple [Mapping [str , Any ], ISeedSequence ]) -> None : ...
87- def __reduce__ (self ) -> tuple [Callable [[str ], Self ], tuple [str ], tuple [Mapping [str , Any ], ISeedSequence ]]: ...
88-
8957 #
9058 @property
9159 def state (self , / ) -> _StateT : ...
9260 @state .setter
9361 def state (self , state : _StateT , / ) -> None : ...
94-
95- #
9662 @property
9763 def seed_seq (self ) -> ISeedSequence : ...
9864 @property
9965 def ctypes (self ) -> _Interface : ...
10066 @property
10167 def cffi (self ) -> _Interface : ...
68+ @property
69+ def capsule (self ) -> CapsuleType : ...
10270
10371 #
104- def spawn (self , n_children : int ) -> list [Self ]: ...
72+ def __init__ (self , / , seed : _ArrayLikeInt_co | SeedSequence | None = None ) -> None : ...
73+ def __reduce__ (self ) -> tuple [Callable [[str ], Self ], tuple [str ], tuple [Mapping [str , Any ], ISeedSequence ]]: ...
74+ def spawn (self , / , n_children : int ) -> list [Self ]: ...
75+ def _benchmark (self , / , cnt : int , method : str = "uint64" ) -> None : ...
10576
10677 #
10778 @overload
108- def random_raw (self , / , size : None = None , output : Literal [True ] = True ) -> int : ...
79+ def random_raw (self , / , size : None = None , output : L [True ] = True ) -> int : ...
10980 @overload
110- def random_raw (self , / , size : _ShapeLike , output : Literal [True ] = True ) -> NDArray [np .uint64 ]: ...
81+ def random_raw (self , / , size : _ShapeLike , output : L [True ] = True ) -> NDArray [np .uint64 ]: ...
11182 @overload
112- def random_raw (self , / , size : _ShapeLike | None , output : Literal [False ]) -> None : ...
83+ def random_raw (self , / , size : _ShapeLike | None , output : L [False ]) -> None : ...
11384 @overload
114- def random_raw (self , / , size : _ShapeLike | None = None , * , output : Literal [False ]) -> None : ...
85+ def random_raw (self , / , size : _ShapeLike | None = None , * , output : L [False ]) -> None : ...
86+
87+ ###
88+
89+ class ISeedSequence (abc .ABC ):
90+ @abc .abstractmethod
91+ def generate_state (self , / , n_words : int , dtype : _ToDTypeUInt32 | _ToDTypeUInt64 = ...) -> NDArray [np .uint32 | np .uint64 ]: ...
92+
93+ class ISpawnableSeedSequence (ISeedSequence , abc .ABC ):
94+ @abc .abstractmethod
95+ def spawn (self , / , n_children : int ) -> list [Self ]: ...
96+
97+ class SeedlessSeedSequence (_GenerateStateMixin , ISpawnableSeedSequence ):
98+ def spawn (self , / , n_children : int ) -> list [Self ]: ...
11599
100+ class SeedSequence (_GenerateStateMixin , ISpawnableSeedSequence ):
101+ __pyx_vtable__ : ClassVar [CapsuleType ] = ...
102+
103+ entropy : int | Sequence [int ] | None
104+ spawn_key : tuple [int , ...]
105+ pool_size : int
106+ n_children_spawned : int
107+ pool : NDArray [np .uint32 ]
108+
109+ def __init__ (
110+ self ,
111+ / ,
112+ entropy : _ArrayLikeInt_co | None = None ,
113+ * ,
114+ spawn_key : Sequence [int ] = (),
115+ pool_size : int = 4 ,
116+ n_children_spawned : int = ...,
117+ ) -> None : ...
118+
119+ #
120+ def spawn (self , / , n_children : int ) -> list [Self ]: ...
116121 #
117- def _benchmark (self , cnt : int , method : str = ...) -> None : ...
122+ @property
123+ def state (self ) -> _SeedSeqState : ...
0 commit comments