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
5 changes: 5 additions & 0 deletions src/libsemigroups_pybind11/transf.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ def __ge__(self: Self, other) -> bool:
return other < self or self == other

def __mul__(self: Self, other: Self):
if self.degree() != other.degree():
raise ValueError(
"the arguments (transformations) must have equal degree, "
f"but found {self.degree()} and {other.degree()}"
)
result = one(self)
result.product_inplace(self, other)
return result
Expand Down
2 changes: 1 addition & 1 deletion src/transf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ fewer points requiring less space per point.
m.def("transf_inverse",
py::overload_cast<Perm_ const&>(&inverse<N, Scalar>));
} // bind_perm
} // namespace
} // namespace

void init_transf(py::module& m) {
// Transformations
Expand Down
9 changes: 9 additions & 0 deletions tests/test_transf.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,12 @@ def test_transf_return_policy():
assert x.copy() is not x
assert x.images() is not x.images()
assert x.increase_degree_by(2) is x


def test_transf_mult_diff_degrees():
for T in (Transf, PPerm, Perm):
x, y = T([0]), T([0, 1])
with pytest.raises(ValueError):
assert x * y == x
with pytest.raises(ValueError):
assert y * x == y