Skip to content
15 changes: 9 additions & 6 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ Returns an iterator yielding the generators.
:rtype:
Iterator[Element]
)pbdoc");
thing.def("position",
&Action_::position,
py::arg("pt"),
R"pbdoc(
:sig=(self: Action, pt: Point) -> int:
thing.def(
"position",
[](Action_& self, const_reference_point_type pt) {
return from_int(self.position(pt));
},
py::arg("pt"),
R"pbdoc(
:sig=(self: Action, pt: Point) -> int | Undefined:

Returns the position of a point in the so far discovered points.

Expand All @@ -243,7 +246,7 @@ Returns the position of a point in the so far discovered points.
:complexity: Constant.

:returns: The index of *pt* in ``self`` or :any:`UNDEFINED`.
:rtype: int
:rtype: int | Undefined
)pbdoc");
thing.def("empty",
&Action_::empty,
Expand Down
18 changes: 11 additions & 7 deletions src/aho-corasick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,16 @@ Copy a :any:`AhoCorasick` object.
thing.def("__copy__",
[](AhoCorasick const& self) { return AhoCorasick(self); });

thing.def("child",
&AhoCorasick::child,
py::arg("parent"),
py::arg("letter"),
R"pbdoc(
thing.def(
"child",
[](AhoCorasick const& self,
AhoCorasick::index_type parent,
letter_type letter) { return from_int(self.child(parent, letter)); },
py::arg("parent"),
py::arg("letter"),
R"pbdoc(
:sig=(self: AhoCorasick, parent: int, letter: int) -> int | Undefined:

Return the child of *parent* with edge-label *letter*

This function returns the index of the child of the node with index
Expand All @@ -104,14 +109,13 @@ This function returns the index of the child of the node with index
:type letter: int

:returns: the index of the child.
:rtype: int
:rtype: int | Undefined

:raises LibsemigroupsError: if ``throw_if_node_index_not_active(parent)`` throws.

:complexity: Constant.

.. seealso:: :any:`throw_if_node_index_not_active`.

)pbdoc");

thing.def("height",
Expand Down
10 changes: 1 addition & 9 deletions src/cong-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ namespace libsemigroups {
using KnuthBendixWordRewriteFromLeft
= KnuthBendix<word_type, RewriteFromLeft>;

using int_or_pos_infty = std::variant<uint64_t, PositiveInfinity>;

////////////////////////////////////////////////////////////////////////
// Implementation helpers
////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -411,13 +409,7 @@ Copy a :any:`{name}` object.
doc extra_doc) {
thing.def(
"number_of_classes",
[](Thing& self) -> std::variant<uint64_t, PositiveInfinity> {
auto result = self.number_of_classes();
if (result != POSITIVE_INFINITY) {
return {result};
}
return {POSITIVE_INFINITY};
},
[](Thing& self) { return from_int(self.number_of_classes()); },
make_doc(R"pbdoc(
:sig=(self: {name}) -> int | PositiveInfinity:
{only_document_once}
Expand Down
149 changes: 0 additions & 149 deletions src/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,6 @@ namespace libsemigroups {
return true;
},
py::is_operator())
.def(
"__eq__",
[](Undefined const& lhop, size_t rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](size_t lhop, Undefined const& rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](Undefined const& lhop, int rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](int lhop, Undefined const& rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](Undefined const& lhop, uint64_t rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](uint64_t lhop, Undefined const& rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__int__",
[](Undefined const& x) -> size_t { return static_cast<size_t>(x); })
.def("__chr__",
[](Undefined const& x) -> char { return static_cast<char>(x); })
.def("__hash__", [](Undefined const& op) -> int {
return std::hash<uint64_t>{}(static_cast<uint64_t>(op));
});
Expand Down Expand Up @@ -113,46 +72,6 @@ namespace libsemigroups {
[](PositiveInfinity const& lhop,
NegativeInfinity const& rhop) -> bool { return false; },
py::is_operator())
.def(
"__eq__",
[](int lhop, PositiveInfinity const& rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](PositiveInfinity const& lhop, int rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](int64_t lhop, PositiveInfinity const& rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](PositiveInfinity const& lhop, int64_t rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](uint64_t lhop, PositiveInfinity const& rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](PositiveInfinity const& lhop, uint64_t rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def("to_int",
[](PositiveInfinity const& x) -> int64_t {
return static_cast<int64_t>(x);
})
.def("__hash__", [](PositiveInfinity const& op) -> int {
return std::hash<uint64_t>{}(static_cast<uint64_t>(op));
});
Expand All @@ -177,34 +96,6 @@ namespace libsemigroups {
[](NegativeInfinity const& lhop,
PositiveInfinity const& rhop) -> bool { return lhop == rhop; },
py::is_operator())
.def(
"__eq__",
[](int lhop, NegativeInfinity const& rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](NegativeInfinity const& lhop, int rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](int64_t lhop, NegativeInfinity const& rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](NegativeInfinity const& lhop, int64_t rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def("to_int",
[](NegativeInfinity const& x) -> int64_t {
return static_cast<int64_t>(x);
})
.def("__hash__", [](NegativeInfinity const& op) -> int {
return std::hash<int64_t>{}(static_cast<int64_t>(op));
});
Expand All @@ -219,46 +110,6 @@ namespace libsemigroups {
.def("__repr__",
[](LimitMax const& val) -> std::string { return "LIMIT_MAX"; })
.def(pybind11::self < LimitMax())
.def(pybind11::self < int())
.def(int() < pybind11::self)
.def(
"__eq__",
[](int lhop, LimitMax const& rhop) -> bool { return lhop == rhop; },
py::is_operator())
.def(
"__eq__",
[](LimitMax const& lhop, int rhop) -> bool { return lhop == rhop; },
py::is_operator())
.def(
"__eq__",
[](int64_t lhop, LimitMax const& rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__eq__",
[](LimitMax const& lhop, int64_t rhop) -> bool {
return lhop == rhop;
},
py::is_operator())
.def(
"__sub__",
[](LimitMax const& lhs, int rhs) { return lhs - rhs; },
py::is_operator())
.def(
"__rsub__",
[](LimitMax const& rhs, int lhs) { return lhs - rhs; },
py::is_operator())
.def(
"__sub__",
[](LimitMax const& lhs, int64_t rhs) { return lhs - rhs; },
py::is_operator())
.def(
"__rsub__",
[](LimitMax const& rhs, int64_t lhs) { return lhs - rhs; },
py::is_operator())
.def("to_int",
[](LimitMax const& x) -> int { return static_cast<int>(x); })
.def("__hash__", [](LimitMax const& op) -> int {
return std::hash<uint64_t>{}(static_cast<uint64_t>(op));
});
Expand Down
60 changes: 29 additions & 31 deletions src/forest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

// libsemigroups....
#include <libsemigroups/forest.hpp> // for Forest
#include <libsemigroups/ranges.hpp> // for rx::to_vector

// pybind11....
#include <pybind11/operators.h> // for py::operator
Expand Down Expand Up @@ -69,11 +70,11 @@ Constructs a forest with *n* nodes, that is initialised so that the
)pbdoc");
thing.def(
py::init(
[](std::vector<std::variant<Forest::node_type, Undefined>> const&
parents,
std::vector<std::variant<Forest::node_type, Undefined>> const&
labels) {
return make<Forest>(to_ints(parents), to_ints(labels));
[](std::vector<int_or_unsigned_constant<node_type>> const& parents,
std::vector<int_or_unsigned_constant<node_type>> const& labels) {
using node_type = node_type;
return make<Forest>(to_ints<node_type>(parents),
to_ints<node_type>(labels));
}),
py::arg("parents"),
py::arg("labels"),
Expand Down Expand Up @@ -141,8 +142,8 @@ the same state as if it had just be constructed as ``Forest(n)``.
)pbdoc");
thing.def(
"label",
[](Forest const& self,
Forest::node_type i) -> std::variant<Forest::node_type, Undefined> {
[](Forest const& self,
node_type i) -> int_or_unsigned_constant<node_type> {
if (self.label(i) != UNDEFINED) {
return {self.label(i)};
}
Expand Down Expand Up @@ -173,15 +174,15 @@ Returns the label of the edge from a node to its parent.
thing.def(
"labels",
[](Forest const& self)
-> std::vector<std::variant<Forest::node_type, Undefined>> {
std::vector<std::variant<Forest::node_type, Undefined>> result;
for (auto node : self.labels()) {
if (node != UNDEFINED) {
result.emplace_back(node);
} else {
result.emplace_back(UNDEFINED);
}
}
-> std::vector<int_or_unsigned_constant<node_type>> {
auto result
= self.labels()
| rx::transform(
[](auto val) -> int_or_unsigned_constant<node_type> {
return {val};
})
| rx::to_vector();
from_ints<node_type>(result);
return result;
},
R"pbdoc(
Expand Down Expand Up @@ -218,12 +219,9 @@ in the forest.
thing.def(py::self == py::self, py::arg("that"));
thing.def(
"parent",
[](Forest const& self,
Forest::node_type i) -> std::variant<Forest::node_type, Undefined> {
if (self.parent(i) != UNDEFINED) {
return {self.parent(i)};
}
return {UNDEFINED};
[](Forest const& self,
node_type i) -> int_or_unsigned_constant<node_type> {
return from_int(self.parent(i));
},
py::arg("i"),
R"pbdoc(
Expand All @@ -249,15 +247,15 @@ Returns the parent of a node.
thing.def(
"parents",
[](Forest const& self)
-> std::vector<std::variant<Forest::node_type, Undefined>> {
std::vector<std::variant<Forest::node_type, Undefined>> result;
for (auto node : self.parents()) {
if (node != UNDEFINED) {
result.emplace_back(node);
} else {
result.emplace_back(UNDEFINED);
}
}
-> std::vector<int_or_unsigned_constant<node_type>> {
auto result
= self.parents()
| rx::transform(
[](auto val) -> int_or_unsigned_constant<node_type> {
return {val};
})
| rx::to_vector();
from_ints<node_type>(result);
return result;
},
R"pbdoc(
Expand Down
Loading