Skip to content

Commit 6c636ba

Browse files
Renovate Stephen
1 parent dae5987 commit 6c636ba

File tree

9 files changed

+346
-314
lines changed

9 files changed

+346
-314
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.. Copyright (c) 2022-2025 R. Cirpons, J. D. Mitchell
2+
3+
Distributed under the terms of the GPL license version 3.
4+
5+
The full license is in the file LICENSE, distributed with this software.
6+
7+
.. currentmodule:: libsemigroups_pybind11
8+
9+
The Stephen class
10+
=================
11+
12+
.. autoclass:: Stephen
13+
:doc-only:
14+
:class-doc-from: class
15+
16+
Contents
17+
--------
18+
19+
.. autosummary::
20+
:signatures: short
21+
22+
~Stephen
23+
Stephen.accept_state
24+
Stephen.init
25+
Stephen.is_word_set
26+
Stephen.presentation
27+
Stephen.set_word
28+
Stephen.word
29+
Stephen.word_graph
30+
Stephen.initial_state
31+
32+
Full API
33+
--------
34+
35+
.. autoclass:: Stephen
36+
:class-doc-from: init
37+
:members:
38+
:exclude-members:
39+
current_state, dead, finished, kill, last_report, report, report_every,
40+
report_prefix, report_why_we_stopped, reset_last_report, reset_start_time,
41+
run, run_for, run_until, running, running_for, running_until, start_time,
42+
started, state, stopped, stopped_by_predicate, success, timed_out

docs/source/main-algorithms/stephen/stephen-helpers.rst renamed to docs/source/main-algorithms/stephen/helpers.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
55
The full license is in the file LICENSE, distributed with this software.
66
7-
This file only exists because Breathe always displays all members when
8-
documenting a namespace, and this is nicer for now.
97
10-
Helpers functions for Stephen's procedure
11-
=========================================
8+
Stephen helper functions
9+
========================
1210

1311
This page contains the documentation for various helper functions for
14-
manipulating :any:`StephenPresentationWords` objects.
12+
manipulating :any:`Stephen` objects.
1513

1614
Contents
1715
--------

docs/source/main-algorithms/stephen/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ semigroups.
1414
.. toctree::
1515
:maxdepth: 1
1616

17-
stephen
18-
stephen-helpers
17+
class
18+
helpers

docs/source/main-algorithms/stephen/stephen.rst

Lines changed: 0 additions & 37 deletions
This file was deleted.

etc/replace-strings-in-doc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
replacements = {
2121
r"_libsemigroups_pybind11.": "",
2222
r"libsemigroups_pybind11\.": "",
23-
r"StephenPresentationWords": "Stephen",
2423
}
2524

2625
html_glob = "docs/_build/html/**/*.html"

libsemigroups_pybind11/schreier_sims.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def __init__(self: Self, *args) -> None:
8989
self.add_generator(gen)
9090

9191

92+
########################################################################
93+
# Copy mem fns from sample C++ type and register types
94+
########################################################################
95+
9296
_copy_cxx_mem_fns(_SchreierSimsPerm1, SchreierSims)
9397

9498
_register_cxx_wrapped_type(_SchreierSimsPerm1, SchreierSims)

libsemigroups_pybind11/stephen.py

Lines changed: 103 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,68 +9,120 @@
99
# pylint: disable=no-name-in-module, invalid-name, unused-import, fixme
1010

1111
"""
12-
This package provides the user-facing python part of libsemigroups_pybind11 for
13-
the stephen namespace from libsemigroups.
12+
This page contains the documentation for various helper functions for
13+
manipulating :any:`Stephen` objects. All such functions
14+
are contained in the submodule ``stephen``.
1415
"""
1516

17+
from typing_extensions import Self
18+
1619
from _libsemigroups_pybind11 import (
1720
PresentationWords as _PresentationWords,
1821
InversePresentationWords as _InversePresentationWords,
1922
StephenPresentationWords as _StephenPresentationWords,
2023
StephenInversePresentationWords as _StephenInversePresentationWords,
21-
accepts,
22-
dot,
23-
is_left_factor,
24-
left_factors,
25-
number_of_left_factors,
26-
number_of_words_accepted,
27-
words_accepted,
24+
# TODO rename with stephen_ prefix
25+
accepts as _accepts,
26+
dot as _dot,
27+
is_left_factor as _is_left_factor,
28+
left_factors as _left_factors,
29+
number_of_left_factors as _number_of_left_factors,
30+
number_of_words_accepted as _number_of_words_accepted,
31+
words_accepted as _words_accepted,
32+
)
33+
34+
from libsemigroups_pybind11 import (
35+
Presentation as _Presentation,
36+
InversePresentation as _InversePresentation,
37+
)
38+
39+
from .detail.decorators import copydoc as _copydoc
40+
from .detail.cxx_wrapper import (
41+
CxxWrapper as _CxxWrapper,
42+
to_cxx as _to_cxx,
43+
copy_cxx_mem_fns as _copy_cxx_mem_fns,
44+
wrap_cxx_free_fn as _wrap_cxx_free_fn,
45+
register_cxx_wrapped_type as _register_cxx_wrapped_type,
2846
)
2947

48+
########################################################################
49+
# The Stephen python class
50+
########################################################################
51+
3052

