Skip to main content

Module matrix_powers

Module matrix_powers 

Source
Expand description

Sparse matrix powers and polynomial evaluation.

Computes A^k via repeated SpGEMM with binary exponentiation and optional structure reuse optimization. Also provides matrix polynomial evaluation via Horner’s method: p(A) = c0*I + c1*A + c2*A^2 + ... + ck*A^k.

All operations work on CSR (Compressed Sparse Row) format stored as (row_offsets, col_indices, values) triple on the host side.

(C) 2026 COOLJAPAN OU (Team KitaSan)

Structs§

MatrixPowerConfig
Configuration for sparse matrix power computation.
MatrixPowerResult
Result of a sparse matrix power computation.

Functions§

add_csr
Add two CSR matrices with the same number of rows: C = A + B.
estimate_power_nnz
Heuristic estimate of nnz(A^k) based on average degree.
host_spgemm
Host-side sparse matrix-matrix multiplication: C = A * B.
scalar_multiply_csr
Multiply all values of a CSR matrix by a scalar, keeping the sparsity structure unchanged.
sparse_identity
Construct the CSR representation of an n x n identity matrix.
sparse_matrix_polynomial
Evaluate a polynomial p(A) = c0*I + c1*A + c2*A^2 + ... + ck*A^k using Horner’s method.
sparse_matrix_power
Compute A^power for a sparse CSR matrix using binary exponentiation.