From ffde3bb489be79ac58f37a68634a4462941672e5 Mon Sep 17 00:00:00 2001 From: Joseph Edwards Date: Thu, 23 Apr 2026 17:28:23 +0100 Subject: [PATCH 1/5] Forest: remove useless alias --- src/forest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/forest.cpp b/src/forest.cpp index 2de6c4932..67168a940 100644 --- a/src/forest.cpp +++ b/src/forest.cpp @@ -76,7 +76,6 @@ Constructs a forest with *n* nodes, that is initialised so that the parents, std::vector> const& labels) { - using node_type = node_type; return make(to_ints(parents), to_ints(labels)); }), From e59344044fe841d3ee07ea60b44621142b0b8896 Mon Sep 17 00:00:00 2001 From: Joseph Edwards Date: Thu, 23 Apr 2026 17:29:21 +0100 Subject: [PATCH 2/5] Misc: convert to int with const ref --- src/main.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.hpp b/src/main.hpp index 436c73af6..a098df620 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -100,7 +100,7 @@ namespace libsemigroups { int_or_unsigned_constant>; template - Int to_int(int_or_constant val) { + Int to_int(int_or_constant const& val) { if (std::holds_alternative(val)) { return std::get<0>(val); } else if (std::holds_alternative(val)) { From aa38f10a7945652cef75f54be86c9b0c7f380e11 Mon Sep 17 00:00:00 2001 From: Joseph Edwards Date: Thu, 23 Apr 2026 17:30:00 +0100 Subject: [PATCH 3/5] Use from_int function more --- src/forest.cpp | 5 +---- src/transf.cpp | 11 ++--------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/forest.cpp b/src/forest.cpp index 67168a940..17df68dba 100644 --- a/src/forest.cpp +++ b/src/forest.cpp @@ -155,10 +155,7 @@ the same state as if it had just been constructed as ``Forest(n)``. "label", [](Forest const& self, node_type i) -> int_or_unsigned_constant { - if (self.label(i) != UNDEFINED) { - return {self.label(i)}; - } - return {UNDEFINED}; + return from_int(self.label(i)); }, py::arg("i"), R"pbdoc( diff --git a/src/transf.cpp b/src/transf.cpp index 9e5126e03..cd51e5a0e 100644 --- a/src/transf.cpp +++ b/src/transf.cpp @@ -111,11 +111,7 @@ the image of the point ``i`` under the {0} is ``imgs[i]``. // corresponds to a std::out_of_range for things like list(a) to // work. try { - auto result = a.at(b); - if (result != UNDEFINED) { - return {result}; - } - return {UNDEFINED}; + return from_int(a.at(b)); } catch (LibsemigroupsException const& e) { throw std::out_of_range(formatted_error_message(e)); } @@ -171,10 +167,7 @@ definition, which is equal to the size of :any:`{0}.images`. auto r = rx::iterator_range(self.begin(), self.end()) | rx::transform( [](auto val) -> int_or_unsigned_constant { - if (val != UNDEFINED) { - return {val}; - } - return {UNDEFINED}; + return from_int(val); }); return py::make_iterator(rx::begin(r), rx::end(r)); }, From 843b1d8bf72ae903adc4c4c54e5aa28f08ee38a2 Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Thu, 30 Apr 2026 12:49:45 +0100 Subject: [PATCH 4/5] fixup --- src/transf.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/transf.cpp b/src/transf.cpp index cd51e5a0e..9e5126e03 100644 --- a/src/transf.cpp +++ b/src/transf.cpp @@ -111,7 +111,11 @@ the image of the point ``i`` under the {0} is ``imgs[i]``. // corresponds to a std::out_of_range for things like list(a) to // work. try { - return from_int(a.at(b)); + auto result = a.at(b); + if (result != UNDEFINED) { + return {result}; + } + return {UNDEFINED}; } catch (LibsemigroupsException const& e) { throw std::out_of_range(formatted_error_message(e)); } @@ -167,7 +171,10 @@ definition, which is equal to the size of :any:`{0}.images`. auto r = rx::iterator_range(self.begin(), self.end()) | rx::transform( [](auto val) -> int_or_unsigned_constant { - return from_int(val); + if (val != UNDEFINED) { + return {val}; + } + return {UNDEFINED}; }); return py::make_iterator(rx::begin(r), rx::end(r)); }, From 79fbf55c2f2b6d95c08b0ead0e378c69cd2d3098 Mon Sep 17 00:00:00 2001 From: Joseph Edwards Date: Thu, 30 Apr 2026 19:15:56 +0100 Subject: [PATCH 5/5] Explain why we don't use from_int --- src/transf.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/transf.cpp b/src/transf.cpp index 9e5126e03..3b7e1fe4c 100644 --- a/src/transf.cpp +++ b/src/transf.cpp @@ -112,6 +112,8 @@ the image of the point ``i`` under the {0} is ``imgs[i]``. // work. try { auto result = a.at(b); + // Don't use from_int here, because that will incorrectly convert + // things to LIMIT_MAX and POSITIVE_INFINITY. if (result != UNDEFINED) { return {result}; } @@ -170,6 +172,9 @@ definition, which is equal to the size of :any:`{0}.images`. [](PTransfSubclass& self) { auto r = rx::iterator_range(self.begin(), self.end()) | rx::transform( + // Don't use from_int here, because that will + // incorrectly convert things to LIMIT_MAX and + // POSITIVE_INFINITY. [](auto val) -> int_or_unsigned_constant { if (val != UNDEFINED) { return {val};