14
14
the Action class from libsemigroups.
15
15
"""
16
16
17
- # TODO add _ as prefix of everything imported
18
-
19
17
from typing import Any , Union , Iterator
20
- from typing_extensions import Self
18
+ from typing_extensions import Self as _Self
21
19
22
20
from _libsemigroups_pybind11 import (
23
- RightActionBMat8BMat8 as _RightActionBMat8BMat8 ,
21
+ BMat8 as _BMat8 ,
24
22
LeftActionBMat8BMat8 as _LeftActionBMat8BMat8 ,
25
- RightActionPPerm1List as _RightActionPPerm1List ,
26
- RightActionPPerm2List as _RightActionPPerm2List ,
27
- RightActionPPerm4List as _RightActionPPerm4List ,
28
- RightActionPPerm1PPerm1 as _RightActionPPerm1PPerm1 ,
29
23
LeftActionPPerm1List as _LeftActionPPerm1List ,
24
+ LeftActionPPerm1PPerm1 as _LeftActionPPerm1PPerm1 ,
30
25
LeftActionPPerm2List as _LeftActionPPerm2List ,
31
26
LeftActionPPerm4List as _LeftActionPPerm4List ,
32
- LeftActionPPerm1PPerm1 as _LeftActionPPerm1PPerm1 ,
33
- RightActionTransf1List as _RightActionTransf1List ,
34
- RightActionTransf2List as _RightActionTransf2List ,
35
- RightActionTransf4List as _RightActionTransf4List ,
36
27
LeftActionTransf1List as _LeftActionTransf1List ,
37
28
LeftActionTransf2List as _LeftActionTransf2List ,
38
29
LeftActionTransf4List as _LeftActionTransf4List ,
39
30
PPerm1 as _PPerm1 ,
40
31
PPerm2 as _PPerm2 ,
41
32
PPerm4 as _PPerm4 ,
33
+ RightActionBMat8BMat8 as _RightActionBMat8BMat8 ,
34
+ RightActionPPerm1List as _RightActionPPerm1List ,
35
+ RightActionPPerm1PPerm1 as _RightActionPPerm1PPerm1 ,
36
+ RightActionPPerm2List as _RightActionPPerm2List ,
37
+ RightActionPPerm4List as _RightActionPPerm4List ,
38
+ RightActionTransf1List as _RightActionTransf1List ,
39
+ RightActionTransf2List as _RightActionTransf2List ,
40
+ RightActionTransf4List as _RightActionTransf4List ,
42
41
Transf1 as _Transf1 ,
43
42
Transf2 as _Transf2 ,
44
43
Transf4 as _Transf4 ,
44
+ UNDEFINED as _UNDEFINED ,
45
+ side ,
45
46
)
46
47
47
- from _libsemigroups_pybind11 import BMat8 , side , UNDEFINED
48
-
49
- from .adapters import ImageRightAction , ImageLeftAction
50
- from .transf import PPerm , Transf
48
+ from .adapters import (
49
+ ImageRightAction as _ImageRightAction ,
50
+ ImageLeftAction as _ImageLeftAction ,
51
+ )
52
+ from .transf import PPerm as _PPerm , Transf as _Transf
51
53
52
- from .detail .cxx_wrapper import to_cxx , to_py , CxxWrapper as _CxxWrapper
54
+ from .detail .cxx_wrapper import (
55
+ to_cxx as _to_cxx ,
56
+ to_py as _to_py ,
57
+ CxxWrapper as _CxxWrapper ,
58
+ )
53
59
54
60
55
61
# TODO doc
56
- class Action (
57
- _CxxWrapper
58
- ): # pylint: disable=invalid-name, too-many-instance-attributes, no-member
62
+ class Action (_CxxWrapper ):
59
63
"""
60
64
The documentation for this class is taken from RightActionPPerm1List in
61
65
src/action.cpp!
62
66
"""
63
67
64
68
_py_template_params_to_cxx_type = {
65
- (BMat8 , BMat8 , ImageRightAction , side .right ): _RightActionBMat8BMat8 ,
66
- (BMat8 , BMat8 , ImageLeftAction , side .left ): _LeftActionBMat8BMat8 ,
67
- (PPerm , PPerm , ImageRightAction , side .right ): {
69
+ (_BMat8 , _BMat8 , _ImageRightAction , side .right ): _RightActionBMat8BMat8 ,
70
+ (_BMat8 , _BMat8 , _ImageLeftAction , side .left ): _LeftActionBMat8BMat8 ,
71
+ (_PPerm , _PPerm , _ImageRightAction , side .right ): {
68
72
(
69
73
_PPerm1 ,
70
74
_PPerm1 ,
71
- ImageRightAction ,
75
+ _ImageRightAction ,
72
76
side .right ,
73
77
): _RightActionPPerm1PPerm1 ,
74
78
},
75
- (PPerm , PPerm , ImageLeftAction , side .left ): {
79
+ (_PPerm , _PPerm , _ImageLeftAction , side .left ): {
76
80
(
77
81
_PPerm1 ,
78
82
_PPerm1 ,
79
- ImageLeftAction ,
83
+ _ImageLeftAction ,
80
84
side .left ,
81
85
): _LeftActionPPerm1PPerm1 ,
82
86
},
83
- (PPerm , list , ImageRightAction , side .right ): {
87
+ (_PPerm , list , _ImageRightAction , side .right ): {
84
88
(
85
89
_PPerm1 ,
86
90
list ,
87
- ImageRightAction ,
91
+ _ImageRightAction ,
88
92
side .right ,
89
93
): _RightActionPPerm1List ,
90
94
(
91
95
_PPerm2 ,
92
96
list ,
93
- ImageRightAction ,
97
+ _ImageRightAction ,
94
98
side .right ,
95
99
): _RightActionPPerm2List ,
96
100
(
97
101
_PPerm4 ,
98
102
list ,
99
- ImageRightAction ,
103
+ _ImageRightAction ,
100
104
side .right ,
101
105
): _RightActionPPerm4List ,
102
106
},
103
- (PPerm , list , ImageLeftAction , side .left ): {
107
+ (_PPerm , list , _ImageLeftAction , side .left ): {
104
108
(
105
109
_PPerm1 ,
106
110
list ,
107
- ImageLeftAction ,
111
+ _ImageLeftAction ,
108
112
side .left ,
109
113
): _LeftActionPPerm1List ,
110
- (
111
- _PPerm1 ,
112
- list ,
113
- ImageLeftAction ,
114
- side .right , # TODO left?
115
- ): _LeftActionPPerm1List ,
116
114
(
117
115
_PPerm2 ,
118
116
list ,
119
- ImageLeftAction ,
120
- side .right , # TODO left?
117
+ _ImageLeftAction ,
118
+ side .left ,
121
119
): _LeftActionPPerm2List ,
122
120
(
123
121
_PPerm4 ,
124
122
list ,
125
- ImageLeftAction ,
126
- side .right , # TODO left?
123
+ _ImageLeftAction ,
124
+ side .left ,
127
125
): _LeftActionPPerm4List ,
128
126
},
129
- (Transf , list , ImageRightAction , side .right ): {
127
+ (_Transf , list , _ImageRightAction , side .right ): {
130
128
(
131
129
_Transf1 ,
132
130
list ,
133
- ImageRightAction ,
131
+ _ImageRightAction ,
134
132
side .right ,
135
133
): _RightActionTransf1List ,
136
134
(
137
135
_Transf2 ,
138
136
list ,
139
- ImageRightAction ,
137
+ _ImageRightAction ,
140
138
side .right ,
141
139
): _RightActionTransf2List ,
142
140
(
143
141
_Transf4 ,
144
142
list ,
145
- ImageRightAction ,
143
+ _ImageRightAction ,
146
144
side .right ,
147
145
): _RightActionTransf4List ,
148
146
},
149
- (Transf , list , ImageLeftAction , side .left ): {
147
+ (_Transf , list , _ImageLeftAction , side .left ): {
150
148
(
151
149
_Transf1 ,
152
150
list ,
153
- ImageLeftAction ,
151
+ _ImageLeftAction ,
154
152
side .left ,
155
153
): _LeftActionTransf1List ,
156
154
(
157
155
_Transf2 ,
158
156
list ,
159
- ImageLeftAction ,
157
+ _ImageLeftAction ,
160
158
side .left ,
161
159
): _LeftActionTransf2List ,
162
160
(
163
161
_Transf4 ,
164
162
list ,
165
- ImageLeftAction ,
163
+ _ImageLeftAction ,
166
164
side .left ,
167
165
): _LeftActionTransf4List ,
168
166
},
@@ -171,7 +169,7 @@ class Action(
171
169
# TODO _cxx_type_to_py_template_params??
172
170
# TODO _all_wrapped_cxx_types
173
171
174
- def __init__ (self : Self , ** kwargs ):
172
+ def __init__ (self : _Self , ** kwargs ):
175
173
super ().__init__ (
176
174
required_kwargs = ("Element" , "Point" , "Func" , "Side" ), ** kwargs
177
175
)
@@ -181,11 +179,11 @@ def __init__(self: Self, **kwargs):
181
179
self .Side = kwargs ["Side" ]
182
180
self .init ()
183
181
184
- def __getattr__ (self : Self , meth_name : str ) -> Any :
182
+ def __getattr__ (self : _Self , meth_name : str ) -> Any :
185
183
self ._init_cxx_obj ()
186
184
return super ().__getattr__ (meth_name )
187
185
188
- def _init_cxx_obj (self : Self ) -> None :
186
+ def _init_cxx_obj (self : _Self ) -> None :
189
187
# pylint: disable=attribute-defined-outside-init
190
188
if self ._cxx_obj is not None :
191
189
return
@@ -208,13 +206,13 @@ def _init_cxx_obj(self: Self) -> None:
208
206
self ._cxx_obj = cxx_obj_t ()
209
207
210
208
for x in self ._generators :
211
- self ._cxx_obj .add_generator (to_cxx (x ))
209
+ self ._cxx_obj .add_generator (_to_cxx (x ))
212
210
for x in self ._seeds :
213
- self ._cxx_obj .add_seed (to_cxx (x ))
211
+ self ._cxx_obj .add_seed (_to_cxx (x ))
214
212
self ._cxx_obj .cache_scc_multipliers (self ._cache_scc_multipliers )
215
213
self ._cxx_obj .reserve (self ._reserve )
216
214
217
- def __repr__ (self : Self ) -> str :
215
+ def __repr__ (self : _Self ) -> str :
218
216
result = super ().__repr__ ()
219
217
if result :
220
218
return result
@@ -223,20 +221,20 @@ def __repr__(self: Self) -> str:
223
221
f"{ len (self ._seeds )} points>"
224
222
)
225
223
226
- def __getitem__ (self : Self , pos : int ) -> Any :
224
+ def __getitem__ (self : _Self , pos : int ) -> Any :
227
225
self ._init_cxx_obj ()
228
- return to_py (self .Point , self ._cxx_obj [pos ])
226
+ return _to_py (self .Point , self ._cxx_obj [pos ])
229
227
230
- def __len__ (self : Self ):
228
+ def __len__ (self : _Self ):
231
229
self ._init_cxx_obj ()
232
230
return getattr (self ._cxx_obj , "size" )()
233
231
234
232
# TODO type annotations
235
- def index (self : Self , x ) -> int :
233
+ def index (self : _Self , x ) -> int :
236
234
self ._init_cxx_obj ()
237
- return getattr (self ._cxx_obj , "position" )(to_cxx (x ))
235
+ return getattr (self ._cxx_obj , "position" )(_to_cxx (x ))
238
236
239
- def add_generator (self : Self , x : Any ) -> Self :
237
+ def add_generator (self : _Self , x : Any ) -> _Self :
240
238
if not isinstance (x , self .Element ):
241
239
raise ValueError (
242
240
"the argument (generator) has incorrect type, expected "
@@ -253,26 +251,26 @@ def add_generator(self: Self, x: Any) -> Self:
253
251
)
254
252
255
253
if self ._cxx_obj is not None :
256
- self ._cxx_obj .add_generator (to_cxx (x ))
254
+ self ._cxx_obj .add_generator (_to_cxx (x ))
257
255
else :
258
256
self ._generators .append (x )
259
257
return self
260
258
261
- def add_seed (self : Self , x : Any ) -> Self :
259
+ def add_seed (self : _Self , x : Any ) -> _Self :
262
260
if not isinstance (x , self .Point ):
263
261
raise ValueError (
264
262
"the argument (seed) has incorrect type, expected "
265
263
f"{ self .Element } but found { type (x )} "
266
264
)
267
265
if self ._cxx_obj is not None :
268
- self ._cxx_obj .add_seed (to_cxx (x ))
266
+ self ._cxx_obj .add_seed (_to_cxx (x ))
269
267
else :
270
268
# TODO check compatibility of x with things already in _seeds,
271
269
# i.e. degree. Not currently sure how to do this
272
270
self ._seeds .append (x )
273
271
return self
274
272
275
- def cache_scc_multipliers (self : Self , * args ) -> Union [Self , bool ]:
273
+ def cache_scc_multipliers (self : _Self , * args ) -> Union [_Self , bool ]:
276
274
# pylint: disable=attribute-defined-outside-init
277
275
if self ._cxx_obj is not None :
278
276
return self ._cxx_obj .cache_scc_multipliers (* args )
@@ -285,48 +283,48 @@ def cache_scc_multipliers(self: Self, *args) -> Union[Self, bool]:
285
283
f"expected 0 arguments or 1 argument (a bool), found { len (args )} arguments"
286
284
)
287
285
288
- def current_size (self : Self ) -> int :
286
+ def current_size (self : _Self ) -> int :
289
287
if self ._cxx_obj is not None :
290
288
return self ._cxx_obj .current_size ()
291
289
return len (self ._seeds )
292
290
293
- def empty (self : Self ) -> bool :
291
+ def empty (self : _Self ) -> bool :
294
292
return self .current_size () != 0
295
293
296
- def init (self : Self ) -> Self :
294
+ def init (self : _Self ) -> _Self :
297
295
self ._generators = []
298
296
self ._seeds = []
299
297
self ._cache_scc_multipliers = False
300
298
self ._reserve = 0
301
299
self ._cxx_obj = None
302
300
return self
303
301
304
- def multiplier_from_scc_root (self : Self , pos : int ) -> Any :
302
+ def multiplier_from_scc_root (self : _Self , pos : int ) -> Any :
305
303
self ._init_cxx_obj ()
306
- return to_py (self .Element , self ._cxx_obj .multiplier_from_scc_root (pos ))
304
+ return _to_py (self .Element , self ._cxx_obj .multiplier_from_scc_root (pos ))
307
305
308
- def multiplier_to_scc_root (self : Self , pos : int ) -> Any :
306
+ def multiplier_to_scc_root (self : _Self , pos : int ) -> Any :
309
307
self ._init_cxx_obj ()
310
- return to_py (self .Element , self ._cxx_obj .multiplier_to_scc_root (pos ))
308
+ return _to_py (self .Element , self ._cxx_obj .multiplier_to_scc_root (pos ))
311
309
312
- def number_of_generators (self : Self ) -> int :
310
+ def number_of_generators (self : _Self ) -> int :
313
311
if self ._cxx_obj is None :
314
312
return len (self ._generators )
315
313
316
314
return self ._cxx_obj .number_of_generators ()
317
315
318
- def __contains__ (self : Self , pt : Any ) -> bool :
319
- return self .index (pt ) != UNDEFINED
316
+ def __contains__ (self : _Self , pt : Any ) -> bool :
317
+ return self .index (pt ) != _UNDEFINED
320
318
321
- def reserve (self : Self , val : int ) -> Self :
319
+ def reserve (self : _Self , val : int ) -> _Self :
322
320
# pylint: disable=attribute-defined-outside-init
323
321
if self ._cxx_obj is None :
324
322
self ._reserve = val
325
323
else :
326
324
self ._cxx_obj .reserve (val )
327
325
return self
328
326
329
- def root_of_scc (self : Self , x : Any ) -> Any :
327
+ def root_of_scc (self : _Self , x : Any ) -> Any :
330
328
if not isinstance (x , self .Element ) and not isinstance (x , int ):
331
329
raise ValueError (
332
330
"the 1st argument has incorrect type expected "
@@ -335,7 +333,7 @@ def root_of_scc(self: Self, x: Any) -> Any:
335
333
336
334
self .run ()
337
335
if isinstance (x , self .Element ):
338
- x = to_cxx (x )
336
+ x = _to_cxx (x )
339
337
return self ._cxx_obj .root_of_scc (x )
340
338
341
339
@@ -344,7 +342,7 @@ def root_of_scc(self: Self, x: Any) -> Any:
344
342
345
343
346
344
def RightAction (
347
- Func = ImageRightAction , ** kwargs
345
+ Func = _ImageRightAction , ** kwargs
348
346
): # pylint: disable=invalid-name
349
347
"""
350
348
Construct a right :any:`RightActionPPerm1List` instance.
@@ -364,7 +362,7 @@ def RightAction(
364
362
)
365
363
366
364
367
- def LeftAction (Func = ImageLeftAction , ** kwargs ): # pylint: disable=invalid-name
365
+ def LeftAction (Func = _ImageLeftAction , ** kwargs ): # pylint: disable=invalid-name
368
366
"""
369
367
Construct a left :any:`RightActionPPerm1List` instance.
370
368
0 commit comments