Skip to main content

sparse_matrix_power

Function sparse_matrix_power 

Source
pub fn sparse_matrix_power(
    row_offsets: &[usize],
    col_indices: &[usize],
    values: &[f64],
    rows: usize,
    cols: usize,
    power: usize,
    config: &MatrixPowerConfig,
) -> Result<MatrixPowerResult, SparseError>
Expand description

Compute A^power for a sparse CSR matrix using binary exponentiation.

Binary exponentiation decomposes the exponent into powers of two so that A^8 = ((A^2)^2)^2 requires only 3 multiplications instead of 7.

§Arguments

  • row_offsets – CSR row pointer array (length rows + 1).
  • col_indices – CSR column indices (length nnz).
  • values – CSR values (length nnz).
  • rows, cols – Matrix dimensions (must be square for power > 1).
  • power – The exponent k.
  • configMatrixPowerConfig controlling nnz limits and structure reuse.

§Errors

Returns SparseError::DimensionMismatch if the matrix is not square (when power > 1), SparseError::InvalidFormat if CSR arrays are inconsistent, or SparseError::InvalidArgument if nnz exceeds max_nnz.