ConicBundle
|
Matrix class of symmetric matrices with real values of type Real More...
#include <sparssym.hxx>
Public Member Functions | |
Constructors, Destructor, and Initialization (Members) | |
Sparsesym () | |
empty matrix | |
Sparsesym (const Sparsesym &A, Real d=1.) | |
copy constructor, *this=d*A | |
Sparsesym (Integer nr) | |
initialize to zero-matrix of size nr*nr | |
Sparsesym (Integer nr, Integer nz, const Integer *ini, const Integer *inj, const Real *va) | |
initialize to size nr*nr and nz nonzeros so that this(ini[i],inj[i])=val[i] for i=0,..,nz-1; specify only one of (i,j) and (j,i), multiple elements are summed up. | |
Sparsesym (Integer nr, Integer nz, const Indexmatrix &ini, const Indexmatrix &inj, const Matrix &va) | |
initialize to size nr*nr and nz nonzeros so that this(ini(i),inj(i))=val[i] for i=0,..,nz-1; specify only one of (i,j) and (j,i), multiple elements are summed up. | |
void | set_init (bool) |
after external initialization, call matrix.set_init(true) (not needed if CONICBUNDLE_DEBUG is undefined) | |
bool | get_init () const |
returns true if the matrix has been declared initialized (not needed if CONICBUNDLE_DEBUG is undefined) | |
Sparsesym & | init (const Sparsesym &, Real d=1.) |
initialize to *this=A*d | |
Sparsesym & | init (const Matrix &, Real d=1.) |
initialize to this=d(A+transpose(A))/2., abs(values)<tol are removed from the support | |
Sparsesym & | init (const Indexmatrix &, Real d=1.) |
initialize to this=d(A+transpose(A))/2., zeros are removed from the support | |
Sparsesym & | init (const Symmatrix &, Real d=1.) |
initialize to *this=A*d, abs(values)<tol are removed from the support | |
Sparsesym & | init (const Sparsemat &, Real d=1.) |
initialize to this=d(A+transpose(A))/2. | |
Sparsesym & | init (Integer nr) |
initialize to zero-matrix of size nr*nr | |
Sparsesym & | init (Integer nr, Integer nz, const Integer *ini, const Integer *inj, const Real *va) |
initialize to size nr*nr and nz nonzeros so that this(ini[i],inj[i])=val[i] for i=0,..,nz-1; specify only one of (i,j) and (j,i), multiple elements are summed up. | |
Sparsesym & | init (Integer nr, Integer nz, const Indexmatrix &ini, const Indexmatrix &inj, const Matrix &va) |
initialize to size nr*nr and nz nonzeros so that this(ini(i),inj(i))=val[i] for i=0,..,nz-1; specify only one of (i,j) and (j,i), multiple elements are summed up. | |
Sparsesym & | init_support (const Sparsesym &A, Real d=0.) |
void | set_tol (Real t) |
set tolerance for recognizing zero values to t | |
Conversions from other Matrix Classes (Members) | |
Sparsesym (const Matrix &, Real d=1.) | |
initialize to this=d(A+transpose(A))/2., abs(values)<tol are removed from the support | |
Sparsesym (const Indexmatrix &, Real d=1.) | |
initialize to this=d(A+transpose(A))/2., zeros are removed from the support | |
Sparsesym (const Symmatrix &, Real d=1.) | |
initialize to *this=A*d, abs(values)<tol are removed from the support | |
Sparsesym (const Sparsemat &, Real d=1.) | |
initialize to this=d(A+transpose(A))/2. | |
Size and Type Information (Members) | |
void | dim (Integer &r, Integer &c) const |
returns the number of rows in _nr and the number of columns in _nc | |
Integer | dim () const |
returns the dimension rows * columns when the matrix is regarded as a vector | |
Integer | rowdim () const |
returns the row dimension | |
Integer | coldim () const |
returns the column dimension | |
Integer | nonzeros () const |
returns the number of nonzeros in the lower triangle (including diagonal) | |
Mtype | get_mtype () const |
returns the type of the matrix, MTmatrix | |
Indexing and Submatrices (Members) | |
Real | operator() (Integer i, Integer j) const |
returns value of element (i,j) of the matrix (rowindex i, columnindex j) | |
Real | operator() (Integer i) const |
returns value of element (i) of the matrix if regarded as vector of stacked columns [element (irowdim, i/rowdim)] | |
Real | operator[] (Integer i) const |
returns value of element (i) of the matrix if regarded as vector of stacked columns [element (irowdim, i/rowdim)] | |
const Indexmatrix & | get_colinfo () const |
returns information on nozero diagonal/columns, k by 4, listing: index (<0 for diagonal), # nonzeros, first index in colindex/colval, index in suppport submatrix | |
const Indexmatrix & | get_colindex () const |
returns the index vector of the column representation holding the row index for each element | |
const Matrix & | get_colval () const |
returns the value vector of the column representation holding the value for each element | |
const Indexmatrix & | get_suppind () const |
returns the index vector of the column representation holding the row index w.r.t. the principal support submatrix for each element | |
const Indexmatrix & | get_suppcol () const |
returns the vector listing in ascending order the original column indices of the principal support submatrix | |
void | get_edge_rep (Indexmatrix &I, Indexmatrix &J, Matrix &val) const |
stores the nz nonzero values of the lower triangle of *this in I,J,val so that this(I(i),J(i))=val(i) for i=0,...,nz-1 and dim(I)=dim(J)=dim(val)=nz (ordered as in row representation) | |
int | contains_support (const Sparsesym &A) const |
returns 1 if A is of the same dimension and the support of A is contained in the support of *this, 0 otherwise | |
int | check_support (Integer i, Integer j) const |
returns 0 if (i,j) is not in the support, 1 otherwise | |
BLAS-like Routines (Members) | |
Sparsesym & | xeya (const Sparsesym &A, Real d=1.) |
sets *this=d*A and returns *this | |
Sparsesym & | xeya (const Matrix &A, Real d=1.) |
sets and returns this=d(A+transpose(A))/2. where abs(values)<tol are removed from the support | |
Sparsesym & | xeya (const Indexmatrix &A, Real d=1.) |
sets and returns this=d(A+transpose(A))/2. where zeros are removed from the support | |
Sparsesym & | support_xbpeya (const Sparsesym &y, Real alpha=1., Real beta=0.) |
returns this= alpha*y+beta(*this) restricted to the curent support of *this; if beta==0, then *this is initialized to 0 on its support first | |
Usual Arithmetic Operators (Members) | |
Sparsesym & | operator= (const Sparsesym &A) |
Sparsesym & | operator+= (const Sparsesym &v) |
Sparsesym & | operator-= (const Sparsesym &v) |
Sparsesym | operator- () const |
Sparsesym & | operator*= (Real d) |
Sparsesym & | operator/= (Real d) |
ATTENTION: d is NOT checked for 0. | |
Sparsesym & | operator= (const Matrix &A) |
sets *this=(A+transpose(A))/2. removing abs(values)<tol; returns *this | |
Sparsesym & | operator= (const Indexmatrix &A) |
sets *this=(A+transpose(A))/2. removing zeros; returns *this | |
Sparsesym & | transpose () |
transposes itself (at almost no cost) | |
Connections to other Classes (Members) | |
Sparsesym & | xeya (const Symmatrix &A, Real d=1.) |
sets and returns *this=A*d where abs(values)<tol are removed from the support | |
Sparsesym & | xeya (const Sparsemat &A, Real d=1.) |
sets and returns this=d.(A+transpose(A))/2. | |
Sparsesym & | operator= (const Symmatrix &A) |
sets and returns *this=A where abs(values)<tol are removed from the support | |
Symmatrix | operator+ (const Symmatrix &A) const |
Symmatrix | operator- (const Symmatrix &A) const |
Sparsesym & | operator= (const Sparsemat &A) |
sets and returns *this=(A+transpose(A))/2. | |
Sparsemat | sparsemult (const Matrix &A) const |
compute (*this)*A and return the result in a Sparsemat | |
Input, Output (Members) | |
void | display (std::ostream &out, int precision=0, int width=0, int screenwidth=0) const |
displays a matrix in a pretty way for bounded screen widths; for variables of value zero default values are used. More... | |
Private Member Functions | |
void | init_to_zero () |
initialize the matrix to a 0x0 matrix without storage | |
void | update_support () |
removes zeros and updates suppind and suppcol | |
Private Attributes | |
Mtype | mtype |
used for MatrixError templates (runtime type information was not yet existing) | |
Integer | nr |
number rows = number columns | |
Indexmatrix | colinfo |
k by 4 matrix, for nonzero columns: index (<0 for diagonal), # nonzeros, first index in colindex/colval, index in support submatrix | |
Indexmatrix | colindex |
gives the rowindex of the element at position i, (sorted increasingly per column) | |
Matrix | colval |
gives the value of the element at position i | |
Indexmatrix | suppind |
index of an element with respect to the principal submatrix spanned by the entire support | |
Indexmatrix | suppcol |
the index of the support column in the original matrix | |
Real | tol |
>0, if abs(value)<tol, then value is taken to be zero | |
bool | is_init |
flag whether memory is initialized, it is only used if CONICBUNDLE_DEBUG is defined | |
Friends | |
class | Indexmatrix |
class | Matrix |
class | Symmatrix |
class | Sparsemat |
Indexing and Submatrices (Friends) | |
Matrix | diag (const Sparsesym &A) |
returns the diagonal of A as a dense Matrix vector | |
Sparsesym | sparseDiag (const Matrix &A, Real tol) |
forms a sparse symmetrix matrix having vector A on its diagonal | |
void | swap (Sparsesym &A, Sparsesym &B) |
swap the content of the two sparse matrices A and B (involves no copying) | |
BLAS-like Routines (Friends) | |
Sparsesym & | xbpeya (Sparsesym &x, const Sparsesym &y, Real alpha, Real beta) |
returns x= alpha*y+beta*x; if beta==0. then x is initialized to the correct size | |
Sparsesym & | xeyapzb (Sparsesym &x, const Sparsesym &y, const Sparsesym &z, Real alpha, Real beta) |
returns x= alpha*y+beta*z; x is initialized to the correct size | |
Sparsesym & | support_rankadd (const Matrix &A, Sparsesym &C, Real alpha, Real beta, int trans) |
returns C=beta*C+alpha*AA^T (or A^TA), but only on the current support of C | |
Matrix & | genmult (const Sparsesym &A, const Matrix &B, Matrix &C, Real alpha, Real beta, int btrans) |
returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to B; if beta==0. then C is initialized to the correct size | |
Matrix & | genmult (const Matrix &A, const Sparsesym &B, Matrix &C, Real alpha, Real beta, int atrans) |
returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to B; if beta==0. then C is initialized to the correct size | |
Usual Arithmetic Operators (Friends) | |
Sparsesym | operator+ (const Sparsesym &A, const Sparsesym &B) |
returns a Sparsesym that equals A+B | |
Sparsesym | operator- (const Sparsesym &A, const Sparsesym &B) |
returns a Sparsesym that equals A-B | |
Sparsesym | operator* (const Sparsesym &A, Real d) |
returns a Sparsesym that equals A*d | |
Sparsesym | operator* (Real d, const Sparsesym &A) |
returns a Sparsesym that equals A*d | |
Sparsesym | operator/ (const Sparsesym &A, Real d) |
ATTENTION: d is NOT checked for 0. | |
Matrix | operator* (const Matrix &A, const Sparsesym &B) |
returns a Matrix that equals A*B | |
Matrix | operator* (const Sparsesym &A, const Matrix &B) |
returns a Matrix that equals A*B | |
Matrix | operator+ (const Matrix &A, const Sparsesym &B) |
returns a Matrix that equals A+B | |
Matrix | operator+ (const Sparsesym &A, const Matrix &B) |
returns a Matrix that equals A+B | |
Matrix | operator- (const Matrix &A, const Sparsesym &B) |
returns a Matrix that equals A-B | |
Matrix | operator- (const Sparsesym &A, const Matrix &B) |
returns a Matrix that equals A-B | |
Sparsesym | transpose (const Sparsesym &A) |
(drop it or use a constructor instead) | |
Connections to other Classes (Friends) | |
Symmatrix | operator+ (const Sparsesym &A, const Symmatrix &B) |
returns a Symmatrix that equals A+B | |
Symmatrix | operator+ (const Symmatrix &A, const Sparsesym &B) |
returns a Symmatrix that equals A+B | |
Symmatrix | operator- (const Sparsesym &A, const Symmatrix &B) |
returns a Symmatrix that equals A-B | |
Symmatrix | operator- (const Symmatrix &A, const Sparsesym &B) |
returns a Symmatrix that equals A-B | |
Real | ip (const Symmatrix &A, const Sparsesym &B) |
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j | |
Real | ip (const Sparsesym &A, const Symmatrix &B) |
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j | |
Matrix & | genmult (const Sparsesym &A, const Sparsemat &B, Matrix &C, Real alpha, Real beta, int btrans) |
returns C=beta*C+alpha*A*B, where B may be transposed; if beta==0. then C is initialized to the correct size More... | |
Matrix & | genmult (const Sparsemat &A, const Sparsesym &B, Matrix &C, Real alpha, Real beta, int atrans) |
returns C=beta*C+alpha*A*B, where A may be transposed; if beta==0. then C is initialized to the correct size More... | |
Matrix | operator* (const Sparsesym &A, const Sparsemat &B) |
returns a Matrix that equals A*B | |
Matrix | operator* (const Sparsemat &A, const Sparsesym &B) |
returns a Matrix that equals A*B | |
Elementwise Operations (Friends) | |
Sparsesym | abs (const Sparsesym &A) |
returns a Sparsesym with elements abs((*this)(i,j)) for all i,j | |
Numerical Methods (Friends) | |
Real | trace (const Sparsesym &A) |
returns the sum of the diagonal elements A(i,i) over all i | |
Real | ip (const Sparsesym &A, const Sparsesym &B) |
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j | |
Real | ip (const Matrix &A, const Sparsesym &B) |
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j | |
Real | ip (const Sparsesym &A, const Matrix &B) |
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j | |
Real | norm2 (const Sparsesym &A) |
returns the Frobenius norm of A, i.e., the square root of the sum of A(i,j)*A(i,j) over all i,j | |
Matrix | sumrows (const Sparsesym &A) |
returns a row vector holding the sum over all rows, i.e., (1 1 ... 1)*A | |
Matrix | sumcols (const Sparsesym &A) |
returns a column vector holding the sum over all columns, i.e., A*(1 1 ... 1)^T | |
Real | sum (const Sparsesym &A) |
returns the sum over all elements of A, i.e., (1 1 ... 1)*A*(1 1 ... 1)^T | |
Equal (Members) | |
int | equal (const Sparsesym &A, const Sparsesym &B, Real eqtol) |
returns 1 if both matrices are identical, 0 otherwise | |
Input, Output (Friends) | |
std::ostream & | operator<< (std::ostream &o, const Sparsesym &v) |
output format (lower triangle): nr nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n | |
std::istream & | operator>> (std::istream &i, Sparsesym &v) |
input format (lower triangle): nr nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n | |
Additional Inherited Members | |
Protected Member Functions inherited from CH_Matrix_Classes::Memarrayuser | |
Memarrayuser () | |
if memarray is NULL, then a new Memarray is generated. In any case the number of users of the Memarray is incremented | |
virtual | ~Memarrayuser () |
the number of users is decremented and the Memarray memory manager is destructed, if the number is zero. | |
Static Protected Attributes inherited from CH_Matrix_Classes::Memarrayuser | |
static Memarray * | memarray |
pointer to common memory manager for all Memarrayusers, instantiated in memarray.cxx | |
Matrix class of symmetric matrices with real values of type Real
Any matrix element can be indexed by (i,j) or directly by the one dimensional index (i+j*nr). The latter view directly corresponds to the vec() operator often used in the linear algebra literature, i.e., the matrix is transformed to a vector by stacking the columns on top of each other.
Internally the matrices colinfo, colindex, colval store the diagonal and the remaining lower triangle in columnwise order. For fast matrix multiplication generating sparse matrices additional information is stored in suppind and suppcol.
We now explain the representation of diagonal and columnwise lower triangle. Thereby the diagonal is treated like a separate column with negative index.
Suppose that 0<=k<=nr columns of diagonal and lower triangle of the symmetric nr*nr matrix contain nonzero elements, Then the Indexmatrix colinfo is a k by 4 matrix with one row for each nonzero column and the elements of row k give
Matrix colval is a vector with number of elements equal to the number of nonzeros in the lower triangle (including the diagonal). It stores the values of the nonzero elements of the diagonal and of the lower triangle in columnwise and then rowwise order, i.e., nonzero element (i1,j1) with i1>=j1 appears before a different nonzero element (i2,j2) with i2>=j2 iff (((i1==j1)&&(i2!=j2))||(j1<j2)||((j1==j2)&&(i1<i2)).
Indexmatrix colindex is of the same size as colval and stores for diagonal elemenets the row indices and for offdiagonal elements the rowindces minus the column index in the corresponding position. The shift of the offdiagonal indices helps to speed up some computations.
Note that in multplications with a (full or sparse) matrix it is beneficial to know the structure of principal submatrix that is spanned by the nonzero entries, i.e., to have available the indices of all columns/rows that contain nonzeros. This may differ considerably from the number of columns stored in colinfo, since one column of the lower triangle may cover many rows whose corresponding columns have no further nonzeros in the lower triangle. This information is stored in suppcol and suppind.
The Indexmatrix suppcol is a vector of dimension equal to the number of nonzero columns and contains, in increasing order, the indices of these columns.
The Indexmatrix suppind is arranged corresponding to colval and colindex, but in contrast to colindex it gives the row indices with respect to the principal support submatrix as given by suppcol.
void CH_Matrix_Classes::Sparsesym::display | ( | std::ostream & | out, |
int | precision = 0 , |
||
int | width = 0 , |
||
int | screenwidth = 0 |
||
) | const |
displays a matrix in a pretty way for bounded screen widths; for variables of value zero default values are used.
out | output stream |
precision | number of most significant digits, default=4 |
width | field width, default = precision+6 |
screenwidth | maximum number of characters in one output line, default = 80 |
Referenced by ConicBundle::CMsymsparse::display(), and transpose().
|
friend |
returns C=beta*C+alpha*A*B, where B may be transposed; if beta==0. then C is initialized to the correct size
returns C=beta*C+alpha*A*B, where B may be transposed; if beta==0. then C is initialized to the correct size
|
friend |
returns C=beta*C+alpha*A*B, where A may be transposed; if beta==0. then C is initialized to the correct size
returns C=beta*C+alpha*A*B, where A may be transposed; if beta==0. then C is initialized to the correct size