forked from libsemigroups/libsemigroups_pybind11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pbr.cpp
169 lines (140 loc) · 5.42 KB
/
pbr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//
// libsemigroups_pybind11
// Copyright (C) 2021 James D. Mitchell
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// C std headers....
#include <stddef.h> // for size_t
#include <stdint.h> // for int32_t, uint32_t
// C++ stl headers....
#include <initializer_list> // for initializer_list
#include <vector> // for vector
// libsemigroups....
#include <libsemigroups/pbr.hpp> // for PBR, PBR::vector_type, operator*
// pybind11....
#include <pybind11/operators.h> // for self, operator*, operator<, oper...
#include <pybind11/pybind11.h> // for class_, init, module
#include <pybind11/stl.h>
// libsemigroups_pybind11....
#include "main.hpp" // for init_pbr
namespace py = pybind11;
namespace libsemigroups {
template <typename T>
using vector_type = typename PBR::vector_type<T>;
void init_pbr(py::module &m) {
py::class_<PBR>(m, "PBR")
.def(py::init<PBR const &>(),
py::arg("that"),
R"pbdoc(
Copy constructor.
:param that: the ``PBR`` to copy.
:type that: PBR
)pbdoc")
.def("identity",
py::overload_cast<>(&PBR::identity, py::const_),
R"pbdoc(
Returns the identity ``PBR`` with degree :py:meth:`degree`.
:Parameters: None.
:Returns: A ``PBR``.
)pbdoc")
.def_static("make_identity",
py::overload_cast<size_t>(&PBR::identity),
py::arg("n"),
R"pbdoc(
Returns the identity ``PBR`` with specified degree.
:Parameters: **n** (int) - the degree.
:Returns: A ``PBR``.
)pbdoc")
.def_static("make",
&PBR::make<vector_type<int32_t>, vector_type<int32_t>>,
py::arg("left"),
py::arg("right"),
R"pbdoc(
Construct and validate.
:Parameters: - **left** (List[List[int]]) - the 1st argument to forward to the constructor.
- **right** (List[List[int]]) - the 2nd argument to forward to the constructor.
:Returns: A PBR constructed from left and right, and validated.
)pbdoc")
.def_static("make",
&PBR::make<vector_type<uint32_t>>,
py::arg("adj"),
R"pbdoc(
Construct and validate.
:Parameters: - **adj** (List[List[int]]) - the list of adjacencies.
:Returns: A new ``PBR``.
)pbdoc")
.def(
"__getitem__",
[](const PBR &a, size_t b) { return a[b]; },
py::arg("i"),
py::is_operator(),
R"pbdoc(
Returns the nodes adjacent to the given node.
:param i: an integer
:type i: int
:return: A ``int``.
)pbdoc")
.def(pybind11::self == pybind11::self,
py::arg("that"),
R"pbdoc(
Equality comparison.
Returns ``True`` if ``self`` equals ``that`` by comparing their
image values.
:param that: the ``PBR`` for comparison.
:type that: PBR
:returns: A ``bool``.
)pbdoc")
.def(pybind11::self < pybind11::self,
py::arg("that"),
R"pbdoc(
Less than comparison.
Returns ``True`` if ``self`` is less than ``that``.
:param that: the ``PBR`` for comparison.
:type that: PBR
:returns: A ``bool``.
)pbdoc")
.def(py::self * py::self,
py::arg("that"),
R"pbdoc(
Right multiply ``self`` by ``that``.
:param that: the ``PBR`` to multiply with.
:type that: PBR
:returns: A ``PBR``.
)pbdoc")
.def("degree",
&PBR::degree,
R"pbdoc(
Returns the degree of a PBR.
:Parameters: None.
:return: An ``int``.
)pbdoc")
.def("product_inplace",
&PBR::product_inplace,
py::arg("x"),
py::arg("y"),
py::arg("thread_id"),
R"pbdoc(
Multiply two ``PBR`` objects and store the product in ``self``.
:param x: a ``PBR``.
:type x: PBR
:param y: a ``PBR``.
:type y: PBR
:param thread_id: the index of the calling thread (defaults to ``0``).
:type thread_id: int
:return: (None)
)pbdoc")
.def("__hash__", &PBR::hash_value);
}
} // namespace libsemigroups