Skip to content

Commit 02ba3dd

Browse files
transf: don't allow mult. when degrees differ
1 parent 77662b8 commit 02ba3dd

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/libsemigroups_pybind11/transf.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def __ge__(self: Self, other) -> bool:
123123
return other < self or self == other
124124

125125
def __mul__(self: Self, other: Self):
126+
if self.degree() != other.degree():
127+
raise ValueError(
128+
"the arguments (transformations) must have equal degree, "
129+
f"but found {self.degree()} and {other.degree()}"
130+
)
126131
result = one(self)
127132
result.product_inplace(self, other)
128133
return result

src/transf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ fewer points requiring less space per point.
733733
m.def("transf_inverse",
734734
py::overload_cast<Perm_ const&>(&inverse<N, Scalar>));
735735
} // bind_perm
736-
} // namespace
736+
} // namespace
737737

738738
void init_transf(py::module& m) {
739739
// Transformations

tests/test_transf.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,12 @@ def test_transf_return_policy():
300300
assert x.copy() is not x
301301
assert x.images() is not x.images()
302302
assert x.increase_degree_by(2) is x
303+
304+
305+
def test_transf_mult_diff_degrees():
306+
for T in (Transf, PPerm, Perm):
307+
x, y = T([0]), T([0, 1])
308+
with pytest.raises(ValueError):
309+
assert x * y == x
310+
with pytest.raises(ValueError):
311+
assert y * x == y

0 commit comments

Comments
 (0)