Skip to content

Commit 854e8fc

Browse files
stephen: cleanups
1 parent 28f5bf8 commit 854e8fc

File tree

2 files changed

+55
-71
lines changed

2 files changed

+55
-71
lines changed

libsemigroups_pybind11/stephen.py

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
InversePresentationWords as _InversePresentationWords,
2222
StephenPresentationWords as _StephenPresentationWords,
2323
StephenInversePresentationWords as _StephenInversePresentationWords,
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,
24+
stephen_accepts as _stephen_accepts,
25+
stephen_dot as _stephen_dot,
26+
stephen_is_left_factor as _stephen_is_left_factor,
27+
stephen_left_factors as _stephen_left_factors,
28+
stephen_number_of_left_factors as _stephen_number_of_left_factors,
29+
stephen_number_of_words_accepted as _stephen_number_of_words_accepted,
30+
stephen_words_accepted as _stephen_words_accepted,
3231
)
3332

3433
from .presentation import (
@@ -70,21 +69,6 @@ class Stephen(_CxxWrapper): # pylint: disable=missing-class-docstring
7069

7170
@_copydoc(_StephenPresentationWords.__init__)
7271
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-
"""
8872
super().__init__(*args, **kwargs)
8973
if _to_cxx(self) is not None:
9074
return
@@ -119,10 +103,10 @@ def __imul__(self: Self, other: Self) -> Self:
119103
# Helpers
120104
########################################################################
121105

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)
106+
accepts = _wrap_cxx_free_fn(_stephen_accepts)
107+
dot = _wrap_cxx_free_fn(_stephen_dot)
108+
is_left_factor = _wrap_cxx_free_fn(_stephen_is_left_factor)
109+
left_factors = _wrap_cxx_free_fn(_stephen_left_factors)
110+
number_of_left_factors = _wrap_cxx_free_fn(_stephen_number_of_left_factors)
111+
number_of_words_accepted = _wrap_cxx_free_fn(_stephen_number_of_words_accepted)
112+
words_accepted = _wrap_cxx_free_fn(_stephen_words_accepted)

src/stephen.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ namespace libsemigroups {
3737
void bind_stephen(py::module& m, std::string const& name) {
3838
using Stephen_ = Stephen<PresentationType>;
3939

40-
py::class_<Stephen_, Runner> stephen(m,
41-
name.c_str(),
42-
R"pbdoc(
40+
py::class_<Stephen_, Runner> thing(m,
41+
name.c_str(),
42+
R"pbdoc(
4343
Class template for constructing a word graph of left factors a word in a f.p. semigroup.
4444
4545
This page describes the class :any:`Stephen` which implements Stephen's
@@ -66,27 +66,27 @@ originates in :cite:`Stephen1987aa`.
6666
>>> stephen.accepts(s, [])
6767
False
6868
)pbdoc");
69-
stephen.def("__repr__", [](Stephen_ const& stephen) {
69+
thing.def("__repr__", [](Stephen_ const& stephen) {
7070
return to_human_readable_repr(stephen);
7171
});
72-
stephen.def("__copy__",
73-
[](Stephen_ const& self) { return Stephen_(self); });
72+
thing.def("__copy__",
73+
[](Stephen_ const& self) { return Stephen_(self); });
7474
// Not directly usable so not included
75-
// stephen.def(py::init<>(), R"pbdoc(
75+
// thing.def(py::init<>(), R"pbdoc(
7676
// This function default constructs an empty instance of :any:`Stephen`.
7777
// Use :py:meth:`~Stephen.init` and :py:meth:`~Stephen.set_word` to
7878
// specify the presentation and the word, respectively. )pbdoc");
79-
stephen.def(py::init<PresentationType const&>(),
80-
py::arg("p"),
81-
R"pbdoc(
79+
thing.def(py::init<PresentationType const&>(),
80+
py::arg("p"),
81+
R"pbdoc(
8282
:sig=(self: Stephen, p: Presentation) -> None:
8383
8484
This function constructs :any:`Stephen` from a presentation.
8585
8686
:param p: the presentation.
8787
:type p: Presentation
8888
)pbdoc");
89-
stephen.def(
89+
thing.def(
9090
"copy",
9191
[](Stephen_ const& self) { return Stephen_(self); },
9292
R"pbdoc(
@@ -97,9 +97,9 @@ This function costructs a :any:`Stephen` object by copying another :any:`Stephen
9797
:param s: the :any:`Stephen` object to copy.
9898
:type s: Stephen
9999
)pbdoc");
100-
stephen.def("accept_state",
101-
&Stephen_::accept_state,
102-
R"pbdoc(
100+
thing.def("accept_state",
101+
&Stephen_::accept_state,
102+
R"pbdoc(
103103
:sig=(self: Stephen) -> int:
104104
105105
This function gets the accept state of the word graph. Running this function
@@ -119,7 +119,7 @@ already), and then returns the accept state of the produced word graph.
119119
this function may never terminate.
120120
)pbdoc");
121121
// The next one is complicated to use/doc so omitted.
122-
// stephen.def(
122+
// thing.def(
123123
// "init",
124124
// [](Stephen_& self) -> Stephen_& { return self.init(); },
125125
// R"pbdoc(
@@ -133,7 +133,7 @@ already), and then returns the accept state of the produced word graph.
133133
// :returns: ``self``.
134134
// :rtype: Stephen
135135
// )pbdoc");
136-
stephen.def(
136+
thing.def(
137137
"init",
138138
[](Stephen_& self, PresentationType const& p) -> Stephen_& {
139139
return self.init(p);
@@ -152,9 +152,9 @@ had been newly constructed from the presentation *p*.
152152
:returns: ``self``.
153153
:rtype: Stephen
154154
)pbdoc");
155-
stephen.def("is_word_set",
156-
&Stephen_::is_word_set,
157-
R"pbdoc(
155+
thing.def("is_word_set",
156+
&Stephen_::is_word_set,
157+
R"pbdoc(
158158
:sig=(self: Stephen) -> bool:
159159
Check if the initial word is set.
160160
@@ -164,7 +164,7 @@ the last presentation change and ``False`` otherwise.
164164
:returns: A bool.
165165
:rtype: bool
166166
)pbdoc");
167-
stephen.def(
167+
thing.def(
168168
"__imul__",
169169
[](Stephen_& self, Stephen_& other) -> Stephen_& {
170170
self *= other;
@@ -196,13 +196,13 @@ scratch.
196196
:raises LibsemigroupsError:
197197
if the presentations for *self* and *other* differ.
198198
)pbdoc");
199-
stephen.def(
199+
thing.def(
200200
"__eq__",
201201
[](Stephen_& self, Stephen_& other) { return self == other; },
202202
py::arg("other"));
203-
stephen.def("presentation",
204-
&Stephen_::presentation,
205-
R"pbdoc(
203+
thing.def("presentation",
204+
&Stephen_::presentation,
205+
R"pbdoc(
206206
:sig=(self: Stephen) -> Presentation | InversePresentation:
207207
Get the input presentation.
208208
@@ -211,7 +211,7 @@ Get the input presentation.
211211
)pbdoc");
212212
// TODO(2): Change to support std::string once we have that implemented
213213
// in libsemigroups itself
214-
stephen.def(
214+
thing.def(
215215
"set_word",
216216
[](Stephen_& self, word_type const& word) -> Stephen_& {
217217
return stephen::set_word(self, word);
@@ -234,9 +234,9 @@ This function sets the word whose left factors, or equivalent words, are sought.
234234
if any of the values in *word* are out of range, i.e. they do not belong to
235235
the alphabet of :any:`Stephen.presentation`.
236236
)pbdoc");
237-
stephen.def("word",
238-
&Stephen_::word,
239-
R"pbdoc(
237+
thing.def("word",
238+
&Stephen_::word,
239+
R"pbdoc(
240240
:sig=(self: Stephen) -> List[int]:
241241
242242
Get the initial word.
@@ -251,9 +251,9 @@ Returns the word set by :py:meth:`~Stephen.set_word`.
251251
with :py:meth:`~Stephen.init` or if no word was set with
252252
:py:meth:`~Stephen.set_word`.
253253
)pbdoc");
254-
stephen.def("word_graph",
255-
&Stephen_::word_graph,
256-
R"pbdoc(
254+
thing.def("word_graph",
255+
&Stephen_::word_graph,
256+
R"pbdoc(
257257
:sig=(self: Stephen) -> WordGraph:
258258
259259
Get the word graph.
@@ -269,9 +269,9 @@ implemented in this class is not triggered by calls to this function.
269269
with :py:meth:`~Stephen.init` or if no word was set with
270270
:py:meth:`~Stephen.set_word`.
271271
)pbdoc");
272-
stephen.def_static("initial_state",
273-
&Stephen_::initial_state,
274-
R"pbdoc(
272+
thing.def_static("initial_state",
273+
&Stephen_::initial_state,
274+
R"pbdoc(
275275
:sig=(self: Stephen) -> int:
276276
277277
Get the initial state of the word graph.
@@ -281,7 +281,7 @@ Get the initial state of the word graph.
281281
)pbdoc");
282282

283283
// Helpers
284-
m.def("accepts",
284+
m.def("stephen_accepts",
285285
&stephen::accepts<PresentationType>,
286286
py::arg("s"),
287287
py::arg("w"),
@@ -321,7 +321,7 @@ word *w* is accepted if and only if :math:`uu^{-1}w` is equivalent to
321321
Termination of the Stephen algorithm is undecidable in general, and
322322
this function may never terminate.
323323
)pbdoc");
324-
m.def("dot",
324+
m.def("stephen_dot",
325325
&stephen::dot<PresentationType>,
326326
py::arg("s"),
327327
R"pbdoc(
@@ -337,7 +337,7 @@ Return a :any:`Dot` object representing the underlying word graph of the
337337
:returns: A :any:`Dot` object.
338338
:rtype: Dot
339339
)pbdoc");
340-
m.def("is_left_factor",
340+
m.def("stephen_is_left_factor",
341341
&stephen::is_left_factor<PresentationType>,
342342
py::arg("s"),
343343
py::arg("w"),
@@ -370,7 +370,7 @@ it labels a path in :any:`Stephen.word_graph` with source ``0``.
370370
Termination of the Stephen algorithm is undecidable in general, and
371371
this function may never terminate.
372372
)pbdoc");
373-
m.def("left_factors",
373+
m.def("stephen_left_factors",
374374
&stephen::left_factors<PresentationType>,
375375
py::arg("s"),
376376
R"pbdoc(
@@ -395,7 +395,7 @@ This function triggers the algorithm implemented in this class (if it hasn't bee
395395
Termination of the Stephen algorithm is undecidable in general, and
396396
this function may never terminate.
397397
)pbdoc");
398-
m.def("number_of_left_factors",
398+
m.def("stephen_number_of_left_factors",
399399
&stephen::number_of_left_factors<PresentationType>,
400400
py::arg("s"),
401401
py::arg("min") = 0,
@@ -434,7 +434,7 @@ in the range *min* to *max*.
434434
Termination of the Stephen algorithm is undecidable in general, and
435435
this function may never terminate.
436436
)pbdoc");
437-
m.def("number_of_words_accepted",
437+
m.def("stephen_number_of_words_accepted",
438438
&stephen::number_of_words_accepted<PresentationType>,
439439
py::arg("s"),
440440
py::arg("min") = 0,
@@ -483,7 +483,7 @@ equivalent to :math:`u` in the semigroup defined by
483483
Termination of the Stephen algorithm is undecidable in general, and
484484
this function may never terminate.
485485
)pbdoc");
486-
m.def("words_accepted",
486+
m.def("stephen_words_accepted",
487487
&stephen::words_accepted<PresentationType>,
488488
py::arg("s"),
489489
R"pbdoc(

0 commit comments

Comments
 (0)