num::spmat¶
Defined in header <linear/sparse/sparse.hpp>
class spmat;
Sparse matrix in compressed sparse row (CSR) format. Row i holds its values and column indices in positions [row_ptr[i], row_ptr[i+1]).
Members¶
| member | description |
|---|---|
spmat(idx n_rows, idx n_cols, array<real> vals, array<idx> col_idx, array<idx> row_ptr) |
Construct a matrix from CSR arrays, taking ownership of them. |
static spmat from_triplets(idx n_rows, idx n_cols, const array<idx> &rows, const array<idx> &cols, const array<real> &vals) |
Construct a matrix from (row, column, value) triplets. Duplicate entries are summed; the triplets need not be sorted. |
static spmat from_csc(idx n_rows, idx n_cols, const array<real> &vals, const array<idx> &row_indices, const array<idx> &col_ptrs) |
Construct a matrix from zero-based compressed column (CSC) arrays. Only the first col_ptrs.back() entries of the value and index arrays are read. |
idx n_rows() const |
|
idx n_cols() const |
|
idx rows() const noexcept |
|
idx cols() const noexcept |
|
idx nnz() const |
|
real operator()(idx i, idx j) const |
Return the entry \(a_{ij}\), or 0 if it is not stored. Costs \(O(\mathrm{nnz}/n)\). |
const real *values() const |
|
const idx *col_idx() const |
|
const idx *row_ptr() const |
|
template <class X = vec<real>, class Y = vec<real>> void apply(const X &x, Y &y) const |
Apply the matrix: \(y \leftarrow A x\). |