HLIBpro
2.8.1
|
Class for a sparse matrix stored in compressed row storage format.
#include <TSparseMatrix.hh>
Public Member Functions | |
TSparseMatrix (const size_t anrows, const size_t ancols) | |
construct sparse matrix of size anrows × ancols | |
TSparseMatrix (const TIndexSet arow_is, const TIndexSet acol_is) | |
construct sparse matrix of size anrows × ancols | |
TSparseMatrix (const TBlockCluster *bct=nullptr) | |
construct sparse matrix with size defined by block cluster bct | |
virtual void | set_cluster (const TBlockCluster *bct) |
set block cluster of matrix | |
virtual void | set_size (const size_t nrows, const size_t ncols) |
directly set dimension of matrix | |
void | init (const size_t nnz) |
initialise CRS data for nnz non-zero entries | |
size_t | rows () const |
return number of rows in matrix | |
size_t | cols () const |
return number of columns in matrix | |
size_t | n_non_zero () const |
return number of non-zero elements | |
virtual void | to_real () |
convert coefficients to real valued representation (if possible) | |
virtual void | to_complex () |
convert coefficients to complex valued representation | |
virtual real | entry (const idx_t i, const idx_t j) const |
return matrix coefficient a_ij (real valued) | |
virtual const complex | centry (const idx_t i, const idx_t j) const |
return matrix coefficient a_ij (complex valued) | |
virtual void | set_entry (const idx_t i, const idx_t j, const real c) |
set matrix coefficient a_ij if existent (real valued) | |
virtual void | set_entry (const idx_t i, const idx_t j, const complex c) |
set matrix coefficient a_ij if existent (complex valued) | |
virtual void | add_entry (const idx_t i, const idx_t j, const real c) |
add c to matrix coefficient a_ij if existent (real valued) | |
virtual void | add_entry (const idx_t i, const idx_t j, const complex c) |
add c to matrix coefficient a_ij if existent (complex valued) | |
virtual bool | has_entry (const idx_t i, const idx_t j) const |
return true if entry (i, j) exists | |
void | sort_entries () |
sort matrix coefficients per row with respect to column | |
idx_t | rowptr (const idx_t i) const |
return i'th row pointer (constant) | |
idx_t & | rowptr (const idx_t i) |
return i'th row pointer | |
idx_t | colind (const idx_t i) const |
return i'th column index (constant) | |
idx_t & | colind (const idx_t i) |
return i'th column index | |
real | rcoeff (const idx_t i) const |
return i'th coefficient (real valued, constant) | |
real & | rcoeff (const idx_t i) |
return i'th coefficient (real valued) | |
const complex | ccoeff (const idx_t i) const |
return i'th coefficient (complex valued, constant) | |
complex & | ccoeff (const idx_t i) |
return i'th coefficient (complex valued) | |
void | permute (const TPermutation &rowperm, const TPermutation &colperm) |
bool | test_symmetry () |
return true if matrix is symmetric (really check data) | |
size_t | avg_entries_per_row () const |
compute average number of entries per row | |
size_t | max_entries_per_row () const |
compute maximal number of entries per row | |
bool | has_diag_zero (const real eps=0.0) |
return true if matrix contains zero or elements < ε on diagonal | |
bool | is_diag_dom (const bool weak=false) |
return true if S is (weakly) diagonally dominant | |
real | diag_dom_factor () |
return factor α, such that S + α·I is diagonally dominant (this = S) | |
void | check_matrix () const |
perform some tests on the matrix (for debugging) | |
template<typename T_idx , typename T_val > | |
void | import_crs (const size_t nrows, const size_t ncols, const size_t nnonzero, const T_idx *rowptr, const T_idx *colind, const T_val *coeffs) |
import CRS data into local matrix | |
template<typename T_idx , typename T_val > | |
void | import_ccs (const size_t nrows, const size_t ncols, const size_t nnonzero, const T_idx *colptr, const T_idx *rowind, const T_val *coeffs) |
import CCS data into local matrix | |
template<typename T_idx , typename T_val > | |
void | export_ccs (std::vector< T_idx > &colptr, std::vector< T_idx > &rowind, std::vector< T_val > &coeffs, const bool use_sym) const |
virtual void | scale (const real alpha) |
compute this ≔ α·this | |
virtual void | mul_vec (const real alpha, const TVector *x, const real beta, TVector *y, const matop_t op=MATOP_NORM) const |
compute y ≔ β·y + α·op(M)·x, with M = this | |
virtual void | add (const real alpha, const TMatrix *matrix) |
compute this ≔ this + α · matrix | |
virtual void | transpose () |
transpose matrix | |
virtual void | conjugate () |
conjugate matrix coefficients | |
virtual void | cscale (const complex alpha) |
compute this ≔ α·this | |
virtual void | cmul_vec (const complex alpha, const TVector *x, const complex beta, TVector *y, const matop_t op=MATOP_NORM) const |
compute y ≔ β·y + α·op(M)·x, with M = this | |
virtual void | cadd (const complex a, const TMatrix *matrix) |
compute this ≔ this + α · matrix | |
virtual void | truncate (const TTruncAcc &) |
truncate matrix to given accuracy (NOT YET IMPLEMENTED) | |
std::unique_ptr< TSparseMatrix > | restrict (const TIndexSet &rowis, const TIndexSet &colis) const |
restrict sparse matrix to block index set rowis × colis | |
std::unique_ptr< TSparseMatrix > | restrict (const TIndexSet &rowis, const TPermutation *rowperm, const TIndexSet &colis, const TPermutation *colperm) const |
size_t | restrict_nonzeroes (const TIndexSet &rowis, const TIndexSet &colis) const |
return number of coefficients in sub block index set rowis × colis | |
size_t | restrict_nonzeroes (const TIndexSet &rowis, const TPermutation *rowperm, const TIndexSet &colis, const TPermutation *colperm) const |
return number of coefficients in sub block index set rowis × colis | |
virtual void | print (const uint ofs=0) const |
print matrix to stdout | |
virtual void | read (TByteStream &s) |
read data from stream s and copy to matrix | |
virtual void | build (TByteStream &s) |
use data from stream s to build matrix | |
virtual void | write (TByteStream &s) const |
write data to stream s | |
virtual size_t | bs_size () const |
returns size of object in bytestream | |
virtual auto | create () const -> std::unique_ptr< TMatrix > |
return matrix of same class (but no content) | |
virtual auto | copy () const -> std::unique_ptr< TMatrix > |
return copy of matrix | |
virtual auto | copy_struct () const -> std::unique_ptr< TMatrix > |
return structural copy of matrix | |
virtual void | copy_to (TMatrix *A) const |
copy matrix into matrix A | |
virtual size_t | byte_size () const |
return size in bytes used by this object | |
virtual void | check_data () const |
test data for invalid values, e.g. INF and NAN | |
virtual void | print_pattern_hist (std::ostream &os) const |
print histogram for entries per row in GNUPLOT format | |
virtual auto | copy () const -> std::unique_ptr< TMatrix > |
return copy of matrix | |
virtual auto | copy (const TTruncAcc &acc, const bool coarsen=false) const -> std::unique_ptr< TMatrix > |
return copy of matrix with accuracy acc and optional coarsening | |
virtual void | copy_to (TMatrix *A) const |
copy matrix into matrix A | |
virtual void | copy_to (TMatrix *A, const TTruncAcc &acc, const bool coarsen=false) const |
copy matrix into matrix A with accuracy acc and optional coarsening | |
Public Member Functions inherited from TMatrix | |
TMatrix (const value_type_t avalue_type=real_valued) | |
construct zero sized matrix | |
TMatrix (const TBlockCluster *bcl, const value_type_t avalue_type=real_valued) | |
construct matrix of size defined by block cluster bcl | |
TMatrix (const TBlockIndexSet &bis, const value_type_t avalue_type=real_valued) | |
construct matrix of size defined by block index set bis | |
TMatrix (const TMatrix &A) | |
copy constructor | |
virtual | ~TMatrix () |
dtor | |
int | id () const |
return ID | |
void | set_id (const int aid) |
set ID | |
virtual size_t | nrows (const matop_t op) const |
return number of rows of op(M) | |
virtual size_t | ncols (const matop_t op) const |
return number of columns of op(M) | |
TIndexSet | row_is () const |
return row index set | |
TIndexSet | col_is () const |
return column index set | |
TBlockIndexSet | block_is () const |
return block index set | |
TIndexSet | row_is (const matop_t op) const |
return row index set w.r.t. given matrix operation | |
TIndexSet | col_is (const matop_t op) const |
return row index set w.r.t. given matrix operation | |
TBlockIndexSet | block_is (const matop_t op) const |
return row index set w.r.t. given matrix operation | |
virtual idx_t | row_ofs () const |
return first index (number) in row | |
virtual idx_t | col_ofs () const |
return first index (number) in column | |
virtual void | set_ofs (const idx_t r, const idx_t c) |
set index set offsets | |
virtual void | set_block_is (const TBlockIndexSet &is) |
set block index set of matrix | |
bool | is_nonsym () const |
return true if matrix is unsymmetric | |
bool | is_symmetric () const |
return true if matrix is symmetric | |
bool | is_hermitian () const |
return true if matrix is hermitian | |
matform_t | form () const |
return matrix format | |
void | set_nonsym () |
set matrix to be unsymmetric | |
void | set_symmetric () |
set matrix to be symmetric | |
void | set_hermitian () |
set matrix to be hermitian | |
virtual void | set_form (const matform_t f) |
set matrix format | |
virtual bool | is_zero () const |
return true, if matrix is zero | |
virtual bool | is_blocked () const |
return true, if matrix is blocked | |
virtual bool | is_dense () const |
return true, if matrix is dense | |
virtual bool | is_self_adjoint () const |
return true, if operator is self adjoint | |
const TProcSet & | procs () const |
return matrix processor set | |
uint | nprocs () const |
return number of processors in local set | |
virtual void | set_procs (const TProcSet &ps, const recursion_type_t rec_type=nonrecursive) |
set processor set of matrix | |
bool | is_distributed () const |
return true if matrix is distributed | |
virtual void | copy_struct_from (const TMatrix *M) |
value_type_t | value_type () const |
return value type of matrix | |
void | set_value_type (const value_type_t vt) |
set value type of matrix | |
bool | is_real () const |
return true if matrix is real valued | |
bool | is_complex () const |
return true if matrix is complex valued | |
void | set_complex (const bool b, const bool force=false) |
TUpdateAccumulator & | accumulator () |
access accumulator object | |
void | add_update (const TMatrix *M, const TTruncAcc &acc) |
add update matrix | |
void | add_pending_direct (TDirectMatrixUpdate *U) |
add update U to set of recursive pending updates | |
void | add_pending_recursive (TRecursiveMatrixUpdate *U) |
add update U to set of recursive pending updates | |
virtual void | apply_updates (const TTruncAcc &acc, const recursion_type_t rec_type) |
virtual bool | has_updates (const recursion_type_t recursion) const |
return true, if matrix has updates not yet applied | |
virtual bool | has_parent_updates (const recursion_type_t recursion) const |
return true, if parent matrix has updates not yet applied | |
const TBlockCluster * | cluster () const |
return corresponding block cluster of matrix | |
virtual void | set_cluster_force (const TBlockCluster *c) |
set block cluster of matrix (with forced setting of cluster variable) | |
virtual void | apply (const TVector *x, TVector *y, const matop_t op=apply_normal) const |
virtual void | apply_add (const real alpha, const TVector *x, TVector *y, const matop_t op=apply_normal) const |
virtual void | apply_add (const real alpha, const BLAS::Vector< real > &x, BLAS::Vector< real > &y, const matop_t op=apply_normal) const |
virtual size_t | domain_dim () const |
return dimension of domain | |
virtual size_t | range_dim () const |
return dimension of range | |
virtual auto | domain_vector () const -> std::unique_ptr< TVector > |
return vector in domain space | |
virtual auto | range_vector () const -> std::unique_ptr< TVector > |
return vector in range space | |
virtual TMatrix * | mul_right (const real alpha, const TMatrix *B, const matop_t op_A, const matop_t op_B) const |
compute α·op(A)·op(B), with A = this | |
virtual TMatrix * | mul_left (const real alpha, const TMatrix *A, const matop_t op_A, const matop_t op_B) const |
compute α·op(A)·op(B), with B = this | |
virtual TMatrix * | cmul_right (const complex alpha, const TMatrix *B, const matop_t op_A, const matop_t op_B) const |
compute α·op(A)·op(B), with A = this | |
virtual TMatrix * | cmul_left (const complex alpha, const TMatrix *A, const matop_t op_A, const matop_t op_B) const |
compute α·op(A)·op(B), with B = this | |
virtual size_t | global_byte_size () const |
virtual auto | copy (const TTruncAcc &acc, const bool coarsen=false) const -> std::unique_ptr< TMatrix > |
return copy of matrix with accuracy acc and optional coarsening | |
virtual void | copy_from (const TMatrix *A) |
copy data from matrix A | |
virtual void | copy_to (TMatrix *A, const TTruncAcc &acc, const bool coarsen=false) const |
copy matrix into matrix A with accuracy acc and optional coarsening | |
virtual auto | row_vector () const -> std::unique_ptr< TVector > |
return appropriate row vector object for matrix | |
virtual auto | col_vector () const -> std::unique_ptr< TVector > |
return appropriate column vector object for matrix | |
virtual void | sum (const TProcSet &p, const uint pid, const uint nparts, TByteStream *bs, const TTruncAcc &acc) |
Public Member Functions inherited from TTypeInfo | |
virtual typeid_t | type () const =0 |
return type ID of object | |
virtual bool | is_type (const typeid_t t) const |
return true if local object is of given type ID t | |
virtual std::string | typestr () const |
return string representation of type | |
Public Member Functions inherited from TLockable | |
TMutex & | mutex () |
give access to internal mutex | |
void | lock () |
lock local mutex | |
void | unlock () |
unlock local mutex | |
size_t | byte_size () const |
return size in bytes used by this object | |
void export_ccs | ( | std::vector< T_idx > & | colptr, |
std::vector< T_idx > & | rowind, | ||
std::vector< T_val > & | coeffs, | ||
const bool | use_sym | ||
) | const |
export internal data to CCS format (real valued); if use_sym is true, only the lower triangular part is exported
void permute | ( | const TPermutation & | rowperm, |
const TPermutation & | colperm | ||
) |
permute entries in sparse matrix according to rowperm (for rows) and colperm (for columns)
std::unique_ptr< TSparseMatrix > restrict | ( | const TIndexSet & | rowis, |
const TPermutation * | rowperm, | ||
const TIndexSet & | colis, | ||
const TPermutation * | colperm | ||
) | const |
restrict sparse matrix to block index set rowis × colis which is given in a different ordering