Skip to content

Commit 417786f

Browse files
fixup support Vect16
1 parent f8b44fb commit 417786f

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

src/hpcombi.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
//
1818

19-
// TODO change Transf16 to pad by identity
20-
2119
// libsemigroups headers
2220
#include <libsemigroups/hpcombi.hpp>
2321

@@ -1265,7 +1263,7 @@ is padded with ``0`` values at the end.
12651263
12661264
>>> from libsemigroups_pybind11.hpcombi import Transf16
12671265
>>> Transf16([1, 3, 1, 10])
1268-
Transf16([ 1, 3, 1,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
1266+
Transf16([ 1, 3, 1,10,10,10,10,10,10,10,10,10,10,10,10,10])
12691267
)pbdoc");
12701268

12711269
thing.def(py::init<uint64_t>(), R"pbdoc(
@@ -2369,7 +2367,7 @@ This function returns a newly constructed :any:`PPerm16` with the same image as
23692367
True
23702368
)pbdoc");
23712369
} // init_hpcombi_pperm16
2372-
} // namespace
2370+
} // namespace
23732371
} // namespace HPCombi
23742372

23752373
namespace libsemigroups {

src/konieczny.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ not already known.
740740
int
741741
)pbdoc");
742742
} // bind_konieczny
743-
} // namespace
743+
} // namespace
744744

