Skip to main content

Matrix

Struct Matrix 

Source
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

Source

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.

Source

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.

Source

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

Source

pub fn rows(&self) -> usize

Number of rows (k + p for an encode matrix — ISA-L’s m).

Source

pub fn cols(&self) -> usize

Number of columns (k, the source count, for an encode matrix).

Source

pub fn get(&self, row: usize, col: usize) -> Option<u8>

The coefficient at (row, col), or None out of bounds.

Source

pub fn as_bytes(&self) -> &[u8]

The raw row-major coefficient bytes.

Source

pub fn parity_bytes(&self) -> &[u8]

The bottom p rows — the parity-generating block, in exactly the layout tables::init_tables expects.

Source

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.

Source

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.

Source

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.

Source

pub fn is_identity(&self) -> bool

True if this is the identity matrix.

Trait Implementations§

Source§

impl Clone for Matrix

Source§

fn clone(&self) -> Matrix

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Matrix

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for Matrix

Source§

impl PartialEq for Matrix

Source§

fn eq(&self, other: &Matrix) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Matrix

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.