q1ss.binalg.vectorized

Implementation of binary linear algebra primitives.

BinMat

BinMat

Type alias for a NumPy matrix of 8-bit unsigned integer type, whose values must all be 0 or 1.

alias of ndarray[tuple[Any, …], dtype[uint8]]

BinTensor

BinTensor

Type alias for a NumPy tensor of 8-bit unsigned integer type, whose values must all be 0 or 1.

alias of ndarray[tuple[Any, …], dtype[uint8]]

BinVec

BinVec

Type alias for a NumPy vector of 8-bit unsigned integer type, whose values must all be 0 or 1.

alias of ndarray[tuple[Any, …], dtype[uint8]]

BinVecOrMat

BinVecOrMat

Type alias for a NumPy vector or matrix of 8-bit unsigned integer type, whose values must all be 0 or 1.

alias of ndarray[tuple[Any, …], dtype[uint8]]

IntVec

IntVec

Type alias for a NumPy vector of arbitrary integer type..

alias of ndarray[tuple[Any, …], dtype[integer[Any]]]

UInt8Vec

UInt8Vec

Type alias for a NumPy vector of 8-bit unsigned integer type.

alias of ndarray[tuple[Any, …], dtype[uint8]]

bits_from_bytes

bits_from_bytes = <function bits_from_bytes>[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 desired num_bits between len(b)-7 and len(b) (both inclusive). If a length is specified, the bits ignored at the end must all be zero.

bytes_from_bits

bytes_from_bits(bit_vec)[source]

Compresses a binary vector into a vector of bytes.

Parameters:

bit_vec (BinVec)

Return type:

UInt8Vec

get_rcef_args

get_rcef_args(rcef_data)[source]

Given the binary data for a matrix in RCEF, returns the quadruple (n, m, pivot_rows, params) of the number n of rows, the number m of columns, the list pivot_rows of pivoc columns and the free binary parameters params for the RCEF matrix.

Parameters:

rcef_data (BinMat)

Return type:

tuple[int, int, IntVec, BinVec]

get_rref_args

get_rref_args(rref_data)[source]

Given the binary data for a matrix in RREF, returns the quadruple (n, m, pivot_cols, params) of the number n of rows, the number m of columns, the list pivot_cols of pivoc columns and the free binary parameters params for the RREF matrix.

Parameters:

rref_data (BinMat)

Return type:

tuple[int, int, IntVec, BinVec]

make_rcef

make_rcef = <function make_rcef>[source]

Constructs an n-by-m matrix in RCEF form with the given pivot rows and using the given bitvector to set the free binary parameters. The pivot rows must be in strict ascending order and in range(n), and the params vector must have the number of entries given by num_rcef_params.

make_rref

make_rref = <function make_rref>[source]

Constructs an n-by-m matrix in RREF form with the given pivot cols and using the given bitvector to set the free binary parameters. The pivot cols must be in strict ascending order and in range(m), and the params vector must have the number of entries given by num_rref_params.

matmul2

matmul2(lhs, rhs)[source]

Multiplies two matrices/vectors.

Parameters:
Return type:

BinVecOrMat | Integral

matmul_l2r

matmul_l2r(matrices)[source]

Multiplies the given array of matrices, left-to-right. The sequence must be non-empty and the matrices must have compatible intermediate dimensions.

Warning

This function performs no validation of its input.

Parameters:

matrices (Sequence[BinMat])

Return type:

BinMat

matmul_l2r_partial

matmul_l2r_partial(start, matrices)[source]

Multiples the given array of matrices, left-to-right, starting from the given start matrix (or row vector). The matrices must all be square, with dimension less than or equal to the number of columns in the start matrix.

Warning

This function performs no validation of its input.

Parameters:
Return type:

BinVecOrMat

matmul_r2l

matmul_r2l(matrices)[source]

Multiplies the given array of matrices, right-to-left. The sequence must be non-empty and the matrices must have compatible intermediate dimensions.

Same result as matmul_l2r, but the sequence of matrix compositions is reversed.

Warning

This function performs no validation of its input.

Parameters:

matrices (Sequence[BinMat])

Return type:

BinMat

matmul_r2l_partial

matmul_r2l_partial(matrices, start)[source]

Multiples the given array of matrices, right-to-left, starting from the given start matrix (or col vector). The matrices must all be square, with dimension less than or equal to the number of rows in the start matrix.

Warning

This function performs no validation of its input.

Parameters:
Return type:

BinVecOrMat

num_rcef_params

num_rcef_params = <function num_rcef_params>[source]

Returns the number of free binary parameters for an n-by-m matrix in RCEF form with the given pivot rows. The pivot rows must be in strict ascending order and in range(n).

num_rref_params

num_rref_params = <function num_rref_params>[source]

Returns the number of free binary parameters for an n-by-m matrix in RREF form with the given pivot columns. The pivot columns must be in strict ascending order and in range(m).

pivot_idx

pivot_idx = <function pivot_idx>[source]

Returns the index of the first non-zero entry of the given vector. If the first n entries are all zero, returns n.

rcef

rcef = <function rcef>[source]

Given the data of a binary matrix, returns the matrix’s RCEF and rank (rcef_data, rank), computed using Gaussian elimination. If ext is set to True, the matrix is first augmented to the bottom by the identity matrix with the same number of rows.

rcef_pivot_rows

rcef_pivot_rows = <function rcef_pivot_rows>[source]

Returns the pivot rows of the given binary matrix in RCEF.

rcef_residual_vec

rcef_residual_vec = <function rcef_residual_vec>[source]

Given the binary data for a matrix in RCEF and a vector vec with the same number of rows, returns the vector obtained by subtracting from vec all those columns of the RCEF matrix which have their pivot at a row where vec takes the value 1.

rref

rref = <function rref>[source]

Given the data of a binary matrix, returns the matrix’s RREF and rank (rref_data, rank), computed using Gaussian elimination. If ext is set to True, the matrix is first augmented to the right by the identity matrix with the same number of rows.

rref_pivot_cols

rref_pivot_cols = <function rref_pivot_cols>[source]

Returns the pivot cols of the given binary matrix in RREF.

rref_residual_vec

rref_residual_vec = <function rref_residual_vec>[source]

Given the binary data for a matrix in RREF and a vector vec with the same number of cols, returns the vector obtained by subtracting from vec all those rows of the RCEF matrix which have their pivot at a col where vec takes the value 1.