13
13
various adapters from libsemigroups.
14
14
"""
15
15
16
- from typing import Any
16
+ from typing import Any , Union , Iterator , TypeVar as _TypeVar , List
17
17
18
- from typing_extensions import Self
18
+ from typing_extensions import Self as _Self
19
19
20
20
from _libsemigroups_pybind11 import (
21
- ImageRightActionBMat8BMat8 as _ImageRightActionBMat8BMat8 ,
22
- ImageLeftActionBMat8BMat8 as _ImageLeftActionBMat8BMat8 ,
23
- ImageRightActionPPerm1PPerm1 as _ImageRightActionPPerm1PPerm1 ,
24
- ImageLeftActionPPerm1PPerm1 as _ImageLeftActionPPerm1PPerm1 ,
25
- ImageRightActionPPerm1List as _ImageRightActionPPerm1List ,
26
21
# TODO Transf
27
22
# TODO other pperms
28
23
BMat8 as _BMat8 ,
24
+ ImageLeftActionBMat8BMat8 as _ImageLeftActionBMat8BMat8 ,
25
+ ImageLeftActionPPerm1PPerm1 as _ImageLeftActionPPerm1PPerm1 ,
26
+ ImageRightActionBMat8BMat8 as _ImageRightActionBMat8BMat8 ,
27
+ ImageRightActionPPerm1List as _ImageRightActionPPerm1List ,
28
+ ImageRightActionPPerm1PPerm1 as _ImageRightActionPPerm1PPerm1 ,
29
29
PPerm1 as _PPerm1 ,
30
30
)
31
31
32
- from .detail .cxx_wrapper import CxxWrapper , to_cxx , to_py
32
+ from .detail .cxx_wrapper import (
33
+ CxxWrapper as _CxxWrapper ,
34
+ to_cxx as _to_cxx ,
35
+ to_py_new as _to_py ,
36
+ )
33
37
34
38
from .tools import ordinal
35
- from .transf import PPerm
36
-
37
-
38
- class _ImageAction (CxxWrapper ):
39
- def __init__ (self : Self , ** kwargs ):
40
- super ().__init__ (required_kwargs = ("Element" , "Point" ), ** kwargs )
41
- self .Element = kwargs ["Element" ]
42
- self .Point = kwargs ["Point" ]
43
-
44
- def _init_cxx_obj (self : Self , elt : Any , pt : Any ) -> Any :
45
- cxx_obj_t = self ._cxx_obj_type_from (samples = (elt , pt ))
46
- if self ._cxx_obj is None or not isinstance (self ._cxx_obj , cxx_obj_t ):
47
- self ._cxx_obj = cxx_obj_t ()
48
- return self ._cxx_obj
49
-
50
- def __call__ ( # pylint: disable=inconsistent-return-statements
51
- self : Self , * args
52
- ):
53
- # Point1, Point2, Element -> Point1 = Point2 ^ Element
54
- if 2 > len (args ) or len (args ) > 3 :
55
- raise TypeError (f"expected 2 or 3 arguments, found { len (args )} " )
56
- pt = args [- 2 ]
57
- x = args [- 1 ]
58
- if not isinstance (pt , self .Point ):
59
- raise ValueError (
60
- f"the { ordinal (len (args ) - 2 )} argument (point) has incorrect type, "
61
- f"expected { self .Point } but found { type (pt )} "
62
- )
63
- if not isinstance (x , self .Element ):
64
- raise ValueError (
65
- f"the { ordinal (len (args ) - 1 )} argument (element) has incorrect type, "
66
- f"expected { self .Element } but found { type (x )} "
67
- )
68
- if len (args ) == 3 :
69
- res = args [0 ]
70
- if not isinstance (res , self .Point ):
71
- raise ValueError (
72
- "the 1st argument (result) has incorrect type, "
73
- f"expected { self .Point } but found { type (res )} "
74
- )
75
- if len (args ) == 3 and self .Point is list :
76
- raise NotImplementedError ("not yet implemented" )
77
-
78
- self ._init_cxx_obj (x , pt )
79
- return to_py (
80
- self .Element , self ._cxx_obj (* (to_cxx (arg ) for arg in args ))
39
+ from .transf import PPerm as _PPerm
40
+
41
+
42
+ class _ImageAction (_CxxWrapper ):
43
+ """
44
+ This is a protected base class for ImageRightAction and ImageLeftAction.
45
+ """
46
+
47
+ Element = _TypeVar ("Element" )
48
+ Point = _TypeVar ("Point" )
49
+
50
+ def __init__ (self : _Self , * args , point = None , element = None ) -> None :
51
+ """
52
+ TODO
53
+ Note to self <point> and <element> are the types of the objects used by
54
+ this function not examples of such objects.
55
+ """
56
+ super ().__init__ (
57
+ * args ,
58
+ required_kwargs = ("element" , "point" ),
59
+ point = point ,
60
+ element = element ,
61
+ )
62
+ if _to_cxx (self ) is not None :
63
+ return
64
+ if len (args ) != 0 :
65
+ raise ValueError (f"expected 0 positional arguments, but found { len (args )} " )
66
+ self .py_template_params = (
67
+ type (_to_cxx (element )),
68
+ type (_to_cxx (point )),
81
69
)
70
+ self .init_cxx_obj ()
71
+
72
+ def __call__ (self : _Self , * args ):
73
+ return _to_py (_to_cxx (self )(* (_to_cxx (x ) for x in args )))
82
74
83
75
84
76
class ImageRightAction (_ImageAction ):
85
- # pylint: disable=too-few-public-methods, unused-private-member
86
- """
77
+ """TODO update
87
78
Construct a ImageRightAction instance.
88
79
89
80
:Keyword Arguments:
@@ -93,18 +84,22 @@ class ImageRightAction(_ImageAction):
93
84
94
85
_py_template_params_to_cxx_type = {
95
86
(_BMat8 , _BMat8 ): _ImageRightActionBMat8BMat8 ,
96
- (PPerm , PPerm ): {
97
- (_PPerm1 , _PPerm1 ): _ImageRightActionPPerm1PPerm1 ,
98
- },
99
- (PPerm , list ): {
100
- (_PPerm1 , list ): _ImageRightActionPPerm1List ,
101
- },
87
+ (_PPerm1 , _PPerm1 ): _ImageRightActionPPerm1PPerm1 ,
88
+ (_PPerm1 , list ): _ImageRightActionPPerm1List ,
102
89
}
103
90
91
+ _cxx_type_to_py_template_params = dict (
92
+ zip (
93
+ _py_template_params_to_cxx_type .values (),
94
+ _py_template_params_to_cxx_type .keys (),
95
+ )
96
+ )
104
97
105
- class ImageLeftAction (_ImageAction ): # pylint: disable=invalid-name
106
- # pylint: disable=too-few-public-methods, unused-private-member
107
- """
98
+ _all_wrapped_cxx_types = {* _py_template_params_to_cxx_type .values ()}
99
+
100
+
101
+ class ImageLeftAction (_ImageAction ):
102
+ """TODO update
108
103
Construct a ImageLeftAction instance.
109
104
110
105
:Keyword Arguments:
@@ -114,7 +109,14 @@ class ImageLeftAction(_ImageAction): # pylint: disable=invalid-name
114
109
115
110
_py_template_params_to_cxx_type = {
116
111
(_BMat8 , _BMat8 ): _ImageLeftActionBMat8BMat8 ,
117
- (PPerm , PPerm ): {
118
- (_PPerm1 , _PPerm1 ): _ImageLeftActionPPerm1PPerm1 ,
119
- },
112
+ (_PPerm1 , _PPerm1 ): _ImageLeftActionPPerm1PPerm1 ,
120
113
}
114
+
115
+ _cxx_type_to_py_template_params = dict (
116
+ zip (
117
+ _py_template_params_to_cxx_type .values (),
118
+ _py_template_params_to_cxx_type .keys (),
119
+ )
120
+ )
121
+
122
+ _all_wrapped_cxx_types = {* _py_template_params_to_cxx_type .values ()}
0 commit comments