Skip to content

Commit 8b952f0

Browse files
Use proper class for Kambites
1 parent f936431 commit 8b952f0

File tree

11 files changed

+150
-104
lines changed

11 files changed

+150
-104
lines changed

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def no_doc_run(self):
220220
),
221221
],
222222
"Congruence": [("detail::CongruenceCommon", "Congruence")],
223+
"Kambites": [("detail::CongruenceCommon", "Kambites")],
223224
}
224225

225226
# This is what sphinx considers to be a signature

docs/source/main-algorithms/froidure-pin/to-froidure-pin.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ This function throws a :any:`LibsemigroupsError` if ``cong.kind`` is not
7979

8080
.. _kambites-to-froidure-pin:
8181

82-
Converting a :any:`KambitesMultiStringView` to a :any:`FroidurePinPBR`
82+
Converting a :any:`Kambites` to a :any:`FroidurePinPBR`
8383
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8484

85-
To construct a :any:`FroidurePinPBR` from a :any:`KambitesMultiStringView`,
85+
To construct a :any:`FroidurePinPBR` from a :any:`Kambites`,
8686
specify the following values for *args*:
8787

88-
* **k** (:any:`KambitesMultiStringView`) -- the
89-
:any:`KambitesMultiStringView` object being converted.
88+
* **k** (:any:`Kambites`) -- the
89+
:any:`Kambites` object being converted.
9090

9191
Additionally, specify the following for *Return*:
9292

@@ -96,7 +96,7 @@ The :any:`FroidurePinPBR` object returned is isomorphic to the quotient
9696
semigroup or monoid represented by *k*.
9797

9898
This function throws a :any:`LibsemigroupsError` if the
99-
:any:`KambitesMultiStringView.small_overlap_class` of *k* is not at least
99+
:any:`Kambites.small_overlap_class` of *k* is not at least
100100
:math:`4`.
101101

102102
.. warning::

docs/source/main-algorithms/kambites/class.rst

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
55
The full license is in the file LICENSE, distributed with this software.
66
7-
.. currentmodule:: _libsemigroups_pybind11
7+
.. currentmodule:: libsemigroups_pybind11
88

9-
The KambitesMultiStringView class
10-
=================================
9+
The Kambites class
10+
==================
1111

12-
.. autoclass:: KambitesMultiStringView
12+
.. autoclass:: Kambites
1313
:doc-only:
1414
:class-doc-from: class
1515

@@ -19,21 +19,27 @@ Contents
1919
.. autosummary::
2020
:signatures: short
2121

22-
~KambitesMultiStringView
23-
KambitesMultiStringView.contains
24-
KambitesMultiStringView.currently_contains
25-
KambitesMultiStringView.generating_pairs
26-
KambitesMultiStringView.init
27-
KambitesMultiStringView.number_of_classes
28-
KambitesMultiStringView.presentation
29-
KambitesMultiStringView.reduce
30-
KambitesMultiStringView.reduce_no_run
31-
KambitesMultiStringView.small_overlap_class
32-
KambitesMultiStringView.ukkonen
22+
~Kambites
23+
Kambites.contains
24+
Kambites.currently_contains
25+
Kambites.generating_pairs
26+
Kambites.init
27+
Kambites.number_of_classes
28+
Kambites.presentation
29+
Kambites.reduce
30+
Kambites.reduce_no_run
31+
Kambites.small_overlap_class
32+
Kambites.ukkonen
3333

3434
Full API
3535
--------
3636

37-
.. autoclass:: KambitesMultiStringView
37+
.. autoclass:: Kambites
3838
:members:
3939
:class-doc-from: init
40+
:exclude-members:
41+
current_state, dead, finished, internal_generating_pairs, kill,
42+
last_report, report, report_every, report_prefix, report_why_we_stopped,
43+
reset_last_report, reset_start_time, run, run_for, run_until, running,
44+
running_for, running_until, start_time, started, state, stopped,
45+
stopped_by_predicate, success, timed_out,

docs/source/main-algorithms/kambites/helpers.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
55
The full license is in the file LICENSE, distributed with this software.
66
7-
KambitesMultiStringView helper functions
8-
========================================
7+
.. currentmodule:: libsemigroups_pybind11.kambites
8+
9+
Kambites helper functions
10+
=========================
911

1012
This page contains the documentation for various helper functions for
11-
manipulating :any:`KambitesMultiStringView` objects.
13+
manipulating :any:`Kambites` objects.
1214

1315
Contents
1416
--------
1517

16-
.. currentmodule:: libsemigroups_pybind11.kambites
17-
1818
.. autosummary::
1919
:signatures: short
2020

@@ -30,4 +30,3 @@ Full API
3030
.. automodule:: libsemigroups_pybind11.kambites
3131
:members:
3232
:exclude-members: Kambites
33-
:imported-members:

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
55
The full license is in the file LICENSE, distributed with this software.
66
7-
.. currentmodule:: _libsemigroups_pybind11
8-
9-
KambitesMultiStringView
10-
=======================
7+
Kambites
8+
========
119

