q1ss.binalg.binmat
Binary matrices.
MatBitIdx
- MatBitIdx
Type alias for the union of index types which result in a single bit being selected when passed to
binmat.__getitem__.
MatSubmatIdx
- MatSubmatIdx = slice | list[int] | tuple[slice, slice | list[int]] | tuple[slice | list[int], slice]
Type alias for the union of index types which result in a sub-matrix being selected when passed to
binmat.__getitem__.
MatSubvecIdx
- MatSubvecIdx = int | tuple[int, slice | list[int]] | tuple[slice | list[int], int] | tuple[list[int], list[int]]
Type alias for the union of index types which result in a sub-vector being selected when passed to
binmat.__getitem__.
binmat
- final class binmat(data, *, readonly=False, copy=False)[source]
Bases:
bintensorA mutable binary matrix.
- final class Cols(mat)[source]
Bases:
objectView of a binary matrix as a sequence of columns.
- __add__(vec)[source]
Returns the matrix obtained by adding the given vector to all columns of the matrix.
- __getitem__(idx)[source]
Selects a column vector in a matrix, or creates a new matrix by slicing/selecting columns.
- exception NotInvertibleError[source]
Bases:
ZeroDivisionErrorSubclass of
ZeroDivisionErroruse when attempting to invert a matrix which is not invertible.
- final class Rows(mat)[source]
Bases:
objectView of a binary matrix as a sequence of rows.
- __add__(vec)[source]
Returns the matrix obtained by adding the given vector to all rows of the matrix.
- __getitem__(idx)[source]
Selects a row vector in a matrix, or creates a new matrix by slicing/selecting rows.
- __getitem__(idx)[source]
If the index is an integer, returns the corresponding row of the matrix. If the index is a slice or a list/array of integers, returns the binary matrix containing the selected rows.
- Parameters:
idx (
MatBitIdx|MatSubvecIdx|MatSubmatIdx)- Return type:
- __imatmul__(other)[source]
Performs inplace binary matrix-matrix multiplication.
- Raises:
ShapeError – if the intermediate dimensions don’t match.
- Parameters:
other (
binmat)- Return type:
- __matmul__(other)[source]
Performs binary matrix-vector or matrix-matrix multiplication, depending on the type of
other.- Raises:
ShapeError – if the intermediate dimensions don’t match.
- Parameters:
- Return type:
- static __new__(cls, data, *, readonly=False, copy=False)[source]
Creates a new matrix 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.
- static block(blocks, *, readonly=False)[source]
Creates a block matrix from given submatrices (or vectors).
- static block_diag(blocks, *, readonly=False)[source]
Creates a block-diagonal matrix from given submatrices (or vectors).
- property cols
Returns a view of the matrix as a sequence of column vectors.
- Return type:
- copy(*, readonly=False)[source]
Returns a copy of this tensor. If
readonly=True, the resulting copy is readonly.
- property ext_rcef
Returns the reduced column echelon form (RCEF)
rof this matrix, computed modulo 2, together with the matrixmsuch thatm@self == r.If the matrix is invertible,
ris the identity andmis its inverse.
- property ext_rref
Returns the reduced row echelon form (RREF)
rof this matrix, computed modulo 2, together with the matrixmsuch thatm@self == r.If the matrix is invertible,
ris the identity andmis its inverse.
- static hstack(matrices, *, readonly=False)[source]
Stacks the given matrices (or column vectors) horizontally.
- property inverse
The left inverse of this binary matrix, or
Noneif the matrix is not invertible modulo 2.- Return type:
- static num_rcef_params(n, m, pivots)[source]
The number of parameters for a RCEF matrix with given data. See
rcef_matrix.
- static num_rref_params(n, m, pivots)[source]
The number of parameters for a RREF matrix with given data. See
rref_matrix.
- static random_inv(n, *, rng=None, max_attempts=None, readonly=False)[source]
Returns a random invertible matrix with given shape. This is done by rejection sampling, and a
max_attemptscan be set to limit the number of sampling attempts.
- static random_rcef(n, m, rank=None, *, rng=None, readonly=False)[source]
Returns a random RCEF matrix with given shape. The rank of the matrix can be optionally specified (by default, the sampled RCEF matrix is full rank, i.e.
rank=min(n,m)).Warning
The current sampling method does not result in a uniform distribution in the Grasmannian \(\mathbf{Gr}(r,n)\), where \(r\) is the
rankand \(n\) the number of rows. This will change in future releases.
- static random_rref(n, m, rank=None, *, rng=None, readonly=False)[source]
Returns a random RREF matrix with given shape. The rank of the matrix can be optionally specified (by default, the sampled RREF matrix is full rank, i.e.
rank=min(n,m)).Warning
The current sampling method does not result in a uniform distribution in the Grasmannian \(\mathbf{Gr}(r,m)\), where \(r\) is the
rankand \(m\) the number of cols. This will change in future releases.
- property rcef
Returns the reduced column echelon form (RCEF) of this matrix, computed modulo 2.
- Return type:
- static rcef_matrix(n, m, pivot_rows, params=None, *, readonly=False)[source]
Returns a
n-by-mmatrix in RCEF with the given pivot rows. The available degrees of freedom are filled with the givenparamsvector entries, or set to zero ifparamsis not given.- Raises:
ValueError – if the pivot rows are not in range, not strictly ascending, or not the same number.
ValueError – if
paramsis given and it is not a 1D array with the number of parameters specified bynum_rcef_params.
- Parameters:
- Return type:
- property rows
Returns a view of the matrix as a sequence of row vectors.
- Return type:
- property rref
Returns the reduced row echelon form (RREF) of this matrix, computed modulo 2.
- Return type:
- static rref_matrix(n, m, pivot_cols, params=None, *, readonly=False)[source]
Returns a
n-by-mmatrix in RCEF with the given pivot rows. The available degrees of freedom are filled with the givenparamsvector entries, or set to zero ifparamsis not given.- Raises:
ValueError – if the pivot rows are not in range, not strictly ascending, or not the same number.
ValueError – if
paramsis given and it is not a 1D array with the number of parameters specified bynum_rref_params.
- Parameters:
- Return type:
- static trunc_eye(n, m, *, readonly=False)[source]
The truncated identity matrix with the given shape
- static validate_rcef_args(n, m, pivots, params=None)[source]
Validates the arguments for a RCEF matrix with given data. See
rcef_matrix. Returns the number of parameters expected (the length ofparams, if given).
- static validate_rref_args(n, m, pivots, params=None)[source]
Validates the arguments for a RREF matrix with given data. See
rref_matrix. Returns the number of parameters expected (the length ofparams, if given).