745745
void init_konieczny(py::module& m) {
746746
bind_konieczny<BMat8>(m, "BMat8");
@@ -753,10 +753,7 @@ not already known.
753753
bind_konieczny<PPerm<0, uint32_t>>(m, "PPerm4");
754754

755755
#ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED
756-
// TODO impl in libsemigroups
757-
// bind_konieczny<HPCombi::PTransf16>(m, "HPCombiPTransf16");
758-
// TODO impl in libsemigroups
759-
// bind_konieczny<HPCombi::Perm16>(m, "HPCombiPerm16");
756+
bind_konieczny<HPCombi::PTransf16>(m, "HPCombiPTransf16");
760757
bind_konieczny<HPCombi::Transf16>(m, "HPCombiTransf16");
761758
bind_konieczny<HPCombi::PPerm16>(m, "HPCombiPPerm16");
762759
#endif

tests/test_hpcombi.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def test_hpcombi_vect16_hash():
2727
d = {Vect16([0, 10]): 0}
2828
assert d[Vect16([0, 10])] == 0
2929

30+
def test_hpcombi_vect16_copy():
31+
x = Vect16([1, 2, 0])
32+
assert copy(x) is not x
33+
assert x.copy() is not x
34+
assert x.copy() == copy(x)
35+
assert isinstance(x.copy(), Vect16)
36+
3037
def test_hpcombi_vect16_construct_from_list():
3138
x = Vect16([0, 10])
3239
assert x[0] == 0
@@ -131,10 +138,17 @@ def test_hpcombi_vect16_is_permutation():
131138
# PTransf16
132139
########################################################################
133140

134-
def test_hpcombi_ptransf_hash():
141+
def test_hpcombi_ptransf16_hash():
135142
d = {PTransf16([0, 10]): 0}
136143
assert d[PTransf16([0, 10])] == 0
137144

145+
def test_hpcombi_ptransf16_copy():
146+
x = PTransf16([1, 2, 0])
147+
assert copy(x) is not x
148+
assert x.copy() is not x
149+
assert x.copy() == copy(x)
150+
assert isinstance(x.copy(), PTransf16)
151+
138152
def test_hpcombi_ptransf16_construct_from_list():
139153
x = PTransf16([0, 10])
140154
assert x[0] == 0
@@ -185,15 +199,17 @@ def test_hpcombi_ptransf16_one():
185199
assert PTransf16.one() == PTransf16(list(range(16)))
186200
x = PTransf16([1, 0, 1])
187201
assert x.one() == PTransf16.one()
202+
assert isinstance(PTransf16.one(), PTransf16)
188203

189204
def test_hpcombi_ptransf16_len():
190205
assert len(PTransf16()) == 16
191206

192207
def test_hpcombi_ptransf16_validate():
193208
assert PTransf16.one().validate()
194209
assert PTransf16.one().validate(3)
195-
# FIXME the following should return true, i.e. PTransf16 should
196-
# always return True unless there's a value > 16 and != 255
210+
# TODO update the following line if
211+
# https://github.com/libsemigroups/HPCombi/issues/64
212+
# is resolved.
197213
assert not PTransf16([0, 1, 255]).validate(3)
198214

199215
def test_hpcombi_ptransf16_image_mask():
@@ -299,16 +315,23 @@ def test_hpcombi_ptransf_nb_fix_points():
299315
# Transf16
300316
########################################################################
301317

302-
def test_hpcombi_transf_hash():
318+
def test_hpcombi_transf16_hash():
303319
d = {Transf16([0, 10]): 0}
304320
assert d[Transf16([0, 10])] == 0
305321

322+
def test_hpcombi_transf16_copy():
323+
x = Transf16([1, 2, 0])
324+
assert copy(x) is not x
325+
assert x.copy() is not x
326+
assert x.copy() == copy(x)
327+
assert isinstance(x.copy(), Transf16)
328+
306329
def test_hpcombi_transf16_construct_from_list():
307330
x = Transf16([0, 10])
308331
assert x[0] == 0
309332
assert x[1] == 10
310333
for i in range(2, 16):
311-
assert x[i] == 0
334+
assert x[i] == 10
312335
with pytest.raises(LibsemigroupsError):
313336
x = Transf16([0] * 17)
314337
with pytest.raises(LibsemigroupsError):
@@ -319,11 +342,11 @@ def test_hpcombi_transf16_construct_from_list():
319342
def test_hpcombi_transf16_set_item():
320343
x = Transf16()
321344
x[1] = 10
322-
assert x == Transf16([0, 10])
345+
assert x == Transf16([0, 10] + [0] * 14)
323346

324347
def test_hpcombi_transf16_to_from_ints():
325348
x = Transf16([0, 15])
326-
assert int(x) == 3840
349+
assert int(x) == 18446744073709551600
327350
assert Transf16(int(x)) == x
328351

329352
def test_hpcombi_transf16_lt():
@@ -341,6 +364,7 @@ def test_hpcombi_transf16_mul():
341364

342365
def test_hpcombi_transf16_one():
343366
assert Transf16.one() == Transf16(list(range(16)))
367+
assert isinstance(Transf16.one(), Transf16)
344368

345369
########################################################################
346370
# Perm16
@@ -351,7 +375,6 @@ def test_hpcombi_perm_hash():
351375
assert d[Perm16([1, 0])] == 0
352376

353377
def test_hpcombi_perm16_copy():
354-
# TODO replicate this test for the other types
355378
x = Perm16([1, 2, 0])
356379
assert copy(x) is not x
357380
assert x.copy() is not x
@@ -362,7 +385,7 @@ def test_hpcombi_perm16_one():
362385
assert Perm16.one() == Perm16(list(range(16)))
363386
x = Perm16([1, 2, 0])
364387
assert x.one() == Perm16.one()
365-
assert isinstance(x.one(), Perm16) # TODO add this to the other test cases
388+
assert isinstance(x.one(), Perm16)
366389

367390
def test_hpcombi_perm16_inverse():
368391
x = Perm16([1, 2, 0])
@@ -483,12 +506,11 @@ def test_hpcombi_perm16_unrankSJT(): # pylint: disable=invalid-name
483506
# PPerm16
484507
########################################################################
485508

486-
def test_hpcombi_pperm_hash():
509+
def test_hpcombi_pperm16_hash():
487510
d = {PPerm16([1, 0]): 0}
488511
assert d[PPerm16([1, 0])] == 0
489512

490513
def test_hpcombi_pperm16_copy():
491-
# TODO replicate this test for the other types
492514
x = PPerm16([1, 2, 0])
493515
assert copy(x) is not x
494516
assert x.copy() is not x
@@ -538,10 +560,9 @@ def test_hpcombi_pperm16_left_one():
538560
assert x.left_one() * x == x
539561

540562
def test_hpcombi_pperm16_inverse_ref():
541-
x = Perm16([1, 2, 0])
563+
x = PPerm16([1, 2, 0])
542564
assert x * x.inverse_ref() * x == x
543565
assert x.inverse_ref() * x * x.inverse_ref() == x.inverse_ref()
544566
assert x * x.inverse_ref() == x.left_one()
545567
assert x.inverse_ref() * x == x.right_one()
546-
assert x.inverse_ref() * x * x.inverse_ref() == x.inverse_ref()
547568
assert x**-1 == x.inverse_ref()

0 commit comments

Comments
 (0)