1
1
import abc
2
+ from binascii import Incomplete
2
3
from collections .abc import Callable , Mapping , Sequence
3
4
from 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
6
7
7
8
import numpy as np
8
9
from numpy ._typing import NDArray , _ArrayLikeInt_co , _DTypeLike , _ShapeLike , _UInt32Codes , _UInt64Codes
9
10
10
11
__all__ = ["BitGenerator" , "SeedSequence" ]
11
12
13
+ ###
14
+
12
15
_StateT = TypeVar ("_StateT" , bound = Mapping [str , object ], default = Mapping [str , Any ])
13
16
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
16
19
17
20
###
18
21
@@ -25,93 +28,96 @@ class _SeedSeqState(TypedDict):
25
28
26
29
@type_check_only
27
30
class _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
54
37
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 : ...
61
42
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 ]: ...
64
51
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
+ ###
80
53
81
- class BitGenerator (abc .ABC , Generic [_StateT ]):
54
+ class BitGenerator (_CythonMixin , abc .ABC , Generic [_StateT ]):
82
55
lock : Lock
83
56
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
-
89
57
#
90
58
@property
91
59
def state (self , / ) -> _StateT : ...
92
60
@state .setter
93
61
def state (self , state : _StateT , / ) -> None : ...
94
-
95
- #
96
62
@property
97
63
def seed_seq (self ) -> ISeedSequence : ...
98
64
@property
99
65
def ctypes (self ) -> _Interface : ...
100
66
@property
101
67
def cffi (self ) -> _Interface : ...
68
+ @property
69
+ def capsule (self ) -> CapsuleType : ...
102
70
103
71
#
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 : ...
105
76
106
77
#
107
78
@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 : ...
109
80
@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 ]: ...
111
82
@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 : ...
113
84
@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 ]: ...
115
99
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 ]: ...
116
121
#
117
- def _benchmark (self , cnt : int , method : str = ...) -> None : ...
122
+ @property
123
+ def state (self ) -> _SeedSeqState : ...
0 commit comments