C-XSC - A C++ Class Library for Extended Scientific Computing
2.5.4
|
A sparse complex matrix. More...
#include <scmatrix.hpp>
Public Member Functions | |
std::vector< int > & | column_pointers () |
Returns a reference to the vector containing the column pointers (the array) | |
const std::vector< int > & | column_pointers () const |
Returns a constant reference to the vector containing the column pointers (the array) | |
real | density () const |
Returns the density (the number of non-zeros divided by the number of elements) of the matrix. | |
void | dropzeros () |
Drops explicitly stored zeros from the data structure. | |
complex & | element (int i, int j) |
Returns a reference to the element (i,j) of the matrix. | |
void | full (cmatrix &A) const |
Creates a full matrix out of the sparse matrix and stores it in A. This should normally be done using the respective constructor of the dense matrix. | |
int | get_nnz () const |
Returns the number of non-zero entries (including explicitly stored zeros). | |
const complex | operator() (int i, int j) const |
Returns a copy of the element in row i and column j. | |
scmatrix_slice | operator() (const int, const int, const int, const int) |
Returns a slice of the matrix. | |
const scmatrix_slice | operator() (const int, const int, const int, const int) const |
Returns a slice of the matrix. | |
scmatrix | operator() (const intvector &pervec, const intvector &q) |
Performs a row and column permutation using two permutation vectors. | |
scmatrix | operator() (const intvector &pervec) |
Performs a row permutation using a permutation vector. | |
scmatrix | operator() (const intmatrix &P, const intmatrix &Q) |
Performs row and column permutations using the two permutation matrices P and Q. Faster than explicitly computing the product. | |
scmatrix | operator() (const intmatrix &P) |
Performs a row permutation using the permutation matrix P. Faster than explicitly computing the product. | |
scmatrix & | operator*= (const cmatrix &B) |
Multiply the sparse matrix by B and assign the result to it. | |
scmatrix & | operator*= (const rmatrix &B) |
Multiply the sparse matrix by B and assign the result to it. | |
scmatrix & | operator*= (const rmatrix_slice &B) |
Multiply the sparse matrix by B and assign the result to it. | |
scmatrix & | operator*= (const cmatrix_slice &B) |
Multiply the sparse matrix by B and assign the result to it. | |
scmatrix & | operator*= (const srmatrix &B) |
Multiply the sparse matrix by B and assign the result to it. | |
scmatrix & | operator*= (const scmatrix &B) |
Multiply the sparse matrix by B and assign the result to it. | |
scmatrix & | operator*= (const real &r) |
Multiply all elements of the sparse matrix by r and assign the result to it. | |
scmatrix & | operator*= (const complex &r) |
Multiply all elements of the sparse matrix by r and assign the result to it. | |
scmatrix & | operator+= (const rmatrix &B) |
Add B to the sparse matrix and assign the result to it. | |
scmatrix & | operator+= (const cmatrix &B) |
Add B to the sparse matrix and assign the result to it. | |
scmatrix & | operator+= (const rmatrix_slice &B) |
Add B to the sparse matrix and assign the result to it. | |
scmatrix & | operator+= (const cmatrix_slice &B) |
Add B to the sparse matrix and assign the result to it. | |
scmatrix & | operator+= (const srmatrix &B) |
Add B to the sparse matrix and assign the result to it. | |
scmatrix & | operator+= (const scmatrix &B) |
Add B to the sparse matrix and assign the result to it. | |
scmatrix & | operator-= (const rmatrix &B) |
Subtract B from the sparse matrix and assign the result to it. | |
scmatrix & | operator-= (const cmatrix &B) |
Subtract B from the sparse matrix and assign the result to it. | |
scmatrix & | operator-= (const rmatrix_slice &B) |
Subtract B from the sparse matrix and assign the result to it. | |
scmatrix & | operator-= (const cmatrix_slice &B) |
Subtract B from the sparse matrix and assign the result to it. | |
scmatrix & | operator-= (const srmatrix &B) |
Subtract B from the sparse matrix and assign the result to it. | |
scmatrix & | operator-= (const scmatrix &B) |
Subtract B from the sparse matrix and assign the result to it. | |
scmatrix & | operator/= (const real &r) |
Divide all elements of the sparse matrix by r and assign the result to it. | |
scmatrix & | operator/= (const complex &r) |
Divide all elements of the sparse matrix by r and assign the result to it. | |
scmatrix & | operator= (const real &A) |
Assigns a real value to all elements of the matrix (resulting in a dense matrix!) | |
scmatrix & | operator= (const complex &A) |
Assigns a complex value to all elements of the matrix (resulting in a dense matrix!) | |
scmatrix & | operator= (const rmatrix &A) |
Assigns a dense matrix to the sparse matrix. Only the non zero entries of the dense matrix slice are used. | |
scmatrix & | operator= (const cmatrix &A) |
Assigns a dense matrix to the sparse matrix. Only the non zero entries of the dense matrix slice are used. | |
scmatrix & | operator= (const rmatrix_slice &A) |
Assigns a dense matrix slice to the sparse matrix. Only the non zero entries of the dense matrix slice are used. | |
scmatrix & | operator= (const cmatrix_slice &A) |
Assigns a dense matrix slice to the sparse matrix. Only the non zero entries of the dense matrix slice are used. | |
scmatrix & | operator= (const srmatrix &A) |
Assigns a sparse real matrix to the sparse complex matrix. | |
scmatrix & | operator= (const srmatrix_slice &) |
Assign a sparse matrix slice to a sparse matrix. | |
scmatrix & | operator= (const scmatrix_slice &) |
Assign a sparse matrix slice to a sparse matrix. | |
scmatrix_subv | operator[] (const cxscmatrix_column &) |
Returns a column of the matrix as a sparse subvector object. | |
scmatrix_subv | operator[] (const int) |
Returns a row of the matrix as a sparse subvector object. | |
const scmatrix_subv | operator[] (const cxscmatrix_column &) const |
Returns a column of the matrix as a sparse subvector object. | |
const scmatrix_subv | operator[] (const int) const |
Returns a row of the matrix as a sparse subvector object. | |
std::vector< int > & | row_indices () |
Returns a reference to the vector containing the row indices (the array) | |
const std::vector< int > & | row_indices () const |
Returns a constant reference to the vector containing the row indices (the array) | |
scmatrix () | |
Standard constructor, creates an empty matrix of dimension 0x0. | |
scmatrix (const int r, const int c) | |
Creates an empty matrix with r rows and c columns, pre-reserving space for 2*(r+c) elements. | |
scmatrix (const int r, const int c, const int e) | |
Creates an empty matrix with r rows and c columns, pre-reserving space for e elements. | |
scmatrix (const int m, const int n, const int nnz, const intvector &rows, const intvector &cols, const cvector &values, const enum STORAGE_TYPE t=triplet) | |
Creates a sparse matrix out of three vectors (arrays) forming a matrix stored in triplet, compressed row or compressed column storage. | |
scmatrix (const int m, const int n, const int nnz, const int *rows, const int *cols, const complex *values, const enum STORAGE_TYPE t=triplet) | |
Creates a sparse matrix out of three arrays forming a matrix stored in triplet, compressed row or compressed column storage. | |
scmatrix (const srmatrix &A) | |
Creates a sparse complex matrix out of a sparse real matrix. | |
scmatrix (const rmatrix &A) | |
Creates a sparse matrix out of a dense matrix A. Only the non zero elements of A are stored explicitly. | |
scmatrix (const cmatrix &A) | |
Creates a sparse matrix out of a dense matrix A. Only the non zero elements of A are stored explicitly. | |
scmatrix (const int ms, const int ns, const cmatrix &A) | |
Constructor for banded matrices. | |
scmatrix (const srmatrix_slice &) | |
Creates a sparse matrix out of a sparse matrix slice. | |
scmatrix (const scmatrix_slice &) | |
Creates a sparse matrix out of a sparse matrix slice. | |
std::vector< complex > & | values () |
Returns a reference to the vector containing the stored values (the array) | |
const std::vector< complex > & | values () const |
Returns a constant reference to the vector containing the stored values (the array) | |
Friends | |
srmatrix | abs (const scmatrix &) |
Returns the componentwise absolute value of the sparse matrix A. | |
int | ColLen (const scmatrix &) |
Returns the number of rows of the matrix. | |
srmatrix | CompMat (const scmatrix &) |
Returns Ostrowskis comparison matrix for A. | |
scmatrix | diam (const scimatrix &) |
Returns the componentwise diameter of the matrix A. | |
scmatrix | Id (const scmatrix &) |
Return a sparse unity matrix of the same dimension as A. | |
srmatrix | Im (const scmatrix &) |
Returns the imaginary part of the sparse matrix A. | |
scmatrix | Inf (const scimatrix &) |
Returns the Infimum of the matrix A. | |
int | Lb (const scmatrix &, int) |
Returns the lower index bound for the rows or columns of A. | |
scmatrix | mid (const scimatrix &) |
Returns the componentwise midpoint of the matrix A. | |
std::istream & | operator>> (std::istream &, scmatrix_slice &) |
Standard input operator for sparse matrix slice. | |
std::istream & | operator>> (std::istream &, scmatrix_subv &) |
Standard input operator for subvectors. | |
srmatrix | Re (const scmatrix &) |
Returns the real part of the sparse matrix A. | |
int | RowLen (const scmatrix &) |
Returns the number of columns of the matrix. | |
void | SetLb (scmatrix &, const int, const int) |
Sets the lower index bound of the rows (i==ROW) or columns (i==COL) to j. | |
void | SetUb (scmatrix &, const int, const int) |
Sets the upper index bound of the rows (i==ROW) or columns (i==COL) to j. | |
scmatrix | Sup (const scimatrix &) |
Returns the Supremum of the matrix A. | |
scmatrix | transp (const scmatrix &) |
Returns the transpose of A. | |
int | Ub (const scmatrix &, int) |
Returns the upper index bound for the rows or columns of A. |
A sparse complex matrix.
Sparse matrices in C-XSC are stored in the Compressed Column Storage (CCS) format. The non zero entries of the matrix are stored in three arrays (STL-vectors) , , . The array stores the row indices of the non zero elements, the array the respective values (the -th element of corresponds to the i-th element of , , where is the number of non zeros. The entries are sorted by column. The array of size stores the starting indices for the entries of each column of the matrix, so that the entries of the -th column of the matrix are stored in the elements with index through of the arrays and . The elements of each column are stored as sorted by the row indices, explicitly stored zeros are allowed.
The internal data structure uses 0-based indexing throughout. However, in the interface to the user (using the respective operators) every matrix possesses a lower and an upper row index bound , and a lower and an upper column index bound , of type int. By default, these indexes are 1-based.
It is possible to directly access the internal data structure through the appropriate member function to allow for easier interfacing with other sparse matrix libraries and writing of more efficient sparse matrix algorithms. In this case, the user has to take care that the data structure remains consistent with the format described above. If the user just works with the operators and functions provided by C-XSC, everything will be handled automatically by the C-XSC library.
All matrix and vector operators which require dot product computations use higher precision dot products provided by the dotprecision classes. The precision to be used for these implicit dot products can be choosen by setting the global variable opdotprec accordingly. A value of 0 means maximum accuracy (the default, always used by all older C-XSC versions), a value of 1 means double accuracy, a value of 2 or higher means k-fold double accuracy. Lower accuracy leads to (significantly) faster computing times, but also to less exact results. For all dot products with an interval result, error bounds are computed to guarantee a correct enclosure. For all other dot products approximations without error bounds are computed.
Definition at line 69 of file scmatrix.hpp.
cxsc::scmatrix::scmatrix | ( | const int | m, |
const int | n, | ||
const int | nnz, | ||
const intvector & | rows, | ||
const intvector & | cols, | ||
const cvector & | values, | ||
const enum STORAGE_TYPE | t = triplet |
||
) | [inline] |
Creates a sparse matrix out of three vectors (arrays) forming a matrix stored in triplet, compressed row or compressed column storage.
Creates a sparse matrix of dimension with the values from the three arrays rows, cols and values. These are interpreted according to the storage type t. For triplet rows and cols contains the indices of all non zero values and the array values contains the actual values. For compressed_column, the arrays are interpreted according to the compressed column storage format, where cols contains the column pointers. For compressed_row the arrays are interpreted according to the compressed row storage format, which is equivalent to compressed column storage with the role of the rows and columns interchanged.
In each case the arrays need not be sorted by rows or columns and may contain explicit zero entries.
Definition at line 143 of file scmatrix.hpp.
cxsc::scmatrix::scmatrix | ( | const int | m, |
const int | n, | ||
const int | nnz, | ||
const int * | rows, | ||
const int * | cols, | ||
const complex * | values, | ||
const enum STORAGE_TYPE | t = triplet |
||
) | [inline] |
Creates a sparse matrix out of three arrays forming a matrix stored in triplet, compressed row or compressed column storage.
Creates a sparse matrix of dimension with the values from the three arrays rows, cols and values. These are interpreted according to the storage type t. For triplet rows and cols contains the indices of all non zero values and the array values contains the actual values. For compressed_column, the arrays are interpreted according to the compressed column storage format, where cols contains the column pointers. For compressed_row the arrays are interpreted according to the compressed row storage format, which is equivalent to compressed column storage with the role of the rows and columns interchanged.
In each case the arrays need not be sorted by rows or columns and may contain explicit zero entries.
Definition at line 254 of file scmatrix.hpp.
cxsc::scmatrix::scmatrix | ( | const int | ms, |
const int | ns, | ||
const cmatrix & | A | ||
) | [inline] |
Constructor for banded matrices.
Creates a sparse banded matrix of dimension , whose bands are defined by the columns of the dense matrix A. The column inde range of A must be set appropriately: The columns of with negative indices are used for bands below the diagonal, the column with index 0 is used for the diagonal, and columns with positive index are use for bands above the diagonal.
Definition at line 416 of file scmatrix.hpp.
void cxsc::scmatrix::dropzeros | ( | ) | [inline] |
Drops explicitly stored zeros from the data structure.
Dropping explicit zero entries can be essential when interfacing with other sparse matrix libraries. Some librares using the CCS storage format do not allow explicitly stored zeros.
Definition at line 473 of file scmatrix.hpp.
complex& cxsc::scmatrix::element | ( | int | i, |
int | j | ||
) | [inline] |
Returns a reference to the element (i,j) of the matrix.
This function should only be used for write access. The indices i and j must be used according to the current index range of the matrix. A reference to the element (i,j) is returned. If the element is not stored explicitly, it is created as an explicit 0 entry. For read access to a single element, the ()-opeator should be used.
This function is faster than using the []-operator (for example A[i][j]), since it does not need to create a temporary subvector first.
Note that due to the underlying data structure the access to single elements of a sparse matrix is much more expensive than to the elements of a dense matrix.
Definition at line 579 of file scmatrix.hpp.
Referenced by cxsc::scmatrix_slice::element().
const complex cxsc::scmatrix::operator() | ( | int | i, |
int | j | ||
) | const [inline] |
Returns a copy of the element in row i and column j.
This operator can be used for read access only. The indices i and j must be used according to the current index range of the matrix. A copy of the element (i,j) is returned, or 0 if this element is not explicitly stored. For write access to a single element, the []-opeator or the member function element should be used.
Note that due to the underlying data structure the access to single elements of a sparse matrix is much more expensive than to the elements of a dense matrix.
Definition at line 558 of file scmatrix.hpp.
int Lb | ( | const scmatrix & | A, |
int | i | ||
) | [friend] |
Returns the lower index bound for the rows or columns of A.
If i==ROW, the lower index bound for the rows is returned, if i==COL, the lower index bound for the columns is returned.
Definition at line 956 of file scmatrix.hpp.
Referenced by operator()(), and scmatrix().
std::istream& operator>> | ( | std::istream & | is, |
scmatrix_slice & | M | ||
) | [friend] |
Standard input operator for sparse matrix slice.
The input format is set by global flags, default is dense input. Use cout << SparseInOut; for sparse input or cout << MatrixMarketInOut; for input in matrix market format.
Definition at line 3332 of file scmatrix.hpp.
void SetLb | ( | scmatrix & | A, |
const int | i, | ||
const int | j | ||
) | [friend] |
Sets the lower index bound of the rows (i==ROW) or columns (i==COL) to j.
If i==ROW, the lower index bound for the rows of A ist set to j. if i==COL, the lower index bound of the columns is set to j. The upper index bound is automatically set according to the number of rows or columns of the matrix.
Definition at line 926 of file scmatrix.hpp.
void SetUb | ( | scmatrix & | A, |
const int | i, | ||
const int | j | ||
) | [friend] |
Sets the upper index bound of the rows (i==ROW) or columns (i==COL) to j.
If i==ROW, the upper index bound for the rows of A ist set to j. if i==COL, the upper index bound of the columns is set to j. The lower index bound is automatically set according to the number of rows or columns of the matrix.
Definition at line 941 of file scmatrix.hpp.
int Ub | ( | const scmatrix & | A, |
int | i | ||
) | [friend] |
Returns the upper index bound for the rows or columns of A.
If i==COL, the upper index bound for the rows is returned, if i==COL, the upper index bound for the columns is returned.
Definition at line 969 of file scmatrix.hpp.
Referenced by scmatrix().