Notebooks · lib/sparse
Sparse matrices in compressed sparse row form
A matrix with few nonzeros per row is stored as three arrays, the compressed
sparse row form that NPB CG, SciPy's csr_matrix and most iterative solvers
use. vals[k] is the k-th nonzero, row by row and left to right within a row,
and cols[k] is its column. rowptr[i] is where row i starts in vals, so
row i is vals[rowptr[i]], ..., vals[rowptr[i + 1] - 1], and rowptr[n] is
the number of nonzeros.
rowptr and cols are Int arrays, so an index is never a rounded double.
csr_matvec(rowptr, cols, vals, x, y):y = A x, written intoy. Each row's sum runs left to right, the order NPB CG's Fortran uses, so the result is the reference's to the bit. Rows are independent, so the loop is aparallel for: each pass writes onlyy[i], which the compiler checks.csr_from_dense(M): the CSR arrays of a dense matrix, dropping zeros.csr_to_dense(rowptr, cols, vals, ncols): the dense matrix back, the check member the tests compare against@.
Used with from sparse import csr_matvec.
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.