q1ss.binalg.binvec
Binary vectors.
Bit
binvec
- final class binvec(data, *, readonly=False, copy=False)[source]
Bases:
bintensorA mutable vector over the field \(\mathbb{Z}_2\).
- __getitem__(idx)[source]
If the index is an integer, returns the corresponding entry of the vec. If the index is a slice or a list/array of integers, returns the vec containing the selected entries.
- Parameters:
idx (
typing.Union[int,slice,list[int]]) –- Return type:
- __imatmul__(other)[source]
Inplace vector-matrix multiplication over the field \(\mathbb{Z}_2\)
- Raises:
ShapeError – if the intermediate dimensions don’t match.
- Parameters:
other (
binmat) –- Return type:
- __matmul__(other)[source]
Vector-vector inner product or vector-matrix multiplication over the field \(\mathbb{Z}_2\).
- Raises:
ShapeError – if the intermediate dimensions don’t match.
- Parameters:
other (
typing.Union[binvec,binmat]) –- Return type:
- static __new__(cls, data, *, readonly=False, copy=False)[source]
Creates a new vector from binary data.
If
readonly=True, the resulting tensor and its data are readonly. Ifcopy=True, a fresh copy of the given data is used.
- __setitem__(idx, value)[source]
Sets a single value, or a slice/selection of values.
- Parameters:
idx (
typing.Union[int,slice,list[int]]) –value (
typing.Union[int,binvec]) –
- Return type:
- static el(idx, dim, *, readonly=False)[source]
Returns the canonical basis vector with given index in given dimension.
- static from_bool(bits, *, readonly=False)[source]
Constructs a binary vector from an interable of boolean values.
- static from_bytes(b, num_bits=None, *, readonly=False)[source]
Converts bytes to a binary vector containing the corresponding bits. The binary vector has length
8*len(b)by default, containing all bits, but length can be truncated by specifying a desirednum_bitsbetweenlen(b)-7andlen(b)(both inclusive). If a length is specified, the bits ignored at the end must all be zero.
- static from_str(bits, *, readonly=False)[source]
Constructs a binary vector from a string with chars
'0'and'1'.
- static iter_all(dim, *, readonly=False)[source]
Iterates through all binary vectors with given dimension.
- static iter_std_basis(dim, *, readonly=False)[source]
Iterates through all standard basis binary vectors with given dimension.
- static validate_bitstr(bits)[source]
Validate a binary string. Raises
TypeErrororValueErrorfor invalid strings, returnsTrueotherwise.