Skip to content
Merged
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
30 changes: 22 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,18 @@ The valid values are:
"__int__",
[](Undefined const& x) -> size_t { return static_cast<size_t>(x); })
.def("__chr__",
[](Undefined const& x) -> char { return static_cast<char>(x); });
[](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));
});

m.attr("UNDEFINED") = UNDEFINED;

#ifdef LIBSEMIGROUPS_EIGEN_ENABLED
m.attr("LIBSEMIGROUPS_EIGEN_ENABLED")
= static_cast<bool>(LIBSEMIGROUPS_EIGEN_ENABLED);
#else
m.attr("LIBSEMIGROUPS_EIGEN_ENABLED") = false;
m.attr("LIBSEMIGROUPS_EIGEN_ENABLED") = false;
#endif

#ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED
Expand Down Expand Up @@ -253,7 +256,7 @@ The valid values are:
#ifdef VERSION_INFO
m.attr("__version__") = VERSION_INFO;
#else
m.attr("__version__") = "dev";
m.attr("__version__") = "dev";
#endif

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -351,8 +354,12 @@ default.
return lhop == rhop;
},
py::is_operator())
.def("to_int", [](PositiveInfinity const& x) -> int64_t {
return static_cast<int64_t>(x);
.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));
});

m.attr("POSITIVE_INFINITY") = POSITIVE_INFINITY;
Expand Down Expand Up @@ -395,8 +402,12 @@ default.
return lhop == rhop;
},
py::is_operator())
.def("to_int", [](NegativeInfinity const& x) -> int64_t {
return static_cast<int64_t>(x);
.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));
});

m.attr("NEGATIVE_INFINITY") = NEGATIVE_INFINITY;
Expand Down Expand Up @@ -444,7 +455,10 @@ default.
[](LimitMax const& rhs, int64_t lhs) { return lhs - rhs; },
py::is_operator())
.def("to_int",
[](LimitMax const& x) -> int { return static_cast<int>(x); });
[](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));
});

m.attr("LIMIT_MAX") = LIMIT_MAX;

Expand Down
12 changes: 12 additions & 0 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def test_UNDEFINED(): # pylint: disable=invalid-name
assert not UNDEFINED > UNDEFINED
assert not UNDEFINED < UNDEFINED

d = {UNDEFINED: 0}
assert UNDEFINED in d


def test_POSITIVE_INFINITY(): # pylint: disable=invalid-name
"""
Expand Down Expand Up @@ -79,6 +82,9 @@ def test_POSITIVE_INFINITY(): # pylint: disable=invalid-name
assert POSITIVE_INFINITY > 100
assert POSITIVE_INFINITY > NEGATIVE_INFINITY

d = {POSITIVE_INFINITY: 0}
assert POSITIVE_INFINITY in d


def test_NEGATIVE_INFINITY(): # pylint: disable=invalid-name
"""
Expand Down Expand Up @@ -117,6 +123,9 @@ def test_NEGATIVE_INFINITY(): # pylint: disable=invalid-name
assert not NEGATIVE_INFINITY > 100
assert not NEGATIVE_INFINITY > POSITIVE_INFINITY

d = {NEGATIVE_INFINITY: 0}
assert NEGATIVE_INFINITY in d


def test_LIMIT_MAX(): # pylint: disable=invalid-name
"""
Expand Down Expand Up @@ -151,3 +160,6 @@ def test_LIMIT_MAX(): # pylint: disable=invalid-name
assert 100 < LIMIT_MAX
assert not 0 > LIMIT_MAX
assert not 100 > LIMIT_MAX

d = {LIMIT_MAX: 0}
assert LIMIT_MAX in d