1210
On this page there are links to the documentation for the algorithms in
1311
``libsemigroups_pybind11`` for small overlap monoids by Mark Kambites and the

docs/source/main-algorithms/todd-coxeter/class/common.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Common methods
1111

1212
This page contains documentation of the methods of :any:`ToddCoxeterWord` that
1313
are implemented in all of the classes :any:`Congruence`,
14-
:any:`KambitesMultiStringView`, :any:`KnuthBendixStringRewriteTrie`, and
14+
:any:`Kambites`, :any:`KnuthBendixStringRewriteTrie`, and
1515
:any:`ToddCoxeterWord`.
1616

1717
.. automethod:: ToddCoxeterWord.add_generating_pair

etc/replace-strings-in-doc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
def dict_sub(replacements, string):
88
"""replacements has the form {"regex1": "replacement", "regex2": "replacement2", ...}"""
9-
global_expression = re.compile("|".join("(" + x + ")" for x in replacements))
9+
global_expression = re.compile(
10+
"|".join("(" + x + ")" for x in replacements)
11+
)
1012
replacements_by_group = {}
1113
group = 1
1214
for expr, replacement in replacements.items():
@@ -39,7 +41,6 @@ def dive(path):
3941
"FroidurePinPBR": "FroidurePin",
4042
"ImageLeftActionPPerm1PPerm1": "ImageLeftAction",
4143
"ImageRightActionPPerm1PPerm1": "ImageRightAction",
42-
"KambitesMultiStringView": "Kambites",
4344
"KnuthBendixImplRewriteTrie": "KnuthBendix",
4445
"KnuthBendixStringRewriteTrie": "KnuthBendix",
4546
"PPerm1": "PPerm",

