The Vect16 class
Vector of 16 bytes, with some SIMD optimized methods, superclass of
hpcombi.Transf16. Entries in Vect16 must be integers in the range \([0, 256)\).
This class belongs to the hpcombi subpackage of libsemigroups_pybind11.
The functionality described on this page is only available if
LIBSEMIGROUPS_HPCOMBI_ENABLED is True.
Contents
Vector of |
|
|
Copy a |
Counts how many times each value in \([0, 16)\) appears in self. |
|
Returns the position of the first diff. |
|
Returns the position of the first non-zero item. |
|
Returns the position of the first zero. |
|
Returns whether or not the vector defines a permutation. |
|
Returns the position of the last diff. |
|
Returns the position of the first non-zero item. |
|
Returns the position of the last zero. |
|
Returns the difference of the first diff. |
|
Returns the |
|
|
Returns the sum of the entries mod |
Full API
- class hpcombi.Vect16
- __init__(self: Vect16, img: list[int]) None
Overloaded function.
- __init__(self: hpcombi_Vect16) None
Default constructor.
Constructs a
Vect16object with its entries uninitialized. This means there is no guarantee about the values in the constructed object.
- __init__(self: Vect16, img: list[int]) None
Construct a
Vect16from a list of its entries.This function constructs a
Vect16from the list img of its entries. If the length of img is less than16, then the constructedVect16is padded with0values at the end.- Parameters:
- Raises:
LibsemigroupsError – if any value in img exceeds
255.LibsemigroupsError – if the length of img exceeds
16.TypeError – if any value in img is larger than
255.
>>> 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])
- copy(self: Vect16) Vect16
Copy a
Vect16.- Returns:
A copy of the argument.
- Return type:
>>> from libsemigroups_pybind11.hpcombi import Vect16 >>> x = Vect16([1, 2, 3, 4, 255]) >>> x.copy() is not x True >>> x.copy() == x True
- eval16(self: Vect16) Vect16
Counts how many times each value in \([0, 16)\) appears in self.
This function counts how many times each value in \([0, 16)\) appears in self. In other words, this function returns a
Vect16such that the item in positioniis the number of occurrences ofiin self.- Returns:
The counts.
- Return type:
>>> 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])
- first_diff(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
isuch thatself[i] != other[i]whereiis in the range from0tobound - 1. If self and other agree up to positionbound - 1, then16is returned.- Parameters:
- Returns:
The position of the first difference or
16.- Return type:
>>> from libsemigroups_pybind11.hpcombi import Vect16 >>> Vect16([1, 2, 3, 4, 255]).first_diff(Vect16([1, 2, 3, 4, 245])) 4
- first_non_zero(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
isuch thatself[i] != 0whereiis in the range from0tobound - 1. If self contains no non-zero items, then16is returned.- Parameters:
bound (int) – The bound (defaults to
16).- Returns:
The position of the first zero or
16.- Return type:
>>> from libsemigroups_pybind11.hpcombi import Vect16 >>> Vect16([1, 2, 3, 4, 255]).first_non_zero() 0 >>> Vect16().first_non_zero() 16
- first_zero(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
isuch thatself[i] == 0whereiis in the range from0tobound - 1. If self contains no zeros, then16is returned.- Parameters:
bound (int) – The bound (defaults to
16).- Returns:
The position of the first zero or
16.- Return type:
>>> 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
- is_permutation(self: Vect16, bound: int = 16) bool
Returns whether or not the vector defines a permutation.
This function returns
Trueif the first bound entries of self define a permutation; andFalseotherwise.- Parameters:
bound (int) – The number of entries to check (defaults to
16).- Returns:
Whether or not self is a permutation of its first bound entries.
- Return type:
>>> 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
- last_diff(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
isuch thatself[i] != other[i]whereiis in the range from0tobound - 1. If self and other agree up to positionbound - 1, then16is returned.- Parameters:
- Returns:
The position of the last difference or
16.- Return type:
>>> from libsemigroups_pybind11.hpcombi import Vect16 >>> Vect16([1, 2, 3, 4, 255]).last_diff(Vect16([1, 2, 3, 4, 245])) 4
- last_non_zero(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
isuch thatself[i] != 0whereiis in the range from0tobound - 1. If self contains no non-zero items, then16is returned.- Parameters:
bound (int) – The bound (defaults to
16).- Returns:
The position of the first zero or
16.- Return type:
>>> 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
- last_zero(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
isuch thatself[i] == 0whereiis in the range from0tobound - 1. If self contains no zeros, then16is returned.- Parameters:
bound (int) – The bound (defaults to
16).- Returns:
The position of the last zero or
16.- Return type:
>>> 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
- less_partial(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]andother[i]among the first bound entries or0.- Parameters:
- Returns:
The difference or
0.- Return type:
>>> 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
- partial_sums(self: Vect16) Vect16
Returns the
Vect16of partial sums of the entries mod256.This function returns the
Vect16of partial sums of the items in self mod256.- Returns:
The partial sums of the items in self mod
256.- Return type:
>>> 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])
- sum(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.- Return type:
>>> 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