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

Vect16

Vector of 16 bytes, with some SIMD optimized methods, superclass of hpcombi.Transf16.

Vect16.copy(…)

Copy a Vect16.

Vect16.eval16(…)

Counts how many times each value in \([0, 16)\) appears in self.

Vect16.first_diff(…)

Returns the position of the first diff.

Vect16.first_non_zero(…)

Returns the position of the first non-zero item.

Vect16.first_zero(…)

Returns the position of the first zero.

Vect16.is_permutation(…)

Returns whether or not the vector defines a permutation.

Vect16.last_diff(…)

Returns the position of the last diff.

Vect16.last_non_zero(…)

Returns the position of the first non-zero item.

Vect16.last_zero(…)

Returns the position of the last zero.

Vect16.less_partial(…)

Returns the difference of the first diff.

Vect16.partial_sums(…)

Returns the Vect16 of partial sums of the entries mod 256.

Vect16.sum(…)

Returns the sum of the entries mod 256.

Full API

class hpcombi.Vect16
__init__(self: Vect16, img: list[int]) None

Overloaded function.

__init__(self: hpcombi_Vect16) None

Default constructor.

Constructs a Vect16 object 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 Vect16 from a list of its entries.

This function constructs a Vect16 from the list img of its entries. If the length of img is less than 16, then the constructed Vect16 is padded with 0 values at the end.

Parameters:

img (list[int]) – The list of images.

Raises:
>>> 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:

Vect16

>>> 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 Vect16 such that the item in position i is the number of occurrences of i in self.

Returns:

The counts.

Return type:

Vect16

>>> 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 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.

Parameters:
  • other (Vect16) – The vector for comparison.

  • bound (int) – The bound (defaults to 16).

Returns:

The position of the first difference or 16.

Return type:

int

>>> 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 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.

Parameters:

bound (int) – The bound (defaults to 16).

Returns:

The position of the first zero or 16.

Return type:

int

>>> 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 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.

Parameters:

bound (int) – The bound (defaults to 16).

Returns:

The position of the first zero or 16.

Return type:

int

>>> 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 True if the first bound entries of self define a permutation; and False otherwise.

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:

bool

>>> 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 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.

Parameters:
  • other (Vect16) – The vector for comparison.

  • bound (int) – The bound (defaults to 16).

Returns:

The position of the last difference or 16.

Return type:

int

>>> 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 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.

Parameters:

bound (int) – The bound (defaults to 16).

Returns:

The position of the first zero or 16.

Return type:

int

>>> 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 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.

Parameters:

bound (int) – The bound (defaults to 16).

Returns:

The position of the last zero or 16.

Return type:

int

>>> 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] and other[i] among the first bound entries or 0.

Parameters:
  • other (Vect16) – The vector for comparison.

  • bound (int) – The bound (defaults to 16).

Returns:

The difference or 0.

Return type:

int

>>> 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 Vect16 of partial sums of the entries mod 256.

This function returns the Vect16 of partial sums of the items in self mod 256.

Returns:

The partial sums of the items in self mod 256.

Return type:

Vect16

>>> 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:

int

>>> 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