libsemigroups_pybind11/congruence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def get(self: Self, t: type):
9393
9494
:param t:
9595
The type of object being sought (must be
96-
:any:`KambitesMultiStringView`,
96+
:any:`Kambites`,
9797
:any:`KnuthBendixStringRewriteTrie`, or :any:`ToddCoxeterWord`).
9898
:type t: type
9999
@@ -121,7 +121,7 @@ def has(self: Self, t: type) -> bool:
121121
*t*, and ``False`` if not.
122122
123123
:param t:
124-
The type of object being sought (must be :any:`KambitesMultiStringView`,
124+
The type of object being sought (must be :any:`Kambites`,
125125
:any:`KnuthBendixStringRewriteTrie`, or :any:`ToddCoxeterWord`).
126126
:type t: type
127127

libsemigroups_pybind11/kambites.py

Lines changed: 71 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,99 @@
66
#
77
# The full license is in the file LICENSE, distributed with this software.
88

9-
# pylint: disable=unused-import, no-name-in-module, invalid-name
9+
# pylint: disable=unused-import, no-name-in-module,
1010
# pylint: disable=protected-access, duplicate-code
11+
# pylint: disable=missing-class-docstring, invalid-name
12+
# pylint: disable=missing-function-docstring
1113

1214
"""
1315
This package provides the user-facing python part of libsemigroups_pybind11 for
1416
the libsemigroups::kambites namespace from libsemigroups.
1517
"""
1618

1719
from typing import List
20+
from typing_extensions import Self
1821

1922
from _libsemigroups_pybind11 import (
2023
KambitesMultiStringView as _KambitesMultiStringView,
2124
KambitesWord as _KambitesWord,
2225
PresentationStrings as _PresentationStrings,
2326
PresentationWords as _PresentationWords,
2427
congruence_kind as _congruence_kind,
25-
kambites_non_trivial_classes as non_trivial_classes,
26-
kambites_normal_forms as normal_forms,
27-
kambites_partition as partition,
28+
kambites_non_trivial_classes as _kambites_non_trivial_classes,
29+
kambites_normal_forms as _kambites_normal_forms,
30+
kambites_partition as _kambites_partition,
2831
)
2932

3033
from .detail.decorators import (
3134
may_return_positive_infinity as _may_return_positive_infinity,
35+
copydoc as _copydoc,
3236
)
3337

34-
from .detail import cong_intf
35-
36-
37-
def Kambites(*args, **kwargs): # pylint: disable=invalid-name
38-
"""
39-
Function pretending to be a class, just dispatches to the corresponding
40-
constructor of the appropriate type based on the arguments.
41-
"""
42-
cong_intf.raise_if_bad_args(*args, **kwargs)
43-
if len(args) == 0:
44-
Word = kwargs["Word"]
45-
else:
46-
assert len(args) == 2
47-
if isinstance(args[1], _PresentationStrings):
48-
Word = str
49-
elif isinstance(args[1], _PresentationWords):
50-
Word = List[int]
38+
from .detail import cong_intf as _cong_intf
39+
from .detail.cxx_wrapper import (
40+
CxxWrapper as _CxxWrapper,
41+
copy_cxx_mem_fns as _copy_cxx_mem_fns,
42+
to_cxx as _to_cxx,
43+
)
44+
45+
46+
class Kambites(_CxxWrapper):
47+
__doc__ = _KambitesWord.__doc__
48+
49+
_py_to_cxx_type_dict = {
50+
List[int]: _KambitesWord,
51+
str: _KambitesMultiStringView,
52+
}
53+
54+
@_copydoc(_KambitesWord.__init__)
55+
def __init__( # pylint: disable=super-init-not-called
56+
self: Self, *args, **kwargs
57+
) -> None:
58+
_cong_intf.raise_if_bad_args(*args, **kwargs)
59+
if len(args) == 0:
60+
Word = kwargs["Word"]
5161
else:
52-
raise TypeError(
53-
f"expected the 2nd argument to be Presentation, but found {type(args[1])}"
54-
)
62+
assert len(args) == 2
63+
if isinstance(args[1], _PresentationStrings):
64+
Word = str
65+
elif isinstance(args[1], _PresentationWords):
66+
Word = List[int]
67+
else:
68+
raise TypeError(
69+
f"expected the 2nd argument to be Presentation, but found {type(args[1])}"
70+
)
71+
72+
self._cxx_obj = self._py_to_cxx_type_dict[Word](*args)
73+
74+
@_copydoc(_KambitesWord._number_of_classes)
75+
@_may_return_positive_infinity
76+
def number_of_classes(self: Self) -> int:
77+
return _to_cxx(self)._number_of_classes()
78+
79+
@_copydoc(_KambitesWord._small_overlap_class)
80+
@_may_return_positive_infinity
81+
def small_overlap_class(self: Self) -> int:
82+
return _to_cxx(self)._small_overlap_class()
83+
84+
85+
_copy_cxx_mem_fns(_KambitesWord, Kambites)
86+
87+
88+
@_copydoc(_kambites_partition)
89+
def partition(
90+
k: Kambites, words: List[List[int]] | List[str]
91+
) -> List[List[List[int]]] | List[List[str]]:
92+
return _kambites_partition(_to_cxx(k), words)
93+
5594

56-
cpp_type = {List[int]: _KambitesWord, str: _KambitesMultiStringView}
57-
return cpp_type[Word](*args)
95+
@_copydoc(_kambites_non_trivial_classes)
96+
def non_trivial_classes(
97+
k: Kambites, words: List[List[int]] | List[str]
98+
) -> List[List[List[int]]] | List[List[str]]:
99+
return _kambites_non_trivial_classes(_to_cxx(k), words)
58100

59101

60-
for _Kambites in [_KambitesWord, _KambitesMultiStringView]:
61-
_Kambites.number_of_classes = _may_return_positive_infinity(
62-
_Kambites._number_of_classes # pylint: disable=protected-access
63-
)
64-
_Kambites.small_overlap_class = _may_return_positive_infinity(
65-
_Kambites._small_overlap_class # pylint: disable=protected-access
66-
)
102+
@_copydoc(_kambites_normal_forms)
103+
def normal_forms(k: Kambites) -> List[List[int]] | List[str]:
104+
return _kambites_normal_forms(_to_cxx(k))

src/cong.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace libsemigroups {
3838
py::class_<Congruence<Word>, detail::CongruenceCommon> thing(m,
3939
name,
4040
R"pbdoc(
41-
Class for running :any:`KambitesMultiStringView`,
41+
Class for running :any:`Kambites`,
4242
:any:`KnuthBendixStringRewriteTrie`, and :any:`ToddCoxeterWord` in parallel.
4343
4444
On this page we describe the functionality relating to the class
@@ -47,7 +47,7 @@ congruence over a semigroup or monoid by running every applicable algorithm
4747
from ``libsemigroups`` (and some variants of the same algorithm) in parallel.
4848
This class is provided for convenience, at present it is not very customisable,
4949
and lacks some of the fine grained control offered by the classes implementing
50-
individual algorithms, such as :any:`KambitesMultiStringView`,
50+
individual algorithms, such as :any:`Kambites`,
5151
:any:`KnuthBendixStringRewriteTrie`, and :any:`ToddCoxeterWord`.
5252
5353
.. seealso:: :any:`Runner`, :any:`congruence_kind`, and :any:`tril`.
@@ -137,7 +137,7 @@ Get the current maximum number of threads.
137137
:sig=(self: Congruence) -> int:
138138
139139
Get the number of runners. This function returns the number of distinct
140-
instances of :any:`KambitesMultiStringView`,
140+
instances of :any:`Kambites`,
141141
:any:`KnuthBendixStringRewriteTrie`, and/or :any:`ToddCoxeterWord` that are
142142
contained in a :any:`Congruence` object.
143143

0 commit comments

Comments
 (0)