pub struct Matrix { /* private fields */ }Expand description
A row-major rows x cols matrix over GF(2^8).
For an encode matrix, rows = k + p (sources + parity, ISA-L’s m) and
cols = k; the top k x k block is the identity, so source shards pass
through unchanged and the bottom p rows generate parity.
Implementations§
Source§impl Matrix
impl Matrix
Sourcepub fn reed_solomon(k: usize, p: usize) -> Result<Matrix, MatrixError>
pub fn reed_solomon(k: usize, p: usize) -> Result<Matrix, MatrixError>
Vandermonde-style encode matrix for k sources and p parity rows —
ISA-L’s gf_gen_rs_matrix, refusing the configurations ISA-L’s own
documentation marks unsafe (where some decode submatrices are
singular). Outside the safe region use Matrix::cauchy.
Sourcepub fn cauchy(k: usize, p: usize) -> Result<Matrix, MatrixError>
pub fn cauchy(k: usize, p: usize) -> Result<Matrix, MatrixError>
Cauchy encode matrix for k sources and p parity rows — ISA-L’s
gf_gen_cauchy1_matrix. Every square submatrix is invertible, so any
(k, p) within the field limit is a valid configuration; this is the
recommended general-purpose construction.
Sourcepub fn from_bytes(
rows: usize,
cols: usize,
data: Vec<u8>,
) -> Result<Matrix, MatrixError>
pub fn from_bytes( rows: usize, cols: usize, data: Vec<u8>, ) -> Result<Matrix, MatrixError>
Build a matrix from raw row-major bytes. data.len() must equal
rows * cols, and both dimensions must be in 1..=256 (the GF(2^8)
shard-index limit; the field-based constructors are stricter because
their constructions need ≤ 255 distinct nonzero elements).
Sourcepub fn get(&self, row: usize, col: usize) -> Option<u8>
pub fn get(&self, row: usize, col: usize) -> Option<u8>
The coefficient at (row, col), or None out of bounds.
Sourcepub fn parity_bytes(&self) -> &[u8] ⓘ
pub fn parity_bytes(&self) -> &[u8] ⓘ
The bottom p rows — the parity-generating block, in exactly the
layout tables::init_tables expects.
Sourcepub fn select_rows(&self, indices: &[usize]) -> Result<Matrix, MatrixError>
pub fn select_rows(&self, indices: &[usize]) -> Result<Matrix, MatrixError>
Select indices.len() rows (in order) into a new matrix — the step
that builds a decode matrix from the surviving shards’ rows. Indices
must be in range; duplicates are allowed here and will simply produce
a singular matrix at inversion.
Sourcepub fn invert(&self) -> Result<Matrix, MatrixError>
pub fn invert(&self) -> Result<Matrix, MatrixError>
Invert a square matrix — ISA-L’s gf_invert_matrix (Gauss-Jordan with
row-swap pivoting), except non-destructive and with singularity as a
typed error. Non-square input is a dimension error.
Sourcepub fn multiply(&self, rhs: &Matrix) -> Result<Matrix, MatrixError>
pub fn multiply(&self, rhs: &Matrix) -> Result<Matrix, MatrixError>
Matrix product self * rhs (used by tests and the recovery path).
Dimension mismatch is an error, never a panic.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
True if this is the identity matrix.