Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/forest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Constructs a forest with *n* nodes, that is initialised so that the
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));
}),
Expand Down Expand Up @@ -156,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<node_type> {
if (self.label(i) != UNDEFINED) {
return {self.label(i)};
}
return {UNDEFINED};
return from_int(self.label(i));
},
py::arg("i"),
R"pbdoc(
Expand Down
2 changes: 1 addition & 1 deletion src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace libsemigroups {
int_or_unsigned_constant<Int>>;

template <typename Int>
Int to_int(int_or_constant<Int> val) {
Int to_int(int_or_constant<Int> const& val) {
if (std::holds_alternative<Int>(val)) {
return std::get<0>(val);
} else if (std::holds_alternative<Undefined>(val)) {
Expand Down
11 changes: 2 additions & 9 deletions src/transf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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<Scalar> {
if (val != UNDEFINED) {
return {val};
}
return {UNDEFINED};
return from_int(val);
});
Comment on lines 169 to 171
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to remove this lambda all together, with something like

static_cast<int_or_constant<Scalar> (*)(Scalar)>(from_int)

but this felt a bit unwieldy to me, so I opted to keep the lambda.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you can't just replace the lambda with from_int ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not; transform is unable to infer the type of from_int. I think this is because from_int is an overloaded function template. Something like this seems to work:

auto r = rx::iterator_range(self.begin(), self.end())
         | rx::transform<int_or_constant<Scalar> (*)(Scalar)>(
             &from_int);

Should we go with that instead?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, the lambda is better. Sorry for the noise.

return py::make_iterator(rx::begin(r), rx::end(r));
},
Expand Down
Loading