numerics
Loading...
Searching...
No Matches
num::SparseMatrix Class Reference

Sparse matrix in Compressed Sparse Row (CSR) format. More...

#include <sparse.hpp>

Public Member Functions

 SparseMatrix (idx n_rows, idx n_cols, std::vector< real > vals, std::vector< idx > col_idx, std::vector< idx > row_ptr)
 Construct from raw CSR arrays (takes ownership)
 
idx n_rows () const
 
idx n_cols () const
 
idx nnz () const
 
real operator() (idx i, idx j) const
 Element access A(i,j); returns 0 if outside stored pattern – O(nnz/n)
 
const realvalues () const
 
const idxcol_idx () const
 
const idxrow_ptr () const
 

Static Public Member Functions

static SparseMatrix from_triplets (idx n_rows, idx n_cols, const std::vector< idx > &rows, const std::vector< idx > &cols, const std::vector< real > &vals)
 Build from coordinate (COO / triplet) lists.
 

Detailed Description

Sparse matrix in Compressed Sparse Row (CSR) format.

Non-zero values for row i are stored in vals_[row_ptr_[i] .. row_ptr_[i+1]). Corresponding column indices are in col_idx_[row_ptr_[i] .. row_ptr_[i+1]).

Definition at line 15 of file sparse.hpp.

Constructor & Destructor Documentation

◆ SparseMatrix()

num::SparseMatrix::SparseMatrix ( idx  n_rows,
idx  n_cols,
std::vector< real vals,
std::vector< idx col_idx,
std::vector< idx row_ptr 
)

Construct from raw CSR arrays (takes ownership)

Definition at line 8 of file sparse.cpp.

Member Function Documentation

◆ col_idx()

const idx * num::SparseMatrix::col_idx ( ) const
inline

Definition at line 39 of file sparse.hpp.

◆ from_triplets()

SparseMatrix num::SparseMatrix::from_triplets ( idx  n_rows,
idx  n_cols,
const std::vector< idx > &  rows,
const std::vector< idx > &  cols,
const std::vector< real > &  vals 
)
static

Build from coordinate (COO / triplet) lists.

Duplicate (row, col) entries are summed. Entries need not be sorted.

Definition at line 23 of file sparse.cpp.

References num::ipow(), n_cols(), n_rows(), nnz(), and row_ptr().

◆ n_cols()

idx num::SparseMatrix::n_cols ( ) const
inline

Definition at line 32 of file sparse.hpp.

Referenced by from_triplets().

◆ n_rows()

idx num::SparseMatrix::n_rows ( ) const
inline

Definition at line 31 of file sparse.hpp.

Referenced by from_triplets().

◆ nnz()

idx num::SparseMatrix::nnz ( ) const
inline

Definition at line 33 of file sparse.hpp.

Referenced by from_triplets().

◆ operator()()

real num::SparseMatrix::operator() ( idx  i,
idx  j 
) const

Element access A(i,j); returns 0 if outside stored pattern – O(nnz/n)

Definition at line 104 of file sparse.cpp.

References num::ipow().

◆ row_ptr()

const idx * num::SparseMatrix::row_ptr ( ) const
inline

Definition at line 40 of file sparse.hpp.

Referenced by from_triplets().

◆ values()

const real * num::SparseMatrix::values ( ) const
inline

Definition at line 38 of file sparse.hpp.


The documentation for this class was generated from the following files: