Skip to content

Commit ecb386f

Browse files
hpcombi: resolve #374
The return type of the product of any two hpcombi PTransf16 objects, or any derived class, was always PTransf16. This commit resolves this issue.
1 parent fe27a86 commit ecb386f

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/hpcombi.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ The functionality described on this page is only available if
569569

570570
thing.def(
571571
"__mul__",
572-
// The next line is not a type, but is consistent with the
572+
// The next line is not a typo, but is consistent with the
573573
// other transformations in libsemigroups_pybind11, since
574574
// function composition in HPCombi is backwards.
575575
[](PTransf16 const& x, PTransf16 const& y) { return y * x; },
@@ -1227,6 +1227,16 @@ The functionality described on this page is only available if
12271227

12281228
thing.def("__copy__", [](Transf16 const& v) { return Transf16(v); });
12291229

1230+
thing.def(
1231+
"__mul__",
1232+
// The next line is not a typo, but is consistent with the
1233+
// other transformations in libsemigroups_pybind11, since
1234+
// function composition in HPCombi is backwards.
1235+
// Also this method is required because the return type of the one for
1236+
// PTransf16 is always PTransf16.
1237+
[](Transf16 const& x, Transf16 const& y) { return y * x; },
1238+
py::is_operator());
1239+
12301240
////////////////////////////////////////////////////////////////////////
12311241
// Constructors
12321242
////////////////////////////////////////////////////////////////////////
@@ -1415,6 +1425,16 @@ The functionality described on this page is only available if
14151425
thing.def("__repr__",
14161426
[](Perm16 const& self) { return repr(self, "Perm16"); });
14171427

1428+
thing.def(
1429+
"__mul__",
1430+
// The next line is not a typo, but is consistent with the
1431+
// other transformations in libsemigroups_pybind11, since
1432+
// function composition in HPCombi is backwards.
1433+
// Also this method is required because the return type of the one for
1434+
// PTransf16 is always PTransf16.
1435+
[](Perm16 const& x, Perm16 const& y) { return y * x; },
1436+
py::is_operator());
1437+
14181438
////////////////////////////////////////////////////////////////////////
14191439
// Static methods
14201440
////////////////////////////////////////////////////////////////////////
@@ -2157,6 +2177,16 @@ The functionality described on this page is only available if
21572177
"'PPerm16' and 'int");
21582178
});
21592179

2180+
thing.def(
2181+
"__mul__",
2182+
// The next line is not a typo, but is consistent with the
2183+
// other transformations in libsemigroups_pybind11, since
2184+
// function composition in HPCombi is backwards.
2185+
// Also this method is required because the return type of the one for
2186+
// PTransf16 is always PTransf16.
2187+
[](PPerm16 const& x, PPerm16 const& y) { return y * x; },
2188+
py::is_operator());
2189+
21602190
////////////////////////////////////////////////////////////////////////
21612191
// Static methods
21622192
////////////////////////////////////////////////////////////////////////

tests/test_hpcombi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ def test_hpcombi_ptransf_nb_fix_points():
306306
assert PTransf16([1, 3, 2, 255, 10]).nb_fix_points() == 12
307307
assert PTransf16.one().nb_fix_points() == 16
308308

309+
def test_hpcombi_ptransf_mul_return_type():
310+
x = PTransf16([1, 3, 2, 255, 10])
311+
assert isinstance(x * x, PTransf16)
312+
309313
########################################################################
310314
# Transf16
311315
########################################################################
@@ -361,6 +365,10 @@ def test_hpcombi_transf16_one():
361365
assert Transf16.one() == Transf16(list(range(16)))
362366
assert isinstance(Transf16.one(), Transf16)
363367

368+
def test_hpcombi_transf_mul_return_type():
369+
x = Transf16([1, 0, 2])
370+
assert isinstance(x * x, Transf16)
371+
364372
########################################################################
365373
# Perm16
366374
########################################################################
@@ -497,6 +505,10 @@ def test_hpcombi_perm16_left_weak_leq_length():
497505
def test_hpcombi_perm16_unrankSJT(): # pylint: disable=invalid-name
498506
assert Perm16.unrankSJT(2) == Perm16([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 13, 14])
499507

508+
def test_hpcombi_perm16_mul_return_type():
509+
x = Perm16([1, 0, 2])
510+
assert isinstance(x * x, Perm16)
511+
500512
########################################################################
501513
# PPerm16
502514
########################################################################
@@ -561,3 +573,7 @@ def test_hpcombi_pperm16_inverse_ref():
561573
assert x * x.inverse_ref() == x.left_one()
562574
assert x.inverse_ref() * x == x.right_one()
563575
assert x**-1 == x.inverse_ref()
576+
577+
def test_hpcombi_pperm16_mul_return_type():
578+
x = PPerm16([1, 0, 2])
579+
assert isinstance(x * x, PPerm16)

0 commit comments

Comments
 (0)