3153
# TODO(2): Make this work with string presentations once it works
32-
# TODO(0): Change this to a proper class similar to what's done with Kambites
33-
# (once the proper classes PR is merged)
34-
def Stephen(*args): # pylint: disable=invalid-name
35-
"""Construct a Stephen instance of the type specified by its arguments.
36-
37-
Options for calling this function are:
38-
1 Stephen(presentation: PresentationWords)
39-
2 Stephen(presentation: InversePresentationWords)
40-
3 Stephen(presentation: StephenPresentationWords)
41-
4 Stephen(presentation: StephenInversePresentationWords)
42-
43-
In cases 1 and 2 a new Stephen object is constructed with the given
44-
presentation. In cases 3 and 4 the Stephen object is constructed by copying
45-
an existing Stephen object. In cases 1 and 3 a StephenPresentationWords
46-
object is returned. In cases 2 and 4 a StephenInversePresentationWords
47-
object is returned.
48-
"""
49-
50-
if len(args) != 1:
51-
raise ValueError(f"expected 1 argument, but got {len(args)}")
52-
53-
presentation_or_stephen = args[0]
54-
# Order important here due to inheritance
55-
if isinstance(
56-
presentation_or_stephen,
57-
(_InversePresentationWords, _StephenInversePresentationWords),
58-
):
59-
PresentationType = _InversePresentationWords
60-
elif isinstance(
61-
presentation_or_stephen, (_PresentationWords, _StephenPresentationWords)
62-
):
63-
PresentationType = _PresentationWords
64-
else:
65-
raise TypeError(
66-
f"expected first argument to have type in {{PresentationWords, "
67-
f"InversePresentationWords, StephenPresentationWords, "
68-
f"StephenInversePresentationWords}}, but found {type(presentation_or_stephen)}"
69-
)
54+
class Stephen(_CxxWrapper):
55+
__doc__ = _StephenPresentationWords.__doc__
7056

71-
cpp_type = {
72-
_PresentationWords: _StephenPresentationWords,
73-
_InversePresentationWords: _StephenInversePresentationWords,
57+
_py_template_params_to_cxx_type = {
58+
(_PresentationWords,): _StephenPresentationWords,
59+
(_InversePresentationWords,): _StephenInversePresentationWords,
7460
}
7561

76-
return cpp_type[PresentationType](presentation_or_stephen)
62+
_cxx_type_to_py_template_params = dict(
63+
zip(
64+
_py_template_params_to_cxx_type.values(),
65+
_py_template_params_to_cxx_type.keys(),
66+
)
67+
)
68+
69+
_all_wrapped_cxx_types = {*_py_template_params_to_cxx_type.values()}
70+
71+
@_copydoc(_StephenPresentationWords.__init__)
72+
def __init__(self: Self, *args, **kwargs) -> None:
73+
# TODO remove the doc string
74+
"""Construct a Stephen instance of the type specified by its arguments.
75+
76+
Options for calling this function are:
77+
1 Stephen(presentation: PresentationWords)
78+
2 Stephen(presentation: InversePresentationWords)
79+
3 Stephen(presentation: StephenPresentationWords)
80+
4 Stephen(presentation: StephenInversePresentationWords)
81+
82+
In cases 1 and 2 a new Stephen object is constructed with the given
83+
presentation. In cases 3 and 4 the Stephen object is constructed by copying
84+
an existing Stephen object. In cases 1 and 3 a StephenPresentationWords
85+
object is returned. In cases 2 and 4 a StephenInversePresentationWords
86+
object is returned.
87+
"""
88+
super().__init__(*args, **kwargs)
89+
if _to_cxx(self) is not None:
90+
return
91+
92+
if len(args) != 1:
93+
raise ValueError(f"expected 1 argument, but got {len(args)}")
94+
95+
if isinstance(args[0], (_Presentation, _InversePresentation)):
96+
self.py_template_params = (type(_to_cxx(args[0])),)
97+
else:
98+
raise TypeError(
99+
"expected the 1st argument to have type 'Presentation', "
100+
f" or 'InversePresentation', but found {type(args[0])}",
101+
)
102+
self.init_cxx_obj(*args)
103+
104+
def __imul__(self: Self, other: Self) -> Self:
105+
x = _to_cxx(self)
106+
x *= _to_cxx(other)
107+
return self
108+
109+
110+
########################################################################
111+
# Copy mem fns from sample C++ type and register types
112+
########################################################################
113+
114+
_copy_cxx_mem_fns(_StephenPresentationWords, Stephen)
115+
_register_cxx_wrapped_type(_StephenPresentationWords, Stephen)
116+
_register_cxx_wrapped_type(_StephenInversePresentationWords, Stephen)
117+
118+
########################################################################
119+
# Helpers
120+
########################################################################
121+
122+
accepts = _wrap_cxx_free_fn(_accepts)
123+
dot = _wrap_cxx_free_fn(_dot)
124+
is_left_factor = _wrap_cxx_free_fn(_is_left_factor)
125+
left_factors = _wrap_cxx_free_fn(_left_factors)
126+
number_of_left_factors = _wrap_cxx_free_fn(_number_of_left_factors)
127+
number_of_words_accepted = _wrap_cxx_free_fn(_number_of_words_accepted)
128+
words_accepted = _wrap_cxx_free_fn(_words_accepted)

0 commit comments

Comments
 (0)