forked from libsemigroups/libsemigroups_pybind11
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhpcombi.cpp
More file actions
2421 lines (1816 loc) · 70.4 KB
/
hpcombi.cpp
File metadata and controls
2421 lines (1816 loc) · 70.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// libsemigroups_pybind11
// Copyright (C) 2025 James D. Mitchell
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// libsemigroups headers
#include <libsemigroups/hpcombi.hpp>
#ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED
// pybind11....
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
// libsemigroups_pybind11....
#include "main.hpp" // for init_hpcombi
namespace py = pybind11;
namespace HPCombi {
namespace {
using LibsemigroupsException = ::libsemigroups::LibsemigroupsException;
std::string repr(Vect16 const& self, std::string_view prefix) {
auto result = std::to_string(self);
result[0] = '[';
result.back() = ']';
return fmt::format("{}({})", prefix, result);
}
////////////////////////////////////////////////////////////////////////
// Vect16
////////////////////////////////////////////////////////////////////////
void init_hpcombi_vect16(py::module& m) {
py::class_<Vect16> thing(m,
"hpcombi_Vect16",
R"pbdoc(
Vector of ``16`` bytes, with some SIMD optimized methods, superclass of
:any:`hpcombi.Transf16`. Entries in :any:`Vect16` must be integers in the range :math:`[0, 256)`.
This class belongs to the ``hpcombi`` subpackage of ``libsemigroups_pybind11``.
The functionality described on this page is only available if
:any:`LIBSEMIGROUPS_HPCOMBI_ENABLED` is ``True``.
)pbdoc");
////////////////////////////////////////////////////////////////////////
// Special methods
////////////////////////////////////////////////////////////////////////
thing.def("__repr__",
[](Vect16 const& thing) { return repr(thing, "Vect16"); });
thing.def(
"__getitem__",
[](Vect16& self, size_t i) {
if (i > 15) {
throw std::out_of_range(fmt::format(
"index out of range, expected value in [0, 16), found {}",
i));
}
return self[i];
},
py::arg("i"),
py::is_operator());
thing.def(
"__setitem__",
[](Vect16& x, size_t i, size_t val) {
if (i > 15) {
throw std::out_of_range(fmt::format(
"index out of range, expected value in [0, 16), found {}",
i));
}
x[i] = val;
},
py::is_operator());
thing.def("__len__", [](Vect16 const&) { return Vect16::size(); });
thing.def("__copy__", [](Vect16 const& v) { return Vect16(v); });
thing.def("__hash__",
[](Vect16 const& v) { return std::hash<Vect16>{}(v); });
////////////////////////////////////////////////////////////////////////
// Operators
////////////////////////////////////////////////////////////////////////
thing.def(py::self == py::self);
thing.def(py::self != py::self);
thing.def(py::self < py::self);
// NOTE: size isn't bound, use "len" instead
////////////////////////////////////////////////////////////////////////
// Constructors
////////////////////////////////////////////////////////////////////////
thing.def(py::init<>(), R"pbdoc(
Default constructor.
Constructs a :any:`Vect16` object with its entries uninitialized. This means there
is no guarantee about the values in the constructed object.
)pbdoc");
thing.def(py::init([](std::vector<uint8_t> img) {
if (img.size() < 16) {
img.resize(16, 0);
} else if (img.size() > 16) {
LIBSEMIGROUPS_EXCEPTION(
"expected a list of at most 16 values, found {}",
img.size());
}
return Vect16({img[0],
img[1],
img[2],
img[3],
img[4],
img[5],
img[6],
img[7],
img[8],
img[9],
img[10],
img[11],
img[12],
img[13],
img[14],
img[15]});
}),
R"pbdoc(
:sig=(self: Vect16, img: list[int]) -> None:
Construct a :any:`Vect16` from a list of its entries.
This function constructs a :any:`Vect16` from the list *img* of its entries.
If the length of *img* is less than ``16``, then the constructed :any:`Vect16`
is padded with ``0`` values at the end.
:param img: The list of images.
:type img: list[int]
:raises LibsemigroupsError: if any value in *img* exceeds ``255``.
:raises LibsemigroupsError: if the length of *img* exceeds ``16``.
:raises TypeError: if any value in *img* is larger than ``255``.
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([1, 2, 3, 4, 255])
Vect16([ 1, 2, 3, 4,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
)pbdoc");
////////////////////////////////////////////////////////////////////////
// Other methods
////////////////////////////////////////////////////////////////////////
// NOTE: the following doesn't compile, so skipping
// thing.def("as_array",
// &Vect16::as_array,
// R"pbdoc()pbdoc");
thing.def(
"copy",
[](Vect16 const& v) { return Vect16(v); },
R"pbdoc(
:sig=(self: Vect16) -> Vect16:
Copy a :any:`Vect16`.
:returns: A copy of the argument.
:rtype: Vect16
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> x = Vect16([1, 2, 3, 4, 255])
>>> x.copy() is not x
True
>>> x.copy() == x
True
)pbdoc");
thing.def("first_diff",
&Vect16::first_diff,
py::arg("other"),
py::arg("bound") = 16,
R"pbdoc(
:sig=(self: Vect16, other: Vect16, bound: int = 16) -> int:
Returns the position of the first diff.
This function returns the first diff in *self* and *other* among the first
*bound* entries. That is, the minimum ``i`` such that ``self[i] != other[i]``
where ``i`` is in the range from ``0`` to ``bound - 1``. If *self* and *other*
agree up to position ``bound - 1``, then ``16`` is returned.
:param other: The vector for comparison.
:type other: Vect16
:param bound: The bound (defaults to ``16``).
:type bound: int
:returns: The position of the first difference or ``16``.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([1, 2, 3, 4, 255]).first_diff(Vect16([1, 2, 3, 4, 245]))
4
)pbdoc");
thing.def("last_diff",
&Vect16::last_diff,
py::arg("other"),
py::arg("bound") = 16,
R"pbdoc(
:sig=(self: Vect16, other: Vect16, bound: int = 16) -> int:
Returns the position of the last diff.
This function returns the last diff in *self* and *other* among the first
*bound* entries. That is, the maximum ``i`` such that ``self[i] != other[i]``
where ``i`` is in the range from ``0`` to ``bound - 1``. If *self* and *other*
agree up to position ``bound - 1``, then ``16`` is returned.
:param other: The vector for comparison.
:type other: Vect16
:param bound: The bound (defaults to ``16``).
:type bound: int
:returns: The position of the last difference or ``16``.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([1, 2, 3, 4, 255]).last_diff(Vect16([1, 2, 3, 4, 245]))
4
)pbdoc");
thing.def("first_zero",
&Vect16::first_zero,
py::arg("bound") = 16,
R"pbdoc(
:sig=(self: Vect16, bound: int = 16) -> int:
Returns the position of the first zero.
This function returns the first zero in *self* among the first *bound* entries.
That is, the minimum ``i`` such that ``self[i] == 0`` where ``i`` is in the
range from ``0`` to ``bound - 1``. If *self* contains no zeros, then ``16`` is
returned.
:param bound: The bound (defaults to ``16``).
:type bound: int
:returns: The position of the first zero or ``16``.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([1, 2, 3, 4, 255]).first_zero()
5
>>> Vect16().first_zero()
0
>>> Vect16([1, 2, 3, 4, 255]).first_zero(3)
16
)pbdoc");
thing.def("last_zero",
&Vect16::last_zero,
py::arg("bound") = 16,
R"pbdoc(
:sig=(self: Vect16, bound: int = 16) -> int:
Returns the position of the last zero.
This function returns the last zero in *self* among the last *bound* entries.
That is, the maximum ``i`` such that ``self[i] == 0`` where ``i`` is in the
range from ``0`` to ``bound - 1``. If *self* contains no zeros, then ``16`` is
returned.
:param bound: The bound (defaults to ``16``).
:type bound: int
:returns: The position of the last zero or ``16``.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([1, 2, 3, 4, 255]).last_zero()
15
>>> Vect16([1, 2, 3, 4, 255]).first_zero(3)
16
>>> Vect16().last_zero()
15
)pbdoc");
thing.def("first_non_zero",
&Vect16::first_non_zero,
py::arg("bound") = 16,
R"pbdoc(
:sig=(self: Vect16, bound: int = 16) -> int:
Returns the position of the first non-zero item.
This function returns the first non-zero item in *self* among the first *bound* entries.
That is, the minimum ``i`` such that ``self[i] != 0`` where ``i`` is in the
range from ``0`` to ``bound - 1``. If *self* contains no non-zero items, then ``16`` is
returned.
:param bound: The bound (defaults to ``16``).
:type bound: int
:returns: The position of the first zero or ``16``.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([1, 2, 3, 4, 255]).first_non_zero()
0
>>> Vect16().first_non_zero()
16
)pbdoc");
thing.def("last_non_zero",
&Vect16::last_non_zero,
py::arg("bound") = 16,
R"pbdoc(
:sig=(self: Vect16, bound: int = 16) -> int:
Returns the position of the first non-zero item.
This function returns the first non-zero item in *self* among the first *bound* entries.
That is, the minimum ``i`` such that ``self[i] != 0`` where ``i`` is in the
range from ``0`` to ``bound - 1``. If *self* contains no non-zero items, then ``16`` is
returned.
:param bound: The bound (defaults to ``16``).
:type bound: int
:returns: The position of the first zero or ``16``.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([1, 2, 3, 4, 255]).last_non_zero()
4
>>> Vect16([1, 2, 3, 4, 255]).last_non_zero(3)
2
>>> Vect16().last_non_zero()
16
)pbdoc");
// NOTE: This seems unnecessary, see the test file, we can
// already do list(x) and [x for x in v] etc, so no need for
// this.
// thing.def(
// "iterator",
// [](Vect16 const& self) {
// return py::make_iterator(self.cbegin(),
// self.cend());
// },
// R"pbdoc(
// )pbdoc");
thing.def("less_partial",
&Vect16::less_partial,
py::arg("other"),
py::arg("bound") = 16,
R"pbdoc(
:sig=(self: Vect16, other: Vect16, bound: int = 16) -> int:
Returns the difference of the first diff.
This function returns the first non-zero difference (if any) between in
``self[i]`` and ``other[i]`` among the first *bound* entries or ``0``.
:param other: The vector for comparison.
:type other: Vect16
:param bound: The bound (defaults to ``16``).
:type bound: int
:returns: The difference or ``0``.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> v = Vect16([0, 1, 2, 3])
>>> u = Vect16([0, 1, 2, 10])
>>> v.less_partial(u, 3)
0
>>> v.less_partial(u, 4)
-7
>>> u.less_partial(v, 4)
7
>>> u.less_partial(v, 16)
7
>>> v.less_partial(u, 16)
-7
)pbdoc");
// NOTE: the following function is named badly, and I'm not
// completely sure what it does when the values in "other" are >
// 15, so omitting for now.
// thing.def("permuted",
// &Vect16::permuted,
// py::arg("other"),
// R"pbdoc(
// )pbdoc");
thing.def("sum",
&Vect16::sum,
R"pbdoc(
:sig=(self: Vect16) -> int:
Returns the sum of the entries mod ``256``.
This function returns the sum of the items in *self* mod ``256``.
:returns: The sum of the items in *self* mod ``256``.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([0, 1, 2, 3]).sum()
6
>>> Vect16([0, 1, 2, 10]).sum()
13
>>> Vect16([1, 2, 3, 255]).sum()
5
)pbdoc");
thing.def("partial_sums",
&Vect16::partial_sums,
R"pbdoc(
:sig=(self: Vect16) -> Vect16:
Returns the :any:`Vect16` of partial sums of the entries mod ``256``.
This function returns the :any:`Vect16` of partial sums of the items in *self*
mod ``256``.
:returns: The partial sums of the items in *self* mod ``256``.
:rtype: Vect16
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([0, 1, 2, 3]).partial_sums()
Vect16([ 0, 1, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6])
>>> Vect16([1, 2, 3, 255]).partial_sums()
Vect16([ 1, 3, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5])
)pbdoc");
thing.def("eval16",
&Vect16::eval16,
R"pbdoc(
:sig=(self: Vect16) -> Vect16:
Counts how many times each value in :math:`[0, 16)` appears in *self*.
This function counts how many times each value in :math:`[0, 16)` appears in
*self*. In other words, this function returns a :any:`Vect16` such that the
item in position ``i`` is the number of occurrences of ``i`` in *self*.
:returns: The counts.
:rtype: Vect16
.. warning: Values in *self* larger than ``15`` are ignored.
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([5, 5, 2, 5, 1, 6,12, 4, 0, 3, 2,11,12,13,14,15]).eval16()
Vect16([ 1, 1, 2, 1, 1, 3, 1, 0, 0, 0, 0, 1, 2, 1, 1, 1])
)pbdoc");
thing.def(
"is_permutation",
[](Vect16 const& self, size_t bound) {
return self.is_permutation(bound);
},
py::arg("bound") = 16,
R"pbdoc(
:sig=(self: Vect16, bound: int = 16) -> bool:
Returns whether or not the vector defines a permutation.
This function returns ``True`` if the first *bound* entries of *self*
define a permutation; and ``False`` otherwise.
:param bound: The number of entries to check (defaults to ``16``).
:type bound: int
:returns: Whether or not *self* is a permutation of its first *bound* entries.
:rtype: bool
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> Vect16([5, 5, 2, 5, 1, 6,12, 4, 0, 3, 2,11,12,13,14,15]).is_permutation()
False
>>> Vect16([1, 0, 2, 3, 4, 4]).is_permutation()
False
>>> Vect16([1, 0, 2, 3, 4] + list(range(5, 16))).is_permutation()
True
)pbdoc");
} // init_hpcombi_vect16
////////////////////////////////////////////////////////////////////////
// PTransf16
////////////////////////////////////////////////////////////////////////
void init_hpcombi_ptransf16(py::module& m) {
py::class_<PTransf16, Vect16> thing(m,
"hpcombi_PTransf16",
R"pbdoc(
Class representing partial transformations.
SIMD accelerated class :any:`PTransf16` representing partial transformations on
up to ``16`` points. Partial means it might not be defined everywhere.
Undefined images are encoded as ``255``.
This class belongs to the ``hpcombi`` subpackage of ``libsemigroups_pybind11``.
The functionality described on this page is only available if
:any:`LIBSEMIGROUPS_HPCOMBI_ENABLED` is ``True``.
:any:`PTransf16` inherits from :any:`Vect16`.
)pbdoc");
////////////////////////////////////////////////////////////////////////
// Special methods
////////////////////////////////////////////////////////////////////////
thing.def("__repr__",
[](PTransf16 const& self) { return repr(self, "PTransf16"); });
thing.def(
"__mul__",
// The next line is not a typo, but is consistent with the
// other transformations in libsemigroups_pybind11, since
// function composition in HPCombi is backwards.
[](PTransf16 const& x, PTransf16 const& y) { return y * x; },
py::is_operator());
thing.def("__copy__", [](PTransf16 const& v) { return PTransf16(v); });
////////////////////////////////////////////////////////////////////////
// Constructors
////////////////////////////////////////////////////////////////////////
thing.def(py::init<>(), R"pbdoc(
:sig=(self: PTransf16) -> None:
Default constructor.
Constructs a :any:`PTransf16` object with its entries uninitialized. This means
there is no guarantee about the values in the constructed object.
)pbdoc");
thing.def(py::init([](std::vector<uint8_t> img) {
return ::libsemigroups::make<PTransf16>(std::move(img));
}),
R"pbdoc(
:sig=(self: PTransf16, img: list[int]) -> None:
Construct a :any:`PTransf16` from a list of images.
This function constructs a :any:`PTransf16` from the list *img* of its entries.
If the length of *img* is less than ``16``, then the constructed :any:`PTransf16`
is fixed points at the end.
:param img: The list of images.
:type img: list[int]
:raises LibsemigroupsError: if any value in *img* exceeds ``16`` and is not equal to ``255``.
:raises LibsemigroupsError: if the length of *img* exceeds ``16``.
:raises TypeError: if any value in *img* is larger than ``255``.
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> PTransf16([1, 255, 1, 10])
PTransf16([ 1,255, 1,10, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15])
)pbdoc");
thing.def( // Seems like the last arg does nothing
py::init([](std::vector<uint8_t> dom, std::vector<uint8_t> ran) {
return ::libsemigroups::make<PTransf16>(dom, ran, 16);
}),
R"pbdoc(
:sig=(self: PTransf16, dom: list[int], im: list[int]) -> None:
Construct from domain and image.
Constructs a partial transformation of degree *n* such that ``(dom[i])f =
im[i]`` for all ``i`` and which is undefined (``255`` represents undefined in
this context) on every other value in the range :math:`[0, n)`.
:param dom: the domain.
:type dom: list[int]
:param im: the image.
:type im: list[int]
:raises LibsemigroupsError: *dom* and *im* do not have the same size.
:raises LibsemigroupsError: any value in *dom* or *im* is greater than *15*.
:raises LibsemigroupsError: there are repeated entries in *dom*.
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> PTransf16([1, 2], [3, 4])
PTransf16([255, 3, 4,255,255,255,255,255,255,255,255,255,255,255,255,255])
)pbdoc");
////////////////////////////////////////////////////////////////////////
// Static methods
////////////////////////////////////////////////////////////////////////
thing.def_static("one",
&PTransf16::one,
R"pbdoc(
:sig=one() -> PTransf16:
Returns the identity partial transformation.
This function returns the identity :any:`PTransf16` which fixes every value in
:math:`[0, 16)`.
:returns: The identity transformation.
:rtype: PTransf16
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> x = PTransf16([1, 0, 1])
>>> x * x.one() == PTransf16.one() * x == x
True
)pbdoc");
////////////////////////////////////////////////////////////////////////
// Other methods
////////////////////////////////////////////////////////////////////////
thing.def(
"copy",
[](PTransf16 const& v) { return PTransf16(v); },
R"pbdoc(
:sig=(self: PTransf16) -> PTransf16:
Copy a :any:`PTransf16`.
:returns: A copy of the argument.
:rtype: PTransf16
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> x = PTransf16([1, 2, 3, 4, 255])
>>> x.copy() is not x
True
>>> x.copy() == x
True
)pbdoc");
thing.def("validate",
&PTransf16::validate,
py::arg("bound") = 16,
R"pbdoc(
:sig=(self: PTransf16, bound: int = 16) -> bool:
Check whether or not a :any:`PTransf16` is well-defined.
This function returns ``True`` if *self* is a well-defined partial
transformation (i.e. no image value is larger than ``15``) on the values
``0`` up to *bound*.
:param bound: the bound (defaults to ``16``).
:type bound: int
:returns: Whether or not *self* is valid.
:rtype: bool
.. note::
It should not be possible to create an invalid :any:`PTransf16` in
``libsemigroups_pybind11``, and this function is only included for
completeness.
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> PTransf16([1, 0, 1]).validate()
True
)pbdoc");
// NOTE: the following doesn't compile and so is omitted.
// thing.def("image_mask_cmpestrm",
// &PTransf16::image_mask_cmpestrm,
// py::arg("complement"),
// R"pbdoc(
// Returns a mask for the image of *this.
// )pbdoc");
thing.def(
"image_mask_ref",
[](PTransf16 const& self, bool complement) {
return Vect16(self.image_mask_ref(complement));
},
py::arg("complement") = false,
R"pbdoc(
:sig=(self: PTransf16, complement: bool = False) -> Vect16:
Returns a mask for the image.
This function returns a mask for the image of *self* or its complement
depending on the value of *complement*. If *complement* is ``True``, then the
returned mask has ``0`` in position ``i`` for every ``i`` in the image of
*self* and ``255`` (undefined) otherwise. If *complement* is ``False``, then
the returned mask has ``0`` in position ``i`` for every ``i`` not in the image
of *self* and ``255`` otherwise.
This is the reference implementation, use :any:`image_mask` for better performance.
:param complement: whether or not the complement is sought (defaults to ``False``).
:type complement: bool
:returns: The image mask or its complement.
:rtype: Vect16
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> PTransf16([1, 0, 1]).image_mask_ref(True)
Vect16([ 0, 0,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> PTransf16([1, 0, 1]).image_mask_ref(False)
Vect16([255,255, 0,255,255,255,255,255,255,255,255,255,255,255,255,255])
)pbdoc");
thing.def(
"image_mask",
[](PTransf16 const& self, bool complement) {
return Vect16(self.image_mask(complement));
},
py::arg("complement") = false,
R"pbdoc(
:sig=(self: PTransf16, complement: bool = False) -> Vect16:
Returns a mask for the image.
This function returns a mask for the image of *self* or its complement
depending on the value of *complement*. If *complement* is ``True``, then the
returned mask has ``0`` in position ``i`` for every ``i`` in the image of
*self* and ``255`` (undefined) otherwise. If *complement* is ``False``, then
the returned mask has ``0`` in position ``i`` for every ``i`` not in the image
of *self* and ``255`` otherwise.
:param complement: whether or not the complement is sought (defaults to ``False``).
:type complement: bool
:returns: The image mask or its complement.
:rtype: Vect16
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> PTransf16([1, 0, 1]).image_mask(True)
Vect16([ 0, 0,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> PTransf16([1, 0, 1]).image_mask(False)
Vect16([255,255, 0,255,255,255,255,255,255,255,255,255,255,255,255,255])
)pbdoc");
thing.def("image_bitset",
&PTransf16::image_bitset,
py::arg("complement") = false,
R"pbdoc(
:sig=(self: PTransf16, complement: bool = False) -> int:
Returns a bit mask (as an ``int``) for the image of *self* (or its complement).
This function returns a bitset mask for the image of *self* or its complement
depending on the value of *complement*. If *complement* is ``True``, then the
returned mask has ``1`` in bit ``i`` if and only if ``i`` is in the image of
*self*. If *complement* is ``False``, then the returned mask has ``0`` in bit
``i`` if and only if ``i`` is in the image of *self*.
:param complement: whether or not the complement is sought (defaults to ``False``).
:type complement: bool
:returns: The image bitset or its complement.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> x = PTransf16([1, 3, 1, 255, 10])
>>> x.image_bitset()
65514
>>> bin(x.image_bitset())
'0b1111111111101010'
>>> bin(x.image_bitset(True))
'0b10101'
>>> bool(x.image_bitset() & 1 << 1)
True
>>> bool(x.image_bitset() & 1 << 2)
False
)pbdoc");
thing.def(
"domain_mask",
[](PTransf16 const& self, bool complement) {
return Vect16(self.domain_mask(complement));
},
py::arg("complement") = false,
R"pbdoc(
:sig=(self: PTransf16, complement: bool = False) -> Vect16:
Returns a mask for the domain.
This function returns a mask for the domain of *self* or its complement
depending on the value of *complement*. If *complement* is ``True``, then the
returned mask has ``0`` in position ``i`` for every ``i`` in the domain of
*self* and ``255`` (undefined) otherwise. If *complement* is ``False``, then
the returned mask has ``0`` in position ``i`` for every ``i`` not in the domain
of *self* and ``255`` otherwise.
:param complement: whether or not the complement is sought (defaults to ``False``).
:type complement: bool
:returns: The domain mask or its complement.
:rtype: Vect16
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> PTransf16([1, 0, 1]).domain_mask(True)
Vect16([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
>>> PTransf16([1, 0, 1]).domain_mask(False)
Vect16([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255])
)pbdoc");
thing.def("domain_bitset",
&PTransf16::domain_bitset,
py::arg("complement") = false,
R"pbdoc(
:sig=(self: PTransf16, complement: bool = False) -> int:
Returns a bit mask (as an ``int``) for the domain of *self* (or its complement).
This function returns a bitset mask for the domain of *self* or its complement
depending on the value of *complement*. If *complement* is ``True``, then the
returned mask has ``1`` in bit ``i`` if and only if ``i`` is in the domain of
*self*. If *complement* is ``False``, then the returned mask has ``0`` in bit
``i`` if and only if ``i`` is in the domain of *self*.
:param complement: whether or not the complement is sought (defaults to ``False``).
:type complement: bool
:returns: The domain bitset or its complement.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> x = PTransf16([1, 3, 1, 255, 10])
>>> x.domain_bitset()
65527
>>> bin(x.domain_bitset())
'0b1111111111110111'
>>> bin(x.domain_bitset(True))
'0b1000'
>>> bool(x.domain_bitset() & 1 << 1)
True
>>> bool(x.domain_bitset() & 1 << 3)
False
)pbdoc");
thing.def("right_one",
// This is not a typo, everything is reversed in HPCombi
&PTransf16::left_one,
R"pbdoc(
:sig=(self: PTransf16) -> PTransf16:
Returns the right one of a partial transformation.
This function returns a newly constructed :any:`PTransf16` with the same image as
*self* and that acts as the identity on *self* by right multiplication.
:returns: A right one of *self*.
:rtype: PTransf16
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> x = PTransf16([1, 3, 1, 255, 10])
>>> x.image_bitset() == x.right_one().image_bitset()
True
>>> x * x.right_one() == x
True
)pbdoc");
thing.def("left_one",
// This is not a typo, everything is reversed in HPCombi
&PTransf16::right_one,
R"pbdoc(
:sig=(self: PTransf16) -> PTransf16:
Returns the left one of a partial transformation.
This function returns a newly constructed :any:`PTransf16` with the same image as
*self* and that acts as the identity on *self* by left multiplication.
:returns: A left one of *self*.
:rtype: PTransf16
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> x = PTransf16([1, 3, 1, 255, 10])
>>> x.domain_bitset() == x.left_one().domain_bitset()
True
>>> x.left_one() * x == x
True
)pbdoc");
thing.def("rank_ref",
&PTransf16::rank_ref,
R"pbdoc(
:sig=(self: PTransf16) -> int:
Returns the size of the image set of a partial transformation.
This function returns the size of the image set of *self*.
:returns: The size of the image set.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import PTransf16
>>> x = PTransf16([1, 3, 1, 255, 10])
>>> x.rank_ref()
13
)pbdoc");
thing.def("rank",
&PTransf16::rank,
R"pbdoc(
:sig=(self: PTransf16) -> int:
Returns the size of the image set of a partial transformation.
This function returns the size of the image set of *self*.
:returns: The size of the image set.
:rtype: int
.. doctest::
>>> from libsemigroups_pybind11.hpcombi import Vect16
>>> x = PTransf16([1, 3, 1, 255, 10])
>>> x.rank()
13
)pbdoc");
thing.def("rank_cmpestrm",
&PTransf16::rank_cmpestrm,
R"pbdoc(
:sig=(self: PTransf16) -> int:
Returns the size of the image set of a partial